mirror of https://github.com/ppy/osu
Add back orphaning as a fail-safe
This commit is contained in:
parent
05ff4de944
commit
4c083e0e7e
|
@ -89,13 +89,15 @@ private void onCommentRepliesRequested(DrawableComment drawableComment, int page
|
|||
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 @@ private void appendComments([NotNull] CommentBundle bundle)
|
|||
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 @@ void addNewComment(Comment comment)
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue