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
1 changed files with 15 additions and 3 deletions

View File

@ -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);
}
}
}