public void TestSingleComment(bool withPinned)
        {
            var comment = new Comment
            {
                Id         = 1,
                Message    = "This is a single comment",
                LegacyName = "SingleUser",
                CreatedAt  = DateTimeOffset.Now,
                VotesCount = 0,
                Pinned     = withPinned,
            };

            var bundle = new CommentBundle
            {
                Comments = new List <Comment> {
                    comment
                },
                IncludedComments = new List <Comment>(),
                PinnedComments   = new List <Comment>(),
            };

            if (withPinned)
            {
                bundle.PinnedComments.Add(comment);
            }

            setUpCommentsResponse(bundle);
            AddStep("show comments", () => commentsContainer.ShowComments(CommentableType.Beatmapset, 123));
            AddUntilStep("wait comment load", () => commentsContainer.ChildrenOfType <DrawableComment>().Any());
            AddAssert("only one comment shown", () =>
                      commentsContainer.ChildrenOfType <DrawableComment>().Count(d => d.Comment.Pinned == withPinned) == 1);
        }
Esempio n. 2
0
        public void TestGenericRequestHandling()
        {
            AddStep("register request handling", () => ((DummyAPIAccess)API).HandleRequest = req =>
            {
                switch (req)
                {
                case CommentVoteRequest cRequest:
                    cRequest.TriggerSuccess(new CommentBundle());
                    break;
                }
            });

            CommentVoteRequest request  = null;
            CommentBundle      response = null;

            AddStep("fire request", () =>
            {
                response         = null;
                request          = new CommentVoteRequest(1, CommentVoteAction.Vote);
                request.Success += res => response = res;
                API.Queue(request);
            });

            AddAssert("response event fired", () => response != null);

            AddAssert("request has response", () => request.Result == response);
        }
Esempio n. 3
0
        private void onSuccess(CommentBundle response)
        {
            loadCancellation = new CancellationTokenSource();

            LoadComponentAsync(new CommentsPage(response)
            {
                ShowDeleted   = { BindTarget = ShowDeleted },
                Sort          = { BindTarget = Sort },
                Type          = { BindTarget = type },
                CommentableId = { BindTarget = id }
            }, loaded =>
            {
                content.Add(loaded);

                deletedCommentsCounter.Count.Value += response.Comments.Count(c => c.IsDeleted && c.IsTopLevel);

                if (response.HasMore)
                {
                    int loadedTopLevelComments = 0;
                    content.Children.OfType <FillFlowContainer>().ForEach(p => loadedTopLevelComments += p.Children.OfType <DrawableComment>().Count());

                    moreButton.Current.Value = response.TopLevelCount - loadedTopLevelComments;
                    moreButton.IsLoading     = false;
                }
                else
                {
                    moreButton.Hide();
                }

                commentCounter.Current.Value = response.Total;
            }, loadCancellation.Token);
        }
Esempio n. 4
0
        private void onSuccess(CommentBundle response)
        {
            var receivedComment = response.Comments.Single();

            isVoted.Value    = receivedComment.IsVoted;
            votesCount.Value = receivedComment.VotesCount;
            IsLoading        = false;
        }
 private void setUpCommentsResponse(CommentBundle commentBundle)
 => AddStep("set up response", () =>
 {
     dummyAPI.HandleRequest = request =>
     {
         if (!(request is GetCommentsRequest getCommentsRequest))
         {
             return(false);
Esempio n. 6
0
 private void createPage(CommentBundle commentBundle)
 {
     content.Clear();
     content.Add(new CommentsPage(commentBundle)
     {
         ShowDeleted = { BindTarget = showDeleted }
     });
 }
Esempio n. 7
0
        protected void OnSuccess(CommentBundle response)
        {
            commentCounter.Current.Value = response.Total;

            if (!response.Comments.Any())
            {
                content.Add(new NoCommentsPlaceholder());
                moreButton.Hide();
                return;
            }

            AppendComments(response);
        }
Esempio n. 8
0
        /// <summary>
        /// Appends retrieved comments to the subtree rooted of comments in this page.
        /// </summary>
        /// <param name="bundle">The bundle of comments to add.</param>
        private void appendComments([NotNull] CommentBundle bundle)
        {
            var orphaned = new List <Comment>();

            foreach (var topLevel in bundle.Comments)
            {
                addNewComment(topLevel);
            }

            foreach (var child in bundle.IncludedComments)
            {
                // Included comments can contain the parent comment, which already exists in the hierarchy.
                if (commentDictionary.ContainsKey(child.Id))
                {
                    continue;
                }

                addNewComment(child);
            }

            // Comments whose parents were seen later than themselves can now be added.
            foreach (var o in orphaned)
            {
                addNewComment(o);
            }

            void addNewComment(Comment comment)
            {
                var drawableComment = getDrawableComment(comment);

                if (comment.ParentId == null)
                {
                    // Comments that have no parent are added as top-level comments to the flow.
                    flow.Add(drawableComment);
                }
                else if (commentDictionary.TryGetValue(comment.ParentId.Value, out var parentDrawable))
                {
                    // The comment's parent has already been seen, so the parent<-> child links can be added.
                    comment.ParentComment = parentDrawable.Comment;
                    parentDrawable.Replies.Add(drawableComment);
                }
                else
                {
                    // The comment's parent has not been seen yet, so keep it orphaned for the time being. This can occur if the comments arrive out of order.
                    // Since this comment has now been seen, any further children can be added to it without being orphaned themselves.
                    orphaned.Add(comment);
                }
            }
        }
Esempio n. 9
0
        private void onSuccess(CommentBundle response)
        {
            loadCancellation = new CancellationTokenSource();

            var page = new FillFlowContainer
            {
                RelativeSizeAxes = Axes.X,
                AutoSizeAxes     = Axes.Y,
                Direction        = FillDirection.Vertical,
            };

            foreach (var c in response.Comments)
            {
                if (c.IsTopLevel)
                {
                    page.Add(new DrawableComment(c)
                    {
                        ShowDeleted = { BindTarget = ShowDeleted }
                    });
                }
            }

            LoadComponentAsync(page, loaded =>
            {
                content.Add(loaded);

                deletedChildrenPlaceholder.DeletedCount.Value += response.Comments.Count(c => c.IsDeleted && c.IsTopLevel);

                if (response.HasMore)
                {
                    int loadedTopLevelComments = 0;
                    content.Children.OfType <FillFlowContainer>().ForEach(p => loadedTopLevelComments += p.Children.OfType <DrawableComment>().Count());

                    moreButton.Current.Value = response.TopLevelCount - loadedTopLevelComments;
                    moreButton.IsLoading     = false;
                }

                commentCounter.Current.Value = response.Total;

                moreButton.FadeTo(response.HasMore ? 1 : 0);
            }, loadCancellation.Token);
        }
 public void ShowComments(CommentBundle bundle)
 {
     this.ChildrenOfType <TotalCommentsCounter>().Single().Current.Value = 0;
     ClearComments();
     OnSuccess(bundle);
 }
 public new void AppendComments([NotNull] CommentBundle bundle) => base.AppendComments(bundle);
 public TestCommentsPage(CommentBundle commentBundle)
     : base(commentBundle)
 {
 }
 public CommentsPage(CommentBundle commentBundle)
 {
     this.commentBundle = commentBundle;
 }
Esempio n. 14
0
        protected void AppendComments([NotNull] CommentBundle bundle)
        {
            var topLevelComments = new List <DrawableComment>();
            var orphaned         = new List <Comment>();

            foreach (var comment in bundle.Comments.Concat(bundle.IncludedComments).Concat(bundle.PinnedComments))
            {
                // Exclude possible duplicated comments.
                if (CommentDictionary.ContainsKey(comment.Id))
                {
                    continue;
                }

                addNewComment(comment);
            }

            // Comments whose parents were seen later than themselves can now be added.
            foreach (var o in orphaned)
            {
                addNewComment(o);
            }

            if (topLevelComments.Any())
            {
                LoadComponentsAsync(topLevelComments, loaded =>
                {
                    pinnedContent.AddRange(loaded.Where(d => d.Comment.Pinned));
                    content.AddRange(loaded.Where(d => !d.Comment.Pinned));

                    deletedCommentsCounter.Count.Value += topLevelComments.Select(d => d.Comment).Count(c => c.IsDeleted && c.IsTopLevel);

                    if (bundle.HasMore)
                    {
                        int loadedTopLevelComments = 0;
                        pinnedContent.Children.OfType <DrawableComment>().ForEach(p => loadedTopLevelComments++);
                        content.Children.OfType <DrawableComment>().ForEach(p => loadedTopLevelComments++);

                        moreButton.Current.Value = bundle.TopLevelCount - loadedTopLevelComments;
                        moreButton.IsLoading     = false;
                    }
                    else
                    {
                        moreButton.Hide();
                    }
                }, (loadCancellation = new CancellationTokenSource()).Token);
            }

            void addNewComment(Comment comment)
            {
                var drawableComment = getDrawableComment(comment);

                if (comment.ParentId == null)
                {
                    // Comments that have no parent are added as top-level comments to the flow.
                    topLevelComments.Add(drawableComment);
                }
                else if (CommentDictionary.TryGetValue(comment.ParentId.Value, out var parentDrawable))
                {
                    // The comment's parent has already been seen, so the parent<-> child links can be added.
                    comment.ParentComment = parentDrawable.Comment;
                    parentDrawable.Replies.Add(drawableComment);
                }
                else
                {
                    // The comment's parent has not been seen yet, so keep it orphaned for the time being. This can occur if the comments arrive out of order.
                    // Since this comment has now been seen, any further children can be added to it without being orphaned themselves.
                    orphaned.Add(comment);
                }
            }
        }