From 68b3687315228dae283eb8ad1591e423bae166fb Mon Sep 17 00:00:00 2001 From: Zihad Date: Fri, 28 Mar 2025 16:06:49 +0600 Subject: [PATCH] Revert "Hide blocked users from currently online" This reverts commits 7ca3a1895a412092da45c7db10c3c7babec59b40 and fbdea8f99019779e15babf2e41b9dda6da84aa70. --- .../Online/TestSceneCurrentlyOnlineDisplay.cs | 82 ------------------- .../Dashboard/CurrentlyOnlineDisplay.cs | 64 ++------------- 2 files changed, 7 insertions(+), 139 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneCurrentlyOnlineDisplay.cs b/osu.Game.Tests/Visual/Online/TestSceneCurrentlyOnlineDisplay.cs index 8e99212bcb..a1d0d40811 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneCurrentlyOnlineDisplay.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneCurrentlyOnlineDisplay.cs @@ -9,7 +9,6 @@ using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Testing; using osu.Game.Database; -using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Metadata; using osu.Game.Online.Spectator; @@ -100,87 +99,6 @@ namespace osu.Game.Tests.Visual.Online AddStep("End watching user presence", () => token.Dispose()); } - [Test] - public void TestBlockedUsersHidden() - { - IDisposable token = null!; - - AddStep("Clear blocks", () => - { - DummyAPIAccess api = (DummyAPIAccess)API; - api.Blocks.Clear(); - }); - - AddStep("Begin watching user presence", () => token = metadataClient.BeginWatchingUserPresence()); - AddStep("Add online user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, new UserPresence { Status = UserStatus.Online, Activity = new UserActivity.InSoloGame() })); - AddUntilStep("Panel loaded", () => currentlyOnline.ChildrenOfType().FirstOrDefault()?.User.Id == streamingUser.Id); - - AddStep("Block online user", () => - { - DummyAPIAccess api = (DummyAPIAccess)API; - api.Blocks.Add(new APIRelation() - { - RelationType = RelationType.Block, - TargetUser = streamingUser, - TargetID = streamingUser.Id - }); - }); - - AddAssert("Blocked user not shown", () => currentlyOnline.ChildrenOfType().All(p => p.User.Id != streamingUser.Id)); - - AddStep("Unblock online user", () => - { - DummyAPIAccess api = (DummyAPIAccess)API; - api.Blocks.RemoveAll(b => b.TargetID == streamingUser.Id); - }); - - AddAssert("Unblocked user shown again", () => currentlyOnline.ChildrenOfType().Any(p => p.User.Id == streamingUser.Id)); - - AddStep("Remove playing user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, null)); - AddStep("End watching user presence", () => token.Dispose()); - } - - [Test] - public void TestUnblockedOfflineUsersHidden() - { - IDisposable token = null!; - - AddStep("Clear blocks", () => - { - DummyAPIAccess api = (DummyAPIAccess)API; - api.Blocks.Clear(); - }); - - AddStep("Begin watching user presence", () => token = metadataClient.BeginWatchingUserPresence()); - AddStep("Add online user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, new UserPresence { Status = UserStatus.Online, Activity = new UserActivity.InSoloGame() })); - AddUntilStep("Panel loaded", () => currentlyOnline.ChildrenOfType().FirstOrDefault()?.User.Id == streamingUser.Id); - - AddStep("Block online user", () => - { - DummyAPIAccess api = (DummyAPIAccess)API; - api.Blocks.Add(new APIRelation() - { - RelationType = RelationType.Block, - TargetUser = streamingUser, - TargetID = streamingUser.Id - }); - }); - - AddAssert("Blocked user not shown", () => currentlyOnline.ChildrenOfType().All(p => p.User.Id != streamingUser.Id)); - - AddStep("Remove playing user", () => metadataClient.UserPresenceUpdated(streamingUser.Id, null)); - - AddStep("Unblock offline user", () => - { - DummyAPIAccess api = (DummyAPIAccess)API; - api.Blocks.RemoveAll(b => b.TargetID == streamingUser.Id); - }); - - AddAssert("Unblocked offline user not shown", () => currentlyOnline.ChildrenOfType().All(p => p.User.Id != streamingUser.Id)); - - AddStep("End watching user presence", () => token.Dispose()); - } - internal partial class TestUserLookupCache : UserLookupCache { private static readonly string[] usernames = diff --git a/osu.Game/Overlays/Dashboard/CurrentlyOnlineDisplay.cs b/osu.Game/Overlays/Dashboard/CurrentlyOnlineDisplay.cs index bda23078d9..39df3ba22c 100644 --- a/osu.Game/Overlays/Dashboard/CurrentlyOnlineDisplay.cs +++ b/osu.Game/Overlays/Dashboard/CurrentlyOnlineDisplay.cs @@ -2,9 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; -using System.Collections.Specialized; using System.Diagnostics; -using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions; @@ -16,7 +14,6 @@ using osu.Framework.Localisation; using osu.Framework.Screens; using osu.Game.Database; using osu.Game.Graphics.UserInterface; -using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Metadata; using osu.Game.Resources.Localisation.Web; @@ -34,7 +31,6 @@ namespace osu.Game.Overlays.Dashboard private const float padding = 10; private readonly IBindableDictionary onlineUserPresences = new BindableDictionary(); - private readonly IBindableList blockedUsers = new BindableList(); private readonly Dictionary userPanels = new Dictionary(); private SearchContainer userFlow = null!; @@ -46,9 +42,6 @@ namespace osu.Game.Overlays.Dashboard [Resolved] private UserLookupCache users { get; set; } = null!; - [Resolved] - private IAPIProvider api { get; set; } = null!; - [BackgroundDependencyLoader] private void load(OverlayColourProvider colourProvider) { @@ -102,8 +95,6 @@ namespace osu.Game.Overlays.Dashboard onlineUserPresences.BindTo(metadataClient.UserPresences); onlineUserPresences.BindCollectionChanged(onUserPresenceUpdated, true); - blockedUsers.BindTo(api.Blocks); - blockedUsers.BindCollectionChanged(onBlocksUpdated); } protected override void OnFocus(FocusEvent e) @@ -113,36 +104,6 @@ namespace osu.Game.Overlays.Dashboard searchTextBox.TakeFocus(); } - private void onBlocksUpdated(object? sender, NotifyCollectionChangedEventArgs e) - { - switch (e.Action) - { - case NotifyCollectionChangedAction.Add: - Debug.Assert(e.NewItems != null); - - foreach (APIRelation block in e.NewItems.Cast()) - { - int userId = block.TargetID; - removeUserPanel(userId); - } - - break; - - case NotifyCollectionChangedAction.Remove: - Debug.Assert(e.OldItems != null); - - foreach (APIRelation block in e.OldItems) - { - int userId = block.TargetID; - if (!onlineUserPresences.ContainsKey(userId)) continue; - - addUserPanel(userId); - } - - break; - } - } - private void onUserPresenceUpdated(object? sender, NotifyDictionaryChangedEventArgs e) => Schedule(() => { switch (e.Action) @@ -153,9 +114,12 @@ namespace osu.Game.Overlays.Dashboard foreach (var kvp in e.NewItems) { int userId = kvp.Key; - if (blockedUsers.Any(b => b.TargetID == userId)) continue; - addUserPanel(userId); + users.GetUserAsync(userId).ContinueWith(task => + { + if (task.GetResultSafely() is APIUser user) + Schedule(() => userFlow.Add(userPanels[userId] = createUserPanel(user))); + }); } break; @@ -166,28 +130,14 @@ namespace osu.Game.Overlays.Dashboard foreach (var kvp in e.OldItems) { int userId = kvp.Key; - removeUserPanel(userId); + if (userPanels.Remove(userId, out var userPanel)) + userPanel.Expire(); } break; } }); - private void addUserPanel(int userId) - { - users.GetUserAsync(userId).ContinueWith(task => - { - if (task.GetResultSafely() is APIUser user) - Schedule(() => userFlow.Add(userPanels[userId] = createUserPanel(user))); - }); - } - - private void removeUserPanel(int userId) - { - if (userPanels.Remove(userId, out var userPanel)) - userPanel.Expire(); - } - private OnlineUserPanel createUserPanel(APIUser user) => new OnlineUserPanel(user).With(panel => {