Ensure ChannelManager has access to API from point of construction

Closes https://github.com/ppy/osu/issues/18451.
This commit is contained in:
Dean Herbert 2022-06-08 18:54:23 +09:00
parent 4df8219c8f
commit c661f2b059
8 changed files with 27 additions and 19 deletions

View File

@ -25,7 +25,7 @@ namespace osu.Game.Tests.Chat
[SetUp] [SetUp]
public void Setup() => Schedule(() => public void Setup() => Schedule(() =>
{ {
var container = new ChannelManagerContainer(); var container = new ChannelManagerContainer(API);
Child = container; Child = container;
channelManager = container.ChannelManager; channelManager = container.ChannelManager;
}); });
@ -145,11 +145,11 @@ namespace osu.Game.Tests.Chat
private class ChannelManagerContainer : CompositeDrawable private class ChannelManagerContainer : CompositeDrawable
{ {
[Cached] [Cached]
public ChannelManager ChannelManager { get; } = new ChannelManager(); public ChannelManager ChannelManager { get; }
public ChannelManagerContainer() public ChannelManagerContainer(IAPIProvider apiProvider)
{ {
InternalChild = ChannelManager; InternalChild = ChannelManager = new ChannelManager(apiProvider);
} }
} }
} }

View File

@ -39,7 +39,7 @@ namespace osu.Game.Tests.Visual.Online
{ {
linkColour = colours.Blue; linkColour = colours.Blue;
var chatManager = new ChannelManager(); var chatManager = new ChannelManager(API);
BindableList<Channel> availableChannels = (BindableList<Channel>)chatManager.AvailableChannels; BindableList<Channel> availableChannels = (BindableList<Channel>)chatManager.AvailableChannels;
availableChannels.Add(new Channel { Name = "#english" }); availableChannels.Add(new Channel { Name = "#english" });
availableChannels.Add(new Channel { Name = "#japanese" }); availableChannels.Add(new Channel { Name = "#japanese" });

View File

@ -59,7 +59,7 @@ namespace osu.Game.Tests.Visual.Online
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
CachedDependencies = new (Type, object)[] CachedDependencies = new (Type, object)[]
{ {
(typeof(ChannelManager), channelManager = new ChannelManager()), (typeof(ChannelManager), channelManager = new ChannelManager(API)),
}, },
Children = new Drawable[] Children = new Drawable[]
{ {

View File

@ -44,7 +44,7 @@ namespace osu.Game.Tests.Visual.Online
Schedule(() => Schedule(() =>
{ {
Child = testContainer = new TestContainer(new[] { publicChannel, privateMessageChannel }) Child = testContainer = new TestContainer(API, new[] { publicChannel, privateMessageChannel })
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}; };
@ -229,7 +229,7 @@ namespace osu.Game.Tests.Visual.Online
private class TestContainer : Container private class TestContainer : Container
{ {
[Cached] [Cached]
public ChannelManager ChannelManager { get; } = new ChannelManager(); public ChannelManager ChannelManager { get; }
[Cached(typeof(INotificationOverlay))] [Cached(typeof(INotificationOverlay))]
public NotificationOverlay NotificationOverlay { get; } = new NotificationOverlay public NotificationOverlay NotificationOverlay { get; } = new NotificationOverlay
@ -245,9 +245,10 @@ namespace osu.Game.Tests.Visual.Online
private readonly Channel[] channels; private readonly Channel[] channels;
public TestContainer(Channel[] channels) public TestContainer(IAPIProvider api, Channel[] channels)
{ {
this.channels = channels; this.channels = channels;
ChannelManager = new ChannelManager(api);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]

View File

@ -11,6 +11,7 @@ using NUnit.Framework;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Chat; using osu.Game.Overlays.Chat;
using osuTK.Input; using osuTK.Input;
@ -44,17 +45,22 @@ namespace osu.Game.Tests.Visual.Online
Id = 5, Id = 5,
}; };
[Cached] private ChannelManager channelManager;
private ChannelManager channelManager = new ChannelManager();
private TestStandAloneChatDisplay chatDisplay; private TestStandAloneChatDisplay chatDisplay;
private int messageIdSequence; private int messageIdSequence;
private Channel testChannel; private Channel testChannel;
public TestSceneStandAloneChatDisplay() protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{ {
Add(channelManager); Add(channelManager = new ChannelManager(parent.Get<IAPIProvider>()));
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.Cache(channelManager);
return dependencies;
} }
[SetUp] [SetUp]

View File

@ -5,6 +5,7 @@ using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Online.API;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Overlays.Chat; using osu.Game.Overlays.Chat;
using osu.Game.Tournament.IPC; using osu.Game.Tournament.IPC;
@ -29,7 +30,7 @@ namespace osu.Game.Tournament.Components
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(MatchIPCInfo ipc) private void load(MatchIPCInfo ipc, IAPIProvider api)
{ {
if (ipc != null) if (ipc != null)
{ {
@ -45,7 +46,7 @@ namespace osu.Game.Tournament.Components
if (manager == null) if (manager == null)
{ {
AddInternal(manager = new ChannelManager { HighPollRate = { Value = true } }); AddInternal(manager = new ChannelManager(api) { HighPollRate = { Value = true } });
Channel.BindTo(manager.CurrentChannel); Channel.BindTo(manager.CurrentChannel);
} }

View File

@ -61,8 +61,7 @@ namespace osu.Game.Online.Chat
/// </summary> /// </summary>
public IBindableList<Channel> AvailableChannels => availableChannels; public IBindableList<Channel> AvailableChannels => availableChannels;
[Resolved] private readonly IAPIProvider api;
private IAPIProvider api { get; set; }
[Resolved] [Resolved]
private UserLookupCache users { get; set; } private UserLookupCache users { get; set; }
@ -71,8 +70,9 @@ namespace osu.Game.Online.Chat
private readonly IBindable<bool> isIdle = new BindableBool(); private readonly IBindable<bool> isIdle = new BindableBool();
public ChannelManager() public ChannelManager(IAPIProvider api)
{ {
this.api = api;
CurrentChannel.ValueChanged += currentChannelChanged; CurrentChannel.ValueChanged += currentChannelChanged;
} }

View File

@ -851,7 +851,7 @@ namespace osu.Game
loadComponentSingleFile(dashboard = new DashboardOverlay(), overlayContent.Add, true); loadComponentSingleFile(dashboard = new DashboardOverlay(), overlayContent.Add, true);
loadComponentSingleFile(news = new NewsOverlay(), overlayContent.Add, true); loadComponentSingleFile(news = new NewsOverlay(), overlayContent.Add, true);
var rankingsOverlay = loadComponentSingleFile(new RankingsOverlay(), overlayContent.Add, true); var rankingsOverlay = loadComponentSingleFile(new RankingsOverlay(), overlayContent.Add, true);
loadComponentSingleFile(channelManager = new ChannelManager(), AddInternal, true); loadComponentSingleFile(channelManager = new ChannelManager(API), AddInternal, true);
loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add, true); loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add, true);
loadComponentSingleFile(new MessageNotifier(), AddInternal, true); loadComponentSingleFile(new MessageNotifier(), AddInternal, true);
loadComponentSingleFile(Settings = new SettingsOverlay(), leftFloatingOverlayContent.Add, true); loadComponentSingleFile(Settings = new SettingsOverlay(), leftFloatingOverlayContent.Add, true);