1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 21:07:33 +08:00

Split HandleMessages method

This commit is contained in:
Craftplacer 2020-01-19 17:55:17 +01:00
parent 86ecaf223d
commit 4feae82434

View File

@ -103,27 +103,30 @@ namespace osu.Game.Online.Chat
if (message.Id < channel.LastReadId)
return;
// ignore messages from yourself
var localUsername = localUser.Value.Username;
if (message.Sender.Username == localUsername)
continue;
var words = getWords(message.Content);
if (checkForPMs(channel, message))
continue;
void onClick()
{
notificationOverlay.Hide();
chatOverlay.Show();
channelManager.CurrentChannel.Value = channel;
// change output to bool again if another "message processor" is added.
checkForMentions(channel, message, localUsername);
}
}
if (notifyOnChat.Value && channel.Type == ChannelType.PM)
private bool checkForPMs(Channel channel, Message message)
{
if (!notifyOnChat.Value || channel.Type != ChannelType.PM)
return false;
var existingNotification = privateMessageNotifications.FirstOrDefault(n => n.Username == message.Sender.Username);
if (existingNotification == null)
{
var notification = new PrivateMessageNotification(message.Sender.Username, onClick);
var notification = new PrivateMessageNotification(message.Sender.Username, channel);
notificationOverlay?.Post(notification);
privateMessageNotifications.Add(notification);
}
@ -132,17 +135,18 @@ namespace osu.Game.Online.Chat
existingNotification.MessageCount++;
}
continue;
return true;
}
if (notifyOnMention.Value && anyCaseInsensitive(words, localUsername))
private void checkForMentions(Channel channel, Message message, string username)
{
var notification = new MentionNotification(message.Sender.Username, onClick);
notificationOverlay?.Post(notification);
var words = getWords(message.Content);
continue;
}
}
if (!notifyOnMention.Value || !anyCaseInsensitive(words, username))
return;
var notification = new MentionNotification(message.Sender.Username, channel);
notificationOverlay?.Post(notification);
}
private static IEnumerable<string> getWords(string input) => Regex.Matches(input, @"\w+").Select(c => c.Value);
@ -158,12 +162,12 @@ namespace osu.Game.Online.Chat
public class PrivateMessageNotification : SimpleNotification
{
public PrivateMessageNotification(string username, Action onClick)
public PrivateMessageNotification(string username, Channel channel)
{
Icon = FontAwesome.Solid.Envelope;
Username = username;
MessageCount = 1;
this.onClick = onClick;
Channel = channel;
}
private int messageCount;
@ -176,17 +180,19 @@ namespace osu.Game.Online.Chat
public string Username { get; set; }
private readonly Action onClick;
public Channel Channel { get; set; }
public override bool IsImportant => false;
[BackgroundDependencyLoader]
private void load(OsuColour colours, MessageNotifier notifier)
private void load(OsuColour colours, ChatOverlay chatOverlay, NotificationOverlay notificationOverlay, ChannelManager channelManager, MessageNotifier notifier)
{
IconBackgound.Colour = colours.PurpleDark;
Activated = delegate
{
onClick?.Invoke();
notificationOverlay.Hide();
chatOverlay.Show();
channelManager.CurrentChannel.Value = Channel;
if (notifier.privateMessageNotifications.Contains(this))
notifier.privateMessageNotifications.Remove(this);
@ -198,24 +204,27 @@ namespace osu.Game.Online.Chat
public class MentionNotification : SimpleNotification
{
public MentionNotification(string username, Action onClick)
public MentionNotification(string username, Channel channel)
{
Icon = FontAwesome.Solid.At;
Text = $"Your name was mentioned in chat by '{username}'. Click to find out why!";
this.onClick = onClick;
Channel = channel;
}
private readonly Action onClick;
public Channel Channel { get; set; }
public override bool IsImportant => false;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
private void load(OsuColour colours, ChatOverlay chatOverlay, NotificationOverlay notificationOverlay, ChannelManager channelManager)
{
IconBackgound.Colour = colours.PurpleDark;
Activated = delegate
{
onClick?.Invoke();
notificationOverlay.Hide();
chatOverlay.Show();
channelManager.CurrentChannel.Value = Channel;
return true;
};
}