Use separate method for fetching channel objects

Resolves a pull request review
This commit is contained in:
Craftplacer 2021-06-05 14:02:48 +02:00
parent 39c3b08fc7
commit ce4bcda803
No known key found for this signature in database
GPG Key ID: 0D94BDA3F64B90CE
1 changed files with 10 additions and 6 deletions

View File

@ -76,9 +76,18 @@ private void newMessagesArrived(IEnumerable<Message> messages)
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)
{
var channel = channelManager.JoinedChannels.SingleOrDefault(c => c.Id == channelId);
// Fetch channel object
var channel = fetchJoinedChannel(channelId);
if (channel == null)
{
@ -86,11 +95,6 @@ public void HandleMessages(long channelId, IEnumerable<Message> messages)
return;
}
HandleMessages(channel, messages);
}
public void HandleMessages(Channel channel, IEnumerable<Message> messages)
{
// Only send notifications, if ChatOverlay and the target channel aren't visible.
if (chatOverlay?.IsPresent == true && channelManager.CurrentChannel.Value == channel)
return;