Actually use the fact that ChannelManager is now a component

This commit is contained in:
miterosan 2018-04-11 20:37:51 +02:00
parent 2056258def
commit c2020742b2
2 changed files with 20 additions and 13 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -19,24 +20,28 @@ namespace osu.Game.Online.Chat
/// <summary> /// <summary>
/// Manages everything channel related /// Manages everything channel related
/// </summary> /// </summary>
public class ChannelManager : Component, IOnlineComponent public class ChannelManager : Component, IOnlineComponent,
{ {
/// <summary> /// <summary>
/// The channels the player joins on startup /// The channels the player joins on startup
/// </summary> /// </summary>
private readonly string[] defaultChannels = private readonly string[] defaultChannels =
{ {
@"#lazer", @"#osu", @"#lobby" @"#lazer",
@"#osu",
@"#lobby"
}; };
/// <summary> /// <summary>
/// The currently opened channel /// The currently opened channel
/// </summary> /// </summary>
public Bindable<Channel> CurrentChannel { get; } = new Bindable<Channel>(); public Bindable<Channel> CurrentChannel { get; } = new Bindable<Channel>();
/// <summary> /// <summary>
/// The Channels the player has joined /// The Channels the player has joined
/// </summary> /// </summary>
public ObservableCollection<Channel> JoinedChannels { get; } = new ObservableCollection<Channel>(); public ObservableCollection<Channel> JoinedChannels { get; } = new ObservableCollection<Channel>();
/// <summary> /// <summary>
/// The channels available for the player to join /// The channels available for the player to join
/// </summary> /// </summary>
@ -68,9 +73,8 @@ namespace osu.Game.Online.Chat
?? new Channel(user); ?? new Channel(user);
} }
public ChannelManager(Scheduler scheduler) public ChannelManager()
{ {
this.scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler));
CurrentChannel.ValueChanged += currentChannelChanged; CurrentChannel.ValueChanged += currentChannelChanged;
} }
@ -131,6 +135,7 @@ namespace osu.Game.Online.Chat
CurrentChannel.Value.AddNewMessages(new ErrorMessage("Usage: /me [action]")); CurrentChannel.Value.AddNewMessages(new ErrorMessage("Usage: /me [action]"));
break; break;
} }
PostMessage(content, true); PostMessage(content, true);
break; break;
@ -253,7 +258,7 @@ namespace osu.Game.Online.Chat
{ {
JoinedChannels.Add(channel); JoinedChannels.Add(channel);
var fetchInitialMsgReq = new GetChannelMessagesRequest(new[] {channel}, null); var fetchInitialMsgReq = new GetChannelMessagesRequest(new[] { channel }, null);
fetchInitialMsgReq.Success += handleChannelMessages; fetchInitialMsgReq.Success += handleChannelMessages;
fetchInitialMsgReq.Failure += exception => Logger.Error(exception, "Failed to fetch inital messages."); fetchInitialMsgReq.Failure += exception => Logger.Error(exception, "Failed to fetch inital messages.");
api.Queue(fetchInitialMsgReq); api.Queue(fetchInitialMsgReq);
@ -268,8 +273,6 @@ namespace osu.Game.Online.Chat
public void APIStateChanged(APIAccess api, APIState state) public void APIStateChanged(APIAccess api, APIState state)
{ {
this.api = api ?? throw new ArgumentNullException(nameof(api));
switch (state) switch (state)
{ {
case APIState.Online: case APIState.Online:
@ -285,5 +288,12 @@ namespace osu.Game.Online.Chat
break; break;
} }
} }
[BackgroundDependencyLoader]
private void load(IAPIProvider api)
{
this.api = this.api;
api.Register(this);
}
} }
} }

View File

@ -113,10 +113,7 @@ namespace osu.Game
dependencies.Cache(api); dependencies.Cache(api);
dependencies.CacheAs<IAPIProvider>(api); dependencies.CacheAs<IAPIProvider>(api);
var chatManager = new ChannelManager(Scheduler); dependencies.Cache(new ChannelManager());
api.Register(chatManager);
dependencies.Cache(chatManager);
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory)); dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage)); dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));