From 5e369534b6a6d949c526a0fea2b802cf7b2d540c Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 4 Feb 2020 19:15:23 +0300 Subject: [PATCH 1/4] Allow guests to view comments --- osu.Game/Overlays/Comments/CommentsContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Comments/CommentsContainer.cs b/osu.Game/Overlays/Comments/CommentsContainer.cs index 8761b88b1e..15443ace88 100644 --- a/osu.Game/Overlays/Comments/CommentsContainer.cs +++ b/osu.Game/Overlays/Comments/CommentsContainer.cs @@ -148,7 +148,7 @@ namespace osu.Game.Overlays.Comments loadCancellation?.Cancel(); request = new GetCommentsRequest(type, id.Value, Sort.Value, currentPage++); request.Success += onSuccess; - api.Queue(request); + api.PerformAsync(request); } private void clearComments() From a84068448a2e40ffd81e94a8bacd42e4981c8403 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 4 Feb 2020 19:19:49 +0300 Subject: [PATCH 2/4] refetch comments on user change --- osu.Game/Overlays/Comments/CommentsContainer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/osu.Game/Overlays/Comments/CommentsContainer.cs b/osu.Game/Overlays/Comments/CommentsContainer.cs index 15443ace88..3d68f453b7 100644 --- a/osu.Game/Overlays/Comments/CommentsContainer.cs +++ b/osu.Game/Overlays/Comments/CommentsContainer.cs @@ -113,6 +113,7 @@ namespace osu.Game.Overlays.Comments protected override void LoadComplete() { + api.LocalUser.BindValueChanged(_ => refetchComments()); Sort.BindValueChanged(_ => refetchComments(), true); base.LoadComplete(); } From 9347c3f535e9820ed461ea5c11b62fd9d9a8d7a4 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 5 Feb 2020 11:13:32 +0300 Subject: [PATCH 3/4] Add trigger user change test --- .../Visual/Online/TestSceneCommentsContainer.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs index 9c526c4f81..33acc75fa8 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs @@ -10,6 +10,7 @@ using osu.Framework.Graphics; using osu.Game.Overlays.Comments; using osu.Game.Overlays; using osu.Framework.Allocation; +using osu.Game.Online.API; namespace osu.Game.Tests.Visual.Online { @@ -34,21 +35,26 @@ namespace osu.Game.Tests.Visual.Online [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); + private CommentsContainer comments; + private readonly BasicScrollContainer scroll; + public TestSceneCommentsContainer() { - BasicScrollContainer scroll; - CommentsContainer comments; - Add(scroll = new BasicScrollContainer { RelativeSizeAxes = Axes.Both, Child = comments = new CommentsContainer() }); + } + [BackgroundDependencyLoader] + private void load(IAPIProvider api) + { AddStep("Big Black comments", () => comments.ShowComments(CommentableType.Beatmapset, 41823)); AddStep("Airman comments", () => comments.ShowComments(CommentableType.Beatmapset, 24313)); AddStep("Lazer build comments", () => comments.ShowComments(CommentableType.Build, 4772)); AddStep("News comments", () => comments.ShowComments(CommentableType.NewsPost, 715)); + AddStep("Trigger user change", api.LocalUser.TriggerChange); AddStep("Idle state", () => { scroll.Clear(); From 5946ad7d809f7e7500ecc1a18d1f5310d47b635a Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Thu, 6 Feb 2020 16:54:02 +0300 Subject: [PATCH 4/4] Fix possible memory leak and better user change test support --- .../Online/TestSceneCommentsContainer.cs | 24 ++++++++++--------- .../Overlays/Comments/CommentsContainer.cs | 7 +++++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs b/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs index 33acc75fa8..2a43ba3f99 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneCommentsContainer.cs @@ -10,7 +10,8 @@ using osu.Framework.Graphics; using osu.Game.Overlays.Comments; using osu.Game.Overlays; using osu.Framework.Allocation; -using osu.Game.Online.API; +using osu.Framework.Bindables; +using osu.Game.Users; namespace osu.Game.Tests.Visual.Online { @@ -35,31 +36,32 @@ namespace osu.Game.Tests.Visual.Online [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); - private CommentsContainer comments; - private readonly BasicScrollContainer scroll; - public TestSceneCommentsContainer() { + BasicScrollContainer scroll; + TestCommentsContainer comments; + Add(scroll = new BasicScrollContainer { RelativeSizeAxes = Axes.Both, - Child = comments = new CommentsContainer() + Child = comments = new TestCommentsContainer() }); - } - [BackgroundDependencyLoader] - private void load(IAPIProvider api) - { AddStep("Big Black comments", () => comments.ShowComments(CommentableType.Beatmapset, 41823)); AddStep("Airman comments", () => comments.ShowComments(CommentableType.Beatmapset, 24313)); AddStep("Lazer build comments", () => comments.ShowComments(CommentableType.Build, 4772)); AddStep("News comments", () => comments.ShowComments(CommentableType.NewsPost, 715)); - AddStep("Trigger user change", api.LocalUser.TriggerChange); + AddStep("Trigger user change", comments.User.TriggerChange); AddStep("Idle state", () => { scroll.Clear(); - scroll.Add(comments = new CommentsContainer()); + scroll.Add(comments = new TestCommentsContainer()); }); } + + private class TestCommentsContainer : CommentsContainer + { + public new Bindable User => base.User; + } } } diff --git a/osu.Game/Overlays/Comments/CommentsContainer.cs b/osu.Game/Overlays/Comments/CommentsContainer.cs index 3d68f453b7..33a6be0d7a 100644 --- a/osu.Game/Overlays/Comments/CommentsContainer.cs +++ b/osu.Game/Overlays/Comments/CommentsContainer.cs @@ -12,6 +12,7 @@ using osu.Game.Online.API.Requests.Responses; using System.Threading; using System.Linq; using osu.Framework.Extensions.IEnumerableExtensions; +using osu.Game.Users; namespace osu.Game.Overlays.Comments { @@ -23,6 +24,8 @@ namespace osu.Game.Overlays.Comments public readonly Bindable Sort = new Bindable(); public readonly BindableBool ShowDeleted = new BindableBool(); + protected readonly Bindable User = new Bindable(); + [Resolved] private IAPIProvider api { get; set; } @@ -109,11 +112,13 @@ namespace osu.Game.Overlays.Comments } } }); + + User.BindTo(api.LocalUser); } protected override void LoadComplete() { - api.LocalUser.BindValueChanged(_ => refetchComments()); + User.BindValueChanged(_ => refetchComments()); Sort.BindValueChanged(_ => refetchComments(), true); base.LoadComplete(); }