1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 03:27:24 +08:00

Add back orphaning as a fail-safe

This commit is contained in:
smoogipoo 2020-02-21 19:41:00 +09:00
parent 05ff4de944
commit 4c083e0e7e

View File

@ -89,13 +89,15 @@ namespace osu.Game.Overlays.Comments
private readonly Dictionary<long, DrawableComment> commentDictionary = new Dictionary<long, DrawableComment>();
/// <summary>
/// Appends retrieved comments to the subtree of comments in this page.
/// 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)
{
foreach (var child in bundle.Comments)
addNewComment(child);
var orphaned = new List<Comment>();
foreach (var topLevel in bundle.Comments)
addNewComment(topLevel);
foreach (var child in bundle.IncludedComments)
{
@ -106,6 +108,10 @@ namespace osu.Game.Overlays.Comments
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);
@ -121,6 +127,12 @@ namespace osu.Game.Overlays.Comments
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);
}
}
}