Rename var chatmanager -> channelManager

Apply requested changes
This commit is contained in:
miterosan 2018-04-12 23:19:13 +02:00
parent b997f0f3fa
commit e39f5a1adf
7 changed files with 48 additions and 46 deletions

View File

@ -22,8 +22,7 @@ namespace osu.Game.Tests.Visual
{ {
typeof(ChatTabControl), typeof(ChatTabControl),
typeof(ChannelTabControl), typeof(ChannelTabControl),
typeof(UserTabControl), typeof(UserTabControl)
}; };
private readonly ChatTabControl chatTabControl; private readonly ChatTabControl chatTabControl;

View File

@ -23,15 +23,15 @@ namespace osu.Game.Graphics.Containers
public override bool HandleMouseInput => true; public override bool HandleMouseInput => true;
private OsuGame game; private OsuGame game;
private ChannelManager chatManager; private ChannelManager channelManager;
private Action showNotImplementedError; private Action showNotImplementedError;
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuGame game, NotificationOverlay notifications, ChannelManager chatManager) private void load(OsuGame game, NotificationOverlay notifications, ChannelManager channelManager)
{ {
// will be null in tests // will be null in tests
this.game = game; this.game = game;
this.chatManager = chatManager; this.channelManager = channelManager;
showNotImplementedError = () => notifications?.Post(new SimpleNotification showNotImplementedError = () => notifications?.Post(new SimpleNotification
{ {
Text = @"This link type is not yet supported!", Text = @"This link type is not yet supported!",
@ -80,9 +80,14 @@ namespace osu.Game.Graphics.Containers
game?.ShowBeatmapSet(setId); game?.ShowBeatmapSet(setId);
break; break;
case LinkAction.OpenChannel: case LinkAction.OpenChannel:
var channel = chatManager.AvailableChannels.FirstOrDefault(c => c.Name == linkArgument); try
if (channel != null) {
chatManager.CurrentChannel.Value = channel; channelManager.OpenChannel(linkArgument);
}
catch (ArgumentException)
{
//channel was not found
}
break; break;
case LinkAction.OpenEditorTimestamp: case LinkAction.OpenEditorTimestamp:
case LinkAction.JoinMultiplayerMatch: case LinkAction.JoinMultiplayerMatch:

View File

@ -9,12 +9,12 @@ using osu.Game.Online.Chat;
namespace osu.Game.Online.API.Requests namespace osu.Game.Online.API.Requests
{ {
public class GetChannelMessagesRequest : APIRequest<List<Message>> public class GetMessagesRequest : APIRequest<List<Message>>
{ {
private readonly IEnumerable<Channel> channels; private readonly IEnumerable<Channel> channels;
private long? since; private long? since;
public GetChannelMessagesRequest(IEnumerable<Channel> channels, long? sinceId) public GetMessagesRequest(IEnumerable<Channel> channels, long? sinceId)
{ {
if (channels == null) if (channels == null)
throw new ArgumentNullException(nameof(channels)); throw new ArgumentNullException(nameof(channels));

View File

@ -7,11 +7,11 @@ using osu.Game.Online.Chat;
namespace osu.Game.Online.API.Requests namespace osu.Game.Online.API.Requests
{ {
public class GetUserMessagesRequest : APIRequest<List<Message>> public class GetPrivateMessagesRequest : APIRequest<List<Message>>
{ {
private long? since; private long? since;
public GetUserMessagesRequest(long? sinceId = null) public GetPrivateMessagesRequest(long? sinceId = null)
{ {
since = sinceId; since = sinceId;
} }

View File

@ -34,7 +34,7 @@ namespace osu.Game.Online.Chat
} }
/// <summary> /// <summary>
/// Contructs a privatechannel /// Contructs a private channel
/// TODO this class needs to be serialized from something like channels/private, instead of creating from a contructor /// TODO this class needs to be serialized from something like channels/private, instead of creating from a contructor
/// </summary> /// </summary>
/// <param name="user">The user </param> /// <param name="user">The user </param>

View File

@ -50,8 +50,8 @@ namespace osu.Game.Online.Chat
private APIAccess api; private APIAccess api;
private readonly Scheduler scheduler; private readonly Scheduler scheduler;
private ScheduledDelegate fetchMessagesScheduleder; private ScheduledDelegate fetchMessagesScheduleder;
private GetChannelMessagesRequest fetchChannelMsgReq; private GetMessagesRequest fetchMsgReq;
private GetUserMessagesRequest fetchUserMsgReq; private GetPrivateMessagesRequest fetchPrivateMsgReq;
private long? lastChannelMsgId; private long? lastChannelMsgId;
private long? lastUserMsgId; private long? lastUserMsgId;
@ -151,26 +151,26 @@ namespace osu.Game.Online.Chat
private void fetchNewMessages() private void fetchNewMessages()
{ {
if (fetchChannelMsgReq == null) if (fetchMsgReq == null)
fetchNewChannelMessages(); fetchNewChannelMessages();
if (fetchUserMsgReq == null) if (fetchPrivateMsgReq == null)
fetchNewUserMessages(); fetchNewUserMessages();
} }
private void fetchNewUserMessages() private void fetchNewUserMessages()
{ {
fetchUserMsgReq = new GetUserMessagesRequest(lastUserMsgId); fetchPrivateMsgReq = new GetPrivateMessagesRequest(lastUserMsgId);
fetchUserMsgReq.Success += messages => fetchPrivateMsgReq.Success += messages =>
{ {
handleUserMessages(messages); handleUserMessages(messages);
lastUserMsgId = messages.LastOrDefault()?.Id ?? lastUserMsgId; lastUserMsgId = messages.LastOrDefault()?.Id ?? lastUserMsgId;
fetchUserMsgReq = null; fetchPrivateMsgReq = null;
}; };
fetchUserMsgReq.Failure += exception => Logger.Error(exception, "Fetching user messages failed."); fetchPrivateMsgReq.Failure += exception => Logger.Error(exception, "Fetching user messages failed.");
api.Queue(fetchUserMsgReq); api.Queue(fetchPrivateMsgReq);
} }
private void handleUserMessages(IEnumerable<Message> messages) private void handleUserMessages(IEnumerable<Message> messages)
@ -220,19 +220,19 @@ namespace osu.Game.Online.Chat
private void fetchNewChannelMessages() private void fetchNewChannelMessages()
{ {
fetchChannelMsgReq = new GetChannelMessagesRequest(JoinedChannels.Where(c => c.Target == TargetType.Channel), lastChannelMsgId); fetchMsgReq = new GetMessagesRequest(JoinedChannels.Where(c => c.Target == TargetType.Channel), lastChannelMsgId);
fetchChannelMsgReq.Success += messages => fetchMsgReq.Success += messages =>
{ {
if (messages == null) if (messages == null)
return; return;
handleChannelMessages(messages); handleChannelMessages(messages);
lastChannelMsgId = messages.LastOrDefault()?.Id ?? lastChannelMsgId; lastChannelMsgId = messages.LastOrDefault()?.Id ?? lastChannelMsgId;
fetchChannelMsgReq = null; fetchMsgReq = null;
}; };
fetchChannelMsgReq.Failure += exception => Logger.Error(exception, "Fetching channel messages failed."); fetchMsgReq.Failure += exception => Logger.Error(exception, "Fetching channel messages failed.");
api.Queue(fetchChannelMsgReq); api.Queue(fetchMsgReq);
} }
private void handleChannelMessages(IEnumerable<Message> messages) private void handleChannelMessages(IEnumerable<Message> messages)
@ -258,7 +258,7 @@ namespace osu.Game.Online.Chat
{ {
JoinedChannels.Add(channel); JoinedChannels.Add(channel);
var fetchInitialMsgReq = new GetChannelMessagesRequest(new[] { channel }, null); var fetchInitialMsgReq = new GetMessagesRequest(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);
@ -281,8 +281,8 @@ namespace osu.Game.Online.Chat
fetchMessagesScheduleder = scheduler.AddDelayed(fetchNewMessages, 1000, true); fetchMessagesScheduleder = scheduler.AddDelayed(fetchNewMessages, 1000, true);
break; break;
default: default:
fetchChannelMsgReq?.Cancel(); fetchMsgReq?.Cancel();
fetchChannelMsgReq = null; fetchMsgReq = null;
fetchMessagesScheduleder?.Cancel(); fetchMessagesScheduleder?.Cancel();
break; break;
} }

View File

@ -30,7 +30,7 @@ namespace osu.Game.Overlays
private const float textbox_height = 60; private const float textbox_height = 60;
private const float channel_selection_min_height = 0.3f; private const float channel_selection_min_height = 0.3f;
private ChannelManager chatManager; private ChannelManager channelManager;
private readonly Container<DrawableChat> currentChatContainer; private readonly Container<DrawableChat> currentChatContainer;
private readonly List<DrawableChat> loadedChannels = new List<DrawableChat>(); private readonly List<DrawableChat> loadedChannels = new List<DrawableChat>();
@ -157,7 +157,7 @@ namespace osu.Game.Overlays
chatTabControl = new ChatTabControl chatTabControl = new ChatTabControl
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
OnRequestLeave = channel => chatManager.JoinedChannels.Remove(channel) OnRequestLeave = channel => channelManager.JoinedChannels.Remove(channel)
} }
} }
}, },
@ -165,7 +165,7 @@ namespace osu.Game.Overlays
}, },
}; };
chatTabControl.Current.ValueChanged += chat => chatManager.CurrentChannel.Value = chat; chatTabControl.Current.ValueChanged += chat => channelManager.CurrentChannel.Value = chat;
chatTabControl.ChannelTabControl.ChannelSelectorActive.ValueChanged += value => channelSelection.State = value ? Visibility.Visible : Visibility.Hidden; chatTabControl.ChannelTabControl.ChannelSelectorActive.ValueChanged += value => channelSelection.State = value ? Visibility.Visible : Visibility.Hidden;
channelSelection.StateChanged += state => channelSelection.StateChanged += state =>
{ {
@ -182,10 +182,10 @@ namespace osu.Game.Overlays
}; };
channelSelection.OnRequestJoin = channel => channelSelection.OnRequestJoin = channel =>
{ {
if (!chatManager.JoinedChannels.Contains(channel)) if (!channelManager.JoinedChannels.Contains(channel))
chatManager.JoinedChannels.Add(channel); channelManager.JoinedChannels.Add(channel);
}; };
channelSelection.OnRequestLeave = channel => chatManager.JoinedChannels.Remove(channel); channelSelection.OnRequestLeave = channel => channelManager.JoinedChannels.Remove(channel);
} }
private void availableChannelsChanged(object sender, NotifyCollectionChangedEventArgs args) private void availableChannelsChanged(object sender, NotifyCollectionChangedEventArgs args)
@ -195,7 +195,7 @@ namespace osu.Game.Overlays
new ChannelSection new ChannelSection
{ {
Header = "All Channels", Header = "All Channels",
Channels = chatManager.AvailableChannels, Channels = channelManager.AvailableChannels,
}, },
}; };
} }
@ -328,10 +328,8 @@ namespace osu.Game.Overlays
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(APIAccess api, OsuConfigManager config, OsuColour colours, ChannelManager chatManager) private void load(OsuConfigManager config, OsuColour colours, ChannelManager channelManager)
{ {
api.Register(chatManager);
ChatHeight = config.GetBindable<double>(OsuSetting.ChatDisplayHeight); ChatHeight = config.GetBindable<double>(OsuSetting.ChatDisplayHeight);
ChatHeight.ValueChanged += h => ChatHeight.ValueChanged += h =>
{ {
@ -344,10 +342,10 @@ namespace osu.Game.Overlays
chatBackground.Colour = colours.ChatBlue; chatBackground.Colour = colours.ChatBlue;
loading.Show(); loading.Show();
this.chatManager = chatManager; this.channelManager = channelManager;
chatManager.CurrentChannel.ValueChanged += currentChatChanged; channelManager.CurrentChannel.ValueChanged += currentChatChanged;
chatManager.JoinedChannels.CollectionChanged += joinedChannelsChanged; channelManager.JoinedChannels.CollectionChanged += joinedChannelsChanged;
chatManager.AvailableChannels.CollectionChanged += availableChannelsChanged; channelManager.AvailableChannels.CollectionChanged += availableChannelsChanged;
} }
private void postMessage(TextBox textbox, bool newText) private void postMessage(TextBox textbox, bool newText)
@ -358,9 +356,9 @@ namespace osu.Game.Overlays
return; return;
if (text[0] == '/') if (text[0] == '/')
chatManager.PostCommand(text.Substring(1)); channelManager.PostCommand(text.Substring(1));
else else
chatManager.PostMessage(text); channelManager.PostMessage(text);
textbox.Text = string.Empty; textbox.Text = string.Empty;
} }