From 05ff4de944626e031ec3c318d798aef92a3f1b34 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 21 Feb 2020 19:16:14 +0900 Subject: [PATCH] Remove the concept of orphaning and refactor --- osu.Game/Overlays/Comments/CommentsPage.cs | 27 ++++++---------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/osu.Game/Overlays/Comments/CommentsPage.cs b/osu.Game/Overlays/Comments/CommentsPage.cs index 65dabc4050..88e209ea2c 100644 --- a/osu.Game/Overlays/Comments/CommentsPage.cs +++ b/osu.Game/Overlays/Comments/CommentsPage.cs @@ -61,7 +61,7 @@ namespace osu.Game.Overlays.Comments return; } - appendComments(null, commentBundle); + appendComments(commentBundle); } private DrawableComment getDrawableComment(Comment comment) @@ -81,7 +81,7 @@ namespace osu.Game.Overlays.Comments { var request = new GetCommentsRequest(CommentableId.Value, Type.Value, Sort.Value, page, drawableComment.Comment.Id); - request.Success += response => Schedule(() => appendComments(drawableComment, response)); + request.Success += response => Schedule(() => appendComments(response)); api.PerformAsync(request); } @@ -89,16 +89,13 @@ namespace osu.Game.Overlays.Comments private readonly Dictionary commentDictionary = new Dictionary(); /// - /// Appends retrieved comments to the subtree rooted at a parenting . + /// Appends retrieved comments to the subtree of comments in this page. /// - /// The parenting . /// The bundle of comments to add. - private void appendComments([CanBeNull] DrawableComment parent, [NotNull] CommentBundle bundle) + private void appendComments([NotNull] CommentBundle bundle) { - var orphaned = new List(); - - foreach (var topLevel in bundle.Comments) - addNewComment(topLevel); + foreach (var child in bundle.Comments) + addNewComment(child); foreach (var child in bundle.IncludedComments) { @@ -109,10 +106,6 @@ namespace osu.Game.Overlays.Comments addNewComment(child); } - // Comments whose parents did not previously have corresponding drawables, are now guaranteed that their parents have corresponding drawables. - foreach (var o in orphaned) - addNewComment(o); - void addNewComment(Comment comment) { var drawableComment = getDrawableComment(comment); @@ -124,16 +117,10 @@ namespace osu.Game.Overlays.Comments } else if (commentDictionary.TryGetValue(comment.ParentId.Value, out var parentDrawable)) { - // The comment's parent already has a corresponding drawable, so add the parent<->child links. + // 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 does not have a corresponding drawable yet, so keep it as orphaned for the time being. - // Note that this comment's corresponding drawable has already been created by this point, so future children will be able to be added without being orphaned themselves. - orphaned.Add(comment); - } } }