1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-05 11:43:01 +08:00

Make replies addition more consistent

This commit is contained in:
Andrei Zavatski 2020-02-13 02:47:13 +03:00
parent c6f8e157fd
commit b0db155565
2 changed files with 9 additions and 13 deletions

View File

@ -89,7 +89,7 @@ namespace osu.Game.Overlays.Comments
}
// No need to find parent for top-level comment
if (comment.IsTopLevel)
if (!comment.ParentId.HasValue)
continue;
if (nodeDictionary.ContainsKey(comment.ParentId.Value))
@ -112,7 +112,7 @@ namespace osu.Game.Overlays.Comments
var replies = comment.ChildComments;
if (replies.Any())
drawableComment.InitialReplies.AddRange(replies.Select(createCommentWithReplies));
drawableComment.Replies.AddRange(replies.Select(createCommentWithReplies));
return drawableComment;
}
@ -139,7 +139,7 @@ namespace osu.Game.Overlays.Comments
uniqueComments.ForEach(c => c.ParentComment = drawableComment.Comment);
drawableComment.AddReplies(uniqueComments.Select(createDrawableComment));
drawableComment.Replies.AddRange(uniqueComments.Select(createDrawableComment));
}
private DrawableComment createDrawableComment(Comment comment) => new DrawableComment(comment)

View File

@ -37,10 +37,7 @@ namespace osu.Game.Overlays.Comments
public readonly Bindable<CommentsSortCriteria> Sort = new Bindable<CommentsSortCriteria>();
private readonly Dictionary<long, Comment> loadedReplies = new Dictionary<long, Comment>();
/// <summary>
/// <see cref="DrawableComment"/>s which will be added to this <see cref="DrawableComment"/> as replies on initial load.
/// </summary>
public readonly List<DrawableComment> InitialReplies = new List<DrawableComment>();
public readonly BindableList<DrawableComment> Replies = new BindableList<DrawableComment>();
private readonly BindableBool childrenExpanded = new BindableBool(true);
@ -272,8 +269,10 @@ namespace osu.Game.Overlays.Comments
});
}
if (InitialReplies.Any())
AddReplies(InitialReplies);
Replies.ItemsAdded += onRepliesAdded;
if (Replies.Any())
onRepliesAdded(Replies);
}
protected override void LoadComplete()
@ -292,11 +291,8 @@ namespace osu.Game.Overlays.Comments
public bool ContainsReply(long replyId) => loadedReplies.ContainsKey(replyId);
public void AddReplies(IEnumerable<DrawableComment> replies)
private void onRepliesAdded(IEnumerable<DrawableComment> replies)
{
if (LoadState == LoadState.NotLoaded)
throw new NotSupportedException($@"Can't use {nameof(AddReplies)} when not loaded.");
var page = createRepliesPage(replies);
if (LoadState == LoadState.Loading)