1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 16:02:58 +08:00

Remove the concept of orphaning and refactor

This commit is contained in:
smoogipoo 2020-02-21 19:16:14 +09:00
parent 4c3468f40e
commit 05ff4de944

View File

@ -61,7 +61,7 @@ namespace osu.Game.Overlays.Comments
return; return;
} }
appendComments(null, commentBundle); appendComments(commentBundle);
} }
private DrawableComment getDrawableComment(Comment comment) 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); 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); api.PerformAsync(request);
} }
@ -89,16 +89,13 @@ namespace osu.Game.Overlays.Comments
private readonly Dictionary<long, DrawableComment> commentDictionary = new Dictionary<long, DrawableComment>(); private readonly Dictionary<long, DrawableComment> commentDictionary = new Dictionary<long, DrawableComment>();
/// <summary> /// <summary>
/// Appends retrieved comments to the subtree rooted at a parenting <see cref="DrawableComment"/>. /// Appends retrieved comments to the subtree of comments in this page.
/// </summary> /// </summary>
/// <param name="parent">The parenting <see cref="DrawableComment"/>.</param>
/// <param name="bundle">The bundle of comments to add.</param> /// <param name="bundle">The bundle of comments to add.</param>
private void appendComments([CanBeNull] DrawableComment parent, [NotNull] CommentBundle bundle) private void appendComments([NotNull] CommentBundle bundle)
{ {
var orphaned = new List<Comment>(); foreach (var child in bundle.Comments)
addNewComment(child);
foreach (var topLevel in bundle.Comments)
addNewComment(topLevel);
foreach (var child in bundle.IncludedComments) foreach (var child in bundle.IncludedComments)
{ {
@ -109,10 +106,6 @@ namespace osu.Game.Overlays.Comments
addNewComment(child); 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) void addNewComment(Comment comment)
{ {
var drawableComment = getDrawableComment(comment); var drawableComment = getDrawableComment(comment);
@ -124,16 +117,10 @@ namespace osu.Game.Overlays.Comments
} }
else if (commentDictionary.TryGetValue(comment.ParentId.Value, out var parentDrawable)) 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; comment.ParentComment = parentDrawable.Comment;
parentDrawable.Replies.Add(drawableComment); 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);
}
} }
} }