Use polling connector in tests

This commit is contained in:
Dan Balasescu 2022-10-28 18:08:08 +09:00
parent 527b1d9db1
commit 169bcc2654
9 changed files with 44 additions and 17 deletions

View File

@ -13,6 +13,7 @@ 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
@ -151,7 +152,7 @@ namespace osu.Game.Tests.Chat
public ChannelManagerContainer(IAPIProvider apiProvider)
{
InternalChild = ChannelManager = new ChannelManager(apiProvider);
InternalChild = ChannelManager = new ChannelManager(apiProvider, new PollingNotificationsClientConnector(apiProvider));
}
}
}

View File

@ -14,6 +14,7 @@ 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;
@ -41,11 +42,13 @@ namespace osu.Game.Tests.Visual.Online
{
linkColour = colours.Blue;
var chatManager = new ChannelManager(API);
var chatManager = new ChannelManager(API, new PollingNotificationsClientConnector(API));
BindableList<Channel> availableChannels = (BindableList<Channel>)chatManager.AvailableChannels;
availableChannels.Add(new Channel { Name = "#english" });
availableChannels.Add(new Channel { Name = "#japanese" });
Dependencies.Cache(chatManager);
Add(chatManager);
}
[SetUp]

View File

@ -24,6 +24,7 @@ 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;
@ -59,7 +60,7 @@ namespace osu.Game.Tests.Visual.Online
RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[]
{
(typeof(ChannelManager), channelManager = new ChannelManager(API)),
(typeof(ChannelManager), channelManager = new ChannelManager(API, new PollingNotificationsClientConnector(API))),
},
Children = new Drawable[]
{

View File

@ -16,6 +16,7 @@ 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;
@ -250,7 +251,7 @@ namespace osu.Game.Tests.Visual.Online
public TestContainer(IAPIProvider api, Channel[] channels)
{
this.channels = channels;
ChannelManager = new ChannelManager(api);
ChannelManager = new ChannelManager(api, new PollingNotificationsClientConnector(api));
}
[BackgroundDependencyLoader]

View File

@ -15,6 +15,7 @@ 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;
@ -56,7 +57,9 @@ namespace osu.Game.Tests.Visual.Online
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
Add(channelManager = new ChannelManager(parent.Get<IAPIProvider>()));
var api = parent.Get<IAPIProvider>();
Add(channelManager = new ChannelManager(api, new PollingNotificationsClientConnector(api)));
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));

View File

@ -9,6 +9,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.Chat;
using osu.Game.Online.Notifications.WebSocket;
using osu.Game.Overlays.Chat;
using osu.Game.Tournament.IPC;
using osu.Game.Tournament.Models;
@ -48,7 +49,7 @@ namespace osu.Game.Tournament.Components
if (manager == null)
{
AddInternal(manager = new ChannelManager(api));
AddInternal(manager = new ChannelManager(api, new WebSocketNotificationsClientConnector(api)));
Channel.BindTo(manager.CurrentChannel);
}

View File

@ -65,20 +65,20 @@ namespace osu.Game.Online.Chat
public IBindableList<Channel> AvailableChannels => availableChannels;
private readonly IAPIProvider api;
private readonly NotificationsClientConnector connector;
[Resolved]
private UserLookupCache users { get; set; }
[Resolved]
private NotificationsClientConnector connector { get; set; }
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
private bool channelsInitialised;
private ScheduledDelegate ackDelegate;
public ChannelManager(IAPIProvider api)
public ChannelManager(IAPIProvider api, NotificationsClientConnector connector)
{
this.api = api;
this.connector = connector;
CurrentChannel.ValueChanged += currentChannelChanged;
}
@ -603,6 +603,12 @@ namespace osu.Game.Online.Chat
api.Queue(req);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
connector?.Dispose();
}
}
/// <summary>

View File

@ -6,13 +6,12 @@ using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Logging;
using osu.Game.Online.API;
namespace osu.Game.Online
{
public abstract class SocketClientConnector : Component
public abstract class SocketClientConnector : IDisposable
{
/// <summary>
/// Whether this is connected to the hub, use <see cref="CurrentConnection"/> to access the connection, if this is <c>true</c>.
@ -173,11 +172,23 @@ namespace osu.Game.Online
public override string ToString() => $"{ClientName} ({(IsConnected.Value ? "connected" : "not connected")})";
protected override void Dispose(bool isDisposing)
private bool isDisposed;
protected virtual void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (isDisposed)
return;
apiState.UnbindAll();
cancelExistingConnect();
isDisposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}

View File

@ -45,7 +45,7 @@ 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.Polling;
using osu.Game.Online.Notifications.WebSocket;
using osu.Game.Overlays;
using osu.Game.Overlays.Music;
using osu.Game.Overlays.Notifications;
@ -757,6 +757,7 @@ namespace osu.Game
BackButton.Receptor receptor;
dependencies.CacheAs(idleTracker = new GameIdleTracker(6000));
dependencies.CacheAs(notificationsClient = new WebSocketNotificationsClientConnector(API));
var sessionIdleTracker = new GameIdleTracker(300000);
sessionIdleTracker.IsIdle.BindValueChanged(idle =>
@ -883,8 +884,7 @@ namespace osu.Game
loadComponentSingleFile(dashboard = new DashboardOverlay(), overlayContent.Add, true);
loadComponentSingleFile(news = new NewsOverlay(), overlayContent.Add, true);
var rankingsOverlay = loadComponentSingleFile(new RankingsOverlay(), overlayContent.Add, true);
loadComponentSingleFile(notificationsClient = new PollingNotificationsClientConnector(API), AddInternal, true);
loadComponentSingleFile(channelManager = new ChannelManager(API), AddInternal, true);
loadComponentSingleFile(channelManager = new ChannelManager(API, notificationsClient), AddInternal, true);
loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add, true);
loadComponentSingleFile(new MessageNotifier(), AddInternal, true);
loadComponentSingleFile(Settings = new SettingsOverlay(), leftFloatingOverlayContent.Add, true);