Inline and refactor overly verbose `MessageNotifier` code

This commit is contained in:
Dean Herbert 2021-06-11 16:27:31 +09:00
parent 16e3a19738
commit 139401a04a
1 changed files with 4 additions and 19 deletions

View File

@ -45,8 +45,7 @@ private void load(OsuConfigManager config, IAPIProvider api)
notifyOnPM = config.GetBindable<bool>(OsuSetting.ChatMessageNotification);
localUser.BindTo(api.LocalUser);
// Listen for new messages
joinedChannels.CollectionChanged += channelsChanged;
joinedChannels.BindCollectionChanged(channelsChanged);
joinedChannels.BindTo(channelManager.JoinedChannels);
}
@ -70,28 +69,14 @@ private void channelsChanged(object sender, NotifyCollectionChangedEventArgs e)
private void newMessagesArrived(IEnumerable<Message> messages)
{
if (messages == null || !messages.Any())
if (!messages.Any())
return;
HandleMessages(messages.First().ChannelId, messages);
}
/// <summary>
/// Searches for a channel with the matching <paramref name="channelId"/>, returns <see langword="null"/> when none found.
/// </summary>
private Channel fetchJoinedChannel(long channelId)
{
return channelManager.JoinedChannels.SingleOrDefault(c => c.Id == channelId);
}
public void HandleMessages(long channelId, IEnumerable<Message> messages)
{
// Fetch channel object
var channel = fetchJoinedChannel(channelId);
var channel = channelManager.JoinedChannels.SingleOrDefault(c => c.Id == messages.First().ChannelId);
if (channel == null)
{
Logger.Log($"Couldn't resolve channel id {channelId}", LoggingTarget.Information);
Logger.Log($"Couldn't resolve channel id {messages.First().ChannelId}", LoggingTarget.Information);
return;
}