From 5b25ef5f2fcc7d4c1db03cd529733fb8375237c4 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 1 Nov 2022 21:34:34 +0900 Subject: [PATCH] Construct notifications client via IAPIProvider --- osu.Game.Tests/Chat/TestSceneChannelManager.cs | 3 +-- osu.Game.Tests/Visual/Online/TestSceneChatLink.cs | 3 +-- osu.Game.Tests/Visual/Online/TestSceneChatOverlay.cs | 3 +-- osu.Game.Tests/Visual/Online/TestSceneMessageNotifier.cs | 3 +-- .../Visual/Online/TestSceneStandAloneChatDisplay.cs | 3 +-- osu.Game/Online/API/APIAccess.cs | 5 +++++ osu.Game/Online/API/DummyAPIAccess.cs | 4 ++++ osu.Game/Online/API/IAPIProvider.cs | 6 ++++++ osu.Game/OsuGame.cs | 3 +-- 9 files changed, 21 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/Chat/TestSceneChannelManager.cs b/osu.Game.Tests/Chat/TestSceneChannelManager.cs index 84609a2733..86be638781 100644 --- a/osu.Game.Tests/Chat/TestSceneChannelManager.cs +++ b/osu.Game.Tests/Chat/TestSceneChannelManager.cs @@ -13,7 +13,6 @@ using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Chat; -using osu.Game.Online.Notifications.Polling; using osu.Game.Tests.Visual; namespace osu.Game.Tests.Chat @@ -152,7 +151,7 @@ namespace osu.Game.Tests.Chat public ChannelManagerContainer(IAPIProvider apiProvider) { - InternalChild = ChannelManager = new ChannelManager(apiProvider, new PollingNotificationsClientConnector(apiProvider)); + InternalChild = ChannelManager = new ChannelManager(apiProvider, apiProvider.GetNotificationsConnector()); } } } diff --git a/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs b/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs index 63526d4278..5c46cd96be 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneChatLink.cs @@ -14,7 +14,6 @@ using osu.Framework.Graphics.Containers; using osu.Game.Graphics; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Chat; -using osu.Game.Online.Notifications.Polling; using osu.Game.Overlays.Chat; using osuTK.Graphics; @@ -42,7 +41,7 @@ namespace osu.Game.Tests.Visual.Online { linkColour = colours.Blue; - var chatManager = new ChannelManager(API, new PollingNotificationsClientConnector(API)); + var chatManager = new ChannelManager(API, API.GetNotificationsConnector()); BindableList availableChannels = (BindableList)chatManager.AvailableChannels; availableChannels.Add(new Channel { Name = "#english" }); availableChannels.Add(new Channel { Name = "#japanese" }); diff --git a/osu.Game.Tests/Visual/Online/TestSceneChatOverlay.cs b/osu.Game.Tests/Visual/Online/TestSceneChatOverlay.cs index dee258f747..6b2124f1f8 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneChatOverlay.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneChatOverlay.cs @@ -24,7 +24,6 @@ using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Chat; -using osu.Game.Online.Notifications.Polling; using osu.Game.Overlays; using osu.Game.Overlays.Chat; using osu.Game.Overlays.Chat.Listing; @@ -60,7 +59,7 @@ namespace osu.Game.Tests.Visual.Online RelativeSizeAxes = Axes.Both, CachedDependencies = new (Type, object)[] { - (typeof(ChannelManager), channelManager = new ChannelManager(API, new PollingNotificationsClientConnector(API))), + (typeof(ChannelManager), channelManager = new ChannelManager(API, API.GetNotificationsConnector())), }, Children = new Drawable[] { diff --git a/osu.Game.Tests/Visual/Online/TestSceneMessageNotifier.cs b/osu.Game.Tests/Visual/Online/TestSceneMessageNotifier.cs index 6d83fb3123..cb93812bc2 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneMessageNotifier.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneMessageNotifier.cs @@ -16,7 +16,6 @@ using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Chat; -using osu.Game.Online.Notifications.Polling; using osu.Game.Overlays; using osu.Game.Overlays.Notifications; using osuTK.Input; @@ -251,7 +250,7 @@ namespace osu.Game.Tests.Visual.Online public TestContainer(IAPIProvider api, Channel[] channels) { this.channels = channels; - ChannelManager = new ChannelManager(api, new PollingNotificationsClientConnector(api)); + ChannelManager = new ChannelManager(api, api.GetNotificationsConnector()); } [BackgroundDependencyLoader] diff --git a/osu.Game.Tests/Visual/Online/TestSceneStandAloneChatDisplay.cs b/osu.Game.Tests/Visual/Online/TestSceneStandAloneChatDisplay.cs index f1daa05e08..07196cc92a 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneStandAloneChatDisplay.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneStandAloneChatDisplay.cs @@ -15,7 +15,6 @@ using osu.Framework.Testing; using osu.Framework.Utils; using osu.Game.Online.API; using osu.Game.Online.API.Requests.Responses; -using osu.Game.Online.Notifications.Polling; using osu.Game.Overlays.Chat; using osuTK.Input; @@ -59,7 +58,7 @@ namespace osu.Game.Tests.Visual.Online { var api = parent.Get(); - Add(channelManager = new ChannelManager(api, new PollingNotificationsClientConnector(api))); + Add(channelManager = new ChannelManager(api, api.GetNotificationsConnector())); var dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index a0c8e0d555..8ac2e2d453 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -20,6 +20,8 @@ using osu.Framework.Logging; using osu.Game.Configuration; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; +using osu.Game.Online.Notifications; +using osu.Game.Online.Notifications.WebSocket; using osu.Game.Users; namespace osu.Game.Online.API @@ -299,6 +301,9 @@ namespace osu.Game.Online.API public IHubClientConnector GetHubConnector(string clientName, string endpoint, bool preferMessagePack) => new HubClientConnector(clientName, endpoint, this, versionHash, preferMessagePack); + public NotificationsClientConnector GetNotificationsConnector() => + new WebSocketNotificationsClientConnector(this); + public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password) { Debug.Assert(State.Value == APIState.Offline); diff --git a/osu.Game/Online/API/DummyAPIAccess.cs b/osu.Game/Online/API/DummyAPIAccess.cs index 7dc34d1293..865e1e0a70 100644 --- a/osu.Game/Online/API/DummyAPIAccess.cs +++ b/osu.Game/Online/API/DummyAPIAccess.cs @@ -9,6 +9,8 @@ using System.Threading.Tasks; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Game.Online.API.Requests.Responses; +using osu.Game.Online.Notifications; +using osu.Game.Online.Notifications.Polling; using osu.Game.Users; namespace osu.Game.Online.API @@ -115,6 +117,8 @@ namespace osu.Game.Online.API public IHubClientConnector GetHubConnector(string clientName, string endpoint, bool preferMessagePack) => null; + public NotificationsClientConnector GetNotificationsConnector() => new PollingNotificationsClientConnector(this); + public RegistrationRequest.RegistrationRequestErrors CreateAccount(string email, string username, string password) { Thread.Sleep(200); diff --git a/osu.Game/Online/API/IAPIProvider.cs b/osu.Game/Online/API/IAPIProvider.cs index a90b11e354..6054effaa1 100644 --- a/osu.Game/Online/API/IAPIProvider.cs +++ b/osu.Game/Online/API/IAPIProvider.cs @@ -5,6 +5,7 @@ using System; using System.Threading.Tasks; using osu.Framework.Bindables; using osu.Game.Online.API.Requests.Responses; +using osu.Game.Online.Notifications; using osu.Game.Users; namespace osu.Game.Online.API @@ -112,6 +113,11 @@ namespace osu.Game.Online.API /// Whether to use MessagePack for serialisation if available on this platform. IHubClientConnector? GetHubConnector(string clientName, string endpoint, bool preferMessagePack = true); + /// + /// Constructs a new . + /// + NotificationsClientConnector GetNotificationsConnector(); + /// /// Create a new user account. This is a blocking operation. /// diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index c1db9630a0..7384c2a297 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -45,7 +45,6 @@ using osu.Game.Online; using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.Chat; using osu.Game.Online.Notifications; -using osu.Game.Online.Notifications.WebSocket; using osu.Game.Overlays; using osu.Game.Overlays.Music; using osu.Game.Overlays.Notifications; @@ -759,7 +758,7 @@ namespace osu.Game BackButton.Receptor receptor; dependencies.CacheAs(idleTracker = new GameIdleTracker(6000)); - dependencies.CacheAs(notificationsClient = new WebSocketNotificationsClientConnector(API)); + dependencies.CacheAs(notificationsClient = API.GetNotificationsConnector()); var sessionIdleTracker = new GameIdleTracker(300000); sessionIdleTracker.IsIdle.BindValueChanged(idle =>