From c2020742b2dbc5b3ced0a2b4fc1acb1f03798945 Mon Sep 17 00:00:00 2001 From: miterosan Date: Wed, 11 Apr 2018 20:37:51 +0200 Subject: [PATCH] Actually use the fact that ChannelManager is now a component --- osu.Game/Online/Chat/ChannelManager.cs | 28 +++++++++++++++++--------- osu.Game/OsuGameBase.cs | 5 +---- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/osu.Game/Online/Chat/ChannelManager.cs b/osu.Game/Online/Chat/ChannelManager.cs index f67e42dfdb..2d75881910 100644 --- a/osu.Game/Online/Chat/ChannelManager.cs +++ b/osu.Game/Online/Chat/ChannelManager.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; @@ -19,24 +20,28 @@ namespace osu.Game.Online.Chat /// /// Manages everything channel related /// - public class ChannelManager : Component, IOnlineComponent + public class ChannelManager : Component, IOnlineComponent, { /// /// The channels the player joins on startup /// private readonly string[] defaultChannels = { - @"#lazer", @"#osu", @"#lobby" + @"#lazer", + @"#osu", + @"#lobby" }; /// /// The currently opened channel /// public Bindable CurrentChannel { get; } = new Bindable(); + /// /// The Channels the player has joined /// public ObservableCollection JoinedChannels { get; } = new ObservableCollection(); + /// /// The channels available for the player to join /// @@ -56,7 +61,7 @@ namespace osu.Game.Online.Chat throw new ArgumentNullException(nameof(name)); CurrentChannel.Value = AvailableChannels.FirstOrDefault(c => c.Name == name) - ?? throw new ArgumentException($"Channel {name} was not found."); + ?? throw new ArgumentException($"Channel {name} was not found."); } public void OpenUserChannel(User user) @@ -65,12 +70,11 @@ namespace osu.Game.Online.Chat throw new ArgumentNullException(nameof(user)); CurrentChannel.Value = JoinedChannels.FirstOrDefault(c => c.Target == TargetType.User && c.Id == user.Id) - ?? new Channel(user); + ?? new Channel(user); } - public ChannelManager(Scheduler scheduler) + public ChannelManager() { - this.scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler)); CurrentChannel.ValueChanged += currentChannelChanged; } @@ -131,6 +135,7 @@ namespace osu.Game.Online.Chat CurrentChannel.Value.AddNewMessages(new ErrorMessage("Usage: /me [action]")); break; } + PostMessage(content, true); break; @@ -253,7 +258,7 @@ namespace osu.Game.Online.Chat { JoinedChannels.Add(channel); - var fetchInitialMsgReq = new GetChannelMessagesRequest(new[] {channel}, null); + var fetchInitialMsgReq = new GetChannelMessagesRequest(new[] { channel }, null); fetchInitialMsgReq.Success += handleChannelMessages; fetchInitialMsgReq.Failure += exception => Logger.Error(exception, "Failed to fetch inital messages."); api.Queue(fetchInitialMsgReq); @@ -268,8 +273,6 @@ namespace osu.Game.Online.Chat public void APIStateChanged(APIAccess api, APIState state) { - this.api = api ?? throw new ArgumentNullException(nameof(api)); - switch (state) { case APIState.Online: @@ -285,5 +288,12 @@ namespace osu.Game.Online.Chat break; } } + + [BackgroundDependencyLoader] + private void load(IAPIProvider api) + { + this.api = this.api; + api.Register(this); + } } } diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 6b4cb731d7..613755ea5d 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -113,10 +113,7 @@ namespace osu.Game dependencies.Cache(api); dependencies.CacheAs(api); - var chatManager = new ChannelManager(Scheduler); - api.Register(chatManager); - - dependencies.Cache(chatManager); + dependencies.Cache(new ChannelManager()); dependencies.Cache(RulesetStore = new RulesetStore(contextFactory)); dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));