public Task <string> AddReaction(string articleSlug, ArticleReactionType articleReactionType, string content, string userId, string userName, DateTime timestamp, string replyingTo = "")
        {
            var newReaction = new ArticleReaction
            {
                ArticleSlug  = articleSlug,
                TimestampId  = (new ArticleReactionTimestampId(timestamp, replyingTo)).ToString(),
                Content      = content,
                AuthorId     = userId,
                AuthorName   = userName,
                ReactionType = articleReactionType
            };

            _GetReactionsDictionaryForArticle(articleSlug).Add(newReaction);

            return(Task.FromResult(newReaction.ReactionId));
        }
Ejemplo n.º 2
0
        public async Task <string> AddReaction(string articleSlug, ArticleReactionType articleReactionType, string content, string userId, string userName, DateTime timestamp, string replyingTo = "")
        {
            var reactionId = new ArticleReactionTimestampId(timestamp, replyingTo);
            var d          = new Document
            {
                [SLUG]      = articleSlug,
                [TIMESTAMP] = reactionId.TimestampId,
                [CONTENT]   = content,
            };

            if (!String.IsNullOrWhiteSpace(userId))
            {
                d[AUTHOR_ID] = userId;
            }
            if (!String.IsNullOrWhiteSpace(userName))
            {
                d[AUTHOR_NAME] = userName;
            }
            switch (articleReactionType)
            {
            case ArticleReactionType.Comment:
                d[ARTICLE_TYPE] = ARTICLE_TYPE_COMMENT;
                break;

            case ArticleReactionType.Edit:
                d[ARTICLE_TYPE] = ARTICLE_TYPE_COMMENTEDIT;
                break;

            case ArticleReactionType.Hide:
                d[ARTICLE_TYPE] = ARTICLE_TYPE_COMMENTHIDE;
                break;

            case ArticleReactionType.Delete:
                d[ARTICLE_TYPE] = ARTICLE_TYPE_COMMENTDELETE;
                break;

            default:
                throw new ArgumentException($"Unknown reaction type {articleReactionType}", "articleReactionType");
            }
            var table = Table.LoadTable(_dbClient, _options.DynamoDbTableName);

            _ = await table.PutItemAsync(d);

            return(reactionId.ReactionId);
        }
Ejemplo n.º 3
0
        public async Task <bool> ValidateReaction(string articleSlug, ArticleReactionType articleReactionType, string content, string userId, string userName, bool isAdministrator, string replyingTo = "")
        {
            // Validate that article exists and is not locked (using cached version is okay)
            var article = await ArticleStore.GetArticleAsync(articleSlug);

            if (article == null || article.LockedForComments)
            {
                return(false);
            }

            // If reacting to a comment, validate that the comment exists
            if (!String.IsNullOrEmpty(replyingTo))
            {
                var reactingToComment = await GetCompleteComment(articleSlug, new ArticleReactionTimestampId(replyingTo));

                if (reactingToComment == null)
                {
                    return(false);
                }
            }

            // Passed validation
            return(true);
        }
        public async Task <string> AddReaction(string articleSlug, ArticleReactionType articleReactionType, string content, string userId, string userName, DateTime timestamp, string replyingTo = "")
        {
            var reactionId = (new ArticleReactionTimestampId(timestamp, replyingTo)).ToString();

            using (var writer = new StreamWriter(Path.Combine(RootFolder, "comments.txt"), true))
            {
                await writer.WriteLineAsync(COMMENT_SEPARATOR);

                await writer.WriteLineAsync(articleSlug);

                await writer.WriteLineAsync(reactionId);

                await writer.WriteLineAsync(userId);

                await writer.WriteLineAsync(userName);

                await writer.WriteLineAsync(articleReactionType.ToString());

                await writer.WriteLineAsync(ArticleReactionEditState.Original.ToString());

                await writer.WriteLineAsync(content);
            }
            return(reactionId);
        }
Ejemplo n.º 5
0
 public async Task <string> AddReaction(string articleSlug, ArticleReactionType articleReactionType, string content, string userId, string userName, DateTime timestamp, string replyingTo = "") => await ArticleStore.AddReaction(articleSlug, articleReactionType, content, userId, userName, timestamp, replyingTo);
Ejemplo n.º 6
0
 public Task <string> AddReaction(string articleSlug, ArticleReactionType articleReactionType, string content, string userId, string userName, DateTime timestamp, string replyingTo = "")
 {
     throw new NotImplementedException();
 }