Reduce duplicate notification code by making a base class

This commit is contained in:
Craftplacer 2021-05-27 01:00:26 +02:00
parent cf39e58ce7
commit a679efac1c
No known key found for this signature in database
GPG Key ID: 0D94BDA3F64B90CE
1 changed files with 13 additions and 26 deletions

View File

@ -142,12 +142,10 @@ private void checkForMentions(Channel channel, Message message, string username)
/// <returns>If the <paramref name="message"/> mentions the <paramref name="username"/></returns>
private static bool isMentioning(string message, string username) => message.IndexOf(username, StringComparison.OrdinalIgnoreCase) != -1 || message.IndexOf(username.Replace(' ', '_'), StringComparison.OrdinalIgnoreCase) != -1;
public class PrivateMessageNotification : SimpleNotification
public class OpenChannelNotification : SimpleNotification
{
public PrivateMessageNotification(string username, Channel channel)
public OpenChannelNotification(Channel channel)
{
Icon = FontAwesome.Solid.Envelope;
Text = $"You received a private message from '{username}'. Click to read it!";
this.channel = channel;
}
@ -171,32 +169,21 @@ private void load(OsuColour colours, ChatOverlay chatOverlay, NotificationOverla
}
}
public class MentionNotification : SimpleNotification
public class PrivateMessageNotification : OpenChannelNotification
{
public MentionNotification(string username, Channel channel)
public PrivateMessageNotification(string username, Channel channel) : base(channel)
{
Icon = FontAwesome.Solid.Envelope;
Text = $"You received a private message from '{username}'. Click to read it!";
}
}
public class MentionNotification : OpenChannelNotification
{
public MentionNotification(string username, Channel channel) : base(channel)
{
Icon = FontAwesome.Solid.At;
Text = $"Your name was mentioned in chat by '{username}'. Click to find out why!";
this.channel = channel;
}
private readonly Channel channel;
public override bool IsImportant => false;
[BackgroundDependencyLoader]
private void load(OsuColour colours, ChatOverlay chatOverlay, NotificationOverlay notificationOverlay, ChannelManager channelManager)
{
IconBackgound.Colour = colours.PurpleDark;
Activated = delegate
{
notificationOverlay.Hide();
chatOverlay.Show();
channelManager.CurrentChannel.Value = channel;
return true;
};
}
}
}