1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 22:33:05 +08:00

Construct notifications client via IAPIProvider

This commit is contained in:
Dan Balasescu 2022-11-01 21:34:34 +09:00
parent 17f482bfc3
commit 5b25ef5f2f
9 changed files with 21 additions and 12 deletions

View File

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

View File

@ -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<Channel> availableChannels = (BindableList<Channel>)chatManager.AvailableChannels;
availableChannels.Add(new Channel { Name = "#english" });
availableChannels.Add(new Channel { Name = "#japanese" });

View File

@ -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[]
{

View File

@ -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]

View File

@ -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<IAPIProvider>();
Add(channelManager = new ChannelManager(api, new PollingNotificationsClientConnector(api)));
Add(channelManager = new ChannelManager(api, api.GetNotificationsConnector()));
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));

View File

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

View File

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

View File

@ -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
/// <param name="preferMessagePack">Whether to use MessagePack for serialisation if available on this platform.</param>
IHubClientConnector? GetHubConnector(string clientName, string endpoint, bool preferMessagePack = true);
/// <summary>
/// Constructs a new <see cref="NotificationsClientConnector"/>.
/// </summary>
NotificationsClientConnector GetNotificationsConnector();
/// <summary>
/// Create a new user account. This is a blocking operation.
/// </summary>

View File

@ -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 =>