private static int GetWatermark(this ICommentDiscussionHeader discussion, int userId) { var comments = discussion.Comments.Where(c => c.AuthorUserId == userId).Select(c => c.Id); var watermarks = discussion.Watermarks.Where(wm => wm.UserId == userId).Select(c => c.CommentId); return(comments.Union(watermarks).Union(0).Max()); }
public static int GetUnreadCount(this ICommentDiscussionHeader commentDiscussion, int currentUserId) { var watermark = commentDiscussion.GetWatermark(currentUserId); return(commentDiscussion.Comments.Where(c => c.IsVisibleTo(currentUserId)).Count(comment => watermark < comment.Id)); }