Exemplo n.º 1
0
        public IEnumerable<ApiComment> SubmissionComments(int submissionId)
        {
            var submission = DataCache.Submission.Retrieve(submissionId);

            if (submission == null || submission.Subverses.admin_disabled == true)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            string cacheKey = String.Format("LegacyApi.SubmissionComments.{0}", submissionId).ToLower();
            IEnumerable<ApiComment> cacheData = CacheHandler.Retrieve<IEnumerable<ApiComment>>(cacheKey);

            if (cacheData == null)
            {
                cacheData = CacheHandler.Register(cacheKey, new Func<IEnumerable<ApiComment>>(() =>
                {

                    var firstComments = from f in submission.Comments
                                let commentScore = f.Likes - f.Dislikes
                                where f.ParentId == null
                                orderby commentScore descending
                                select f;

                    var resultList = new List<ApiComment>();

                    foreach (var firstComment in firstComments.Take(10))
                    {
                        //do not show deleted comments unless they have replies
                        if (firstComment.Name == "deleted" && submission.Comments.Count(a => a.ParentId == firstComment.Id) == 0)
                        {
                            continue;
                        }

                        var resultModel = new ApiComment
                        {
                            Id = firstComment.Id,
                            Date = firstComment.Date,
                            Dislikes = firstComment.Dislikes,
                            LastEditDate = firstComment.LastEditDate,
                            Likes = firstComment.Likes,
                            MessageId = firstComment.MessageId,
                            ParentId = firstComment.ParentId,
                            CommentContent = firstComment.CommentContent
                        };

                        if (firstComment.Message.Anonymized || firstComment.Message.Subverses.anonymized_mode)
                        {
                            resultModel.Name = firstComment.Id.ToString();
                        }
                        else
                        {
                            resultModel.Name = firstComment.Name;
                        }

                        // TODO
                        // fetch child comments

                        resultList.Add(resultModel);
                    }

                    return resultList;

                }), TimeSpan.FromMinutes(5));

            }
            return cacheData;
        }
Exemplo n.º 2
0
        public IEnumerable<ApiComment> SubmissionComments(int submissionId)
        {
            var submission = _db.Messages.Find(submissionId);

            if (submission == null || submission.Subverses.admin_disabled == true)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var firstComments = from f in submission.Comments
                                let commentScore = f.Likes - f.Dislikes
                                where f.ParentId == null
                                orderby commentScore descending
                                select f;

            var resultList = new List<ApiComment>();

            foreach (var firstComment in firstComments.Take(10))
            {
                //do not show deleted comments unless they have replies
                if (firstComment.Name == "deleted" && submission.Comments.Count(a => a.ParentId == firstComment.Id) == 0)
                {
                    continue;
                }

                var resultModel = new ApiComment
                {
                    Id = firstComment.Id,
                    Date = firstComment.Date,
                    Dislikes = firstComment.Dislikes,
                    LastEditDate = firstComment.LastEditDate,
                    Likes = firstComment.Likes,
                    MessageId = firstComment.MessageId,
                    ParentId = firstComment.ParentId,
                    CommentContent = firstComment.CommentContent
                };

                if (firstComment.Message.Anonymized || firstComment.Message.Subverses.anonymized_mode)
                {
                    resultModel.Name = firstComment.Id.ToString();
                }
                else
                {
                    resultModel.Name = firstComment.Name;
                }

                // TODO
                // fetch child comments

                resultList.Add(resultModel);
            }

            return resultList;
        }
Exemplo n.º 3
0
        public ApiComment SingleComment(int id)
        {
            var comment = _db.Comments.Find(id);

            if (comment == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var resultModel = new ApiComment
            {
                Id = comment.Id,
                Date = comment.Date,
                LastEditDate = comment.LastEditDate,
                Likes = comment.Likes,
                Dislikes = comment.Dislikes,
                CommentContent = comment.CommentContent,
                ParentId = comment.ParentId,
                MessageId = comment.MessageId
            };

            if (comment.Message.Anonymized || comment.Message.Subverses.anonymized_mode)
            {
                resultModel.Name = comment.Id.ToString();
            }
            else
            {
                resultModel.Name = comment.Name;
            }

            return resultModel;
        }
Exemplo n.º 4
0
        public ApiComment SingleComment(int id)
        {
            var comment = _db.Comments.Find(id);

            if (comment == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var resultModel = new ApiComment
            {
                Id = comment.ID,
                Date = comment.CreationDate,
                LastEditDate = comment.LastEditDate,
                Likes = (int)comment.UpCount,
                Dislikes = (int)comment.DownCount,
                CommentContent = comment.Content,
                ParentId = comment.ParentID,
                MessageId = comment.SubmissionID
            };

            if (comment.Submission.IsAnonymized || comment.Submission.Subverse1.IsAnonymized)
            {
                resultModel.Name = comment.ID.ToString();
            }
            else
            {
                resultModel.Name = comment.UserName;
            }

            return resultModel;
        }