protected CommentResponse BuildCommentResponse( Comment comment, bool canUserSeeNotApprovedComments, DefaultDictionary <int, List <Comment> > replies, DefaultDictionary <int, int> commentLikesCount, HashSet <int> likedByUserCommentsIds, [CanBeNull] Dictionary <string, List <Group> > authorId2Groups, [CanBeNull] HashSet <string> authorsWithPassed, [CanBeNull] HashSet <int> userAvailableGroups, bool canViewAllGroupMembers, bool addCourseIdAndSlideId, bool addParentCommentId, bool addReplies ) { var commentInfo = new CommentResponse { Id = comment.Id, Text = comment.Text, RenderedText = CommentTextHelper.RenderCommentTextToHtml(comment.Text), Author = BuildShortUserInfo(comment.Author), PublishTime = comment.PublishTime, IsApproved = comment.IsApproved, IsLiked = likedByUserCommentsIds.Contains(comment.Id), LikesCount = commentLikesCount[comment.Id], IsPassed = authorsWithPassed?.Contains(comment.AuthorId) ?? false, Replies = new List <CommentResponse>() }; if (authorId2Groups != null && userAvailableGroups != null && authorId2Groups.ContainsKey(comment.Author.Id)) { commentInfo.AuthorGroups = authorId2Groups[comment.AuthorId] .Where(g => canViewAllGroupMembers || userAvailableGroups.Contains(g.Id)) .Select(BuildShortGroupInfo) .ToList().NullIfEmpty(); } if (addCourseIdAndSlideId) { commentInfo.CourseId = comment.CourseId; commentInfo.SlideId = comment.SlideId; } if (addParentCommentId && !comment.IsTopLevel) { commentInfo.ParentCommentId = comment.ParentCommentId; } if (!comment.IsTopLevel) { commentInfo.IsCorrectAnswer = comment.IsCorrectAnswer; return(commentInfo); } commentInfo.IsPinnedToTop = comment.IsPinnedToTop; if (addReplies) { var commentReplies = FilterVisibleComments(replies[comment.Id], canUserSeeNotApprovedComments); commentInfo.Replies = BuildCommentsListResponse(commentReplies, canUserSeeNotApprovedComments, null, commentLikesCount, likedByUserCommentsIds, authorId2Groups, authorsWithPassed, userAvailableGroups, canViewAllGroupMembers, addCourseIdAndSlideId, addParentCommentId, addReplies); } return(commentInfo); }
public static ReviewCommentResponse Build(ExerciseCodeReviewComment comment) { return(new ReviewCommentResponse { Id = comment.Id, Text = comment.Text, RenderedText = CommentTextHelper.RenderCommentTextToHtml(comment.Text), PublishTime = comment.AddingTime, Author = BaseController.BuildShortUserInfo(comment.Author) }); }
public static ReviewInfo Build(ExerciseCodeReview r, [CanBeNull] IEnumerable <ExerciseCodeReviewComment> comments, bool isUlearnBot) { return(new ReviewInfo { Id = r.Id, Comment = r.Comment, RenderedComment = CommentTextHelper.RenderCommentTextToHtml(r.Comment), Author = isUlearnBot ? null : BaseController.BuildShortUserInfo(r.Author), AddingTime = isUlearnBot || r.AddingTime <= DateTime.UnixEpoch ? (DateTime?)null : r.AddingTime, FinishLine = r.FinishLine, FinishPosition = r.FinishPosition, StartLine = r.StartLine, StartPosition = r.StartPosition, Comments = comments .EmptyIfNull() .OrderBy(c => c.AddingTime) .Select(ReviewCommentResponse.Build) .ToList() }); }