1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 17:57:38 +08:00

No notification "debouncing"

This commit is contained in:
Craftplacer 2020-01-22 10:48:55 +01:00
parent e4accb3344
commit 771155e882

View File

@ -38,8 +38,6 @@ namespace osu.Game.Online.Chat
private Bindable<bool> notifyOnChat; private Bindable<bool> notifyOnChat;
private Bindable<User> localUser; private Bindable<User> localUser;
private readonly List<PrivateMessageNotification> privateMessageNotifications = new List<PrivateMessageNotification>();
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuConfigManager config, IAPIProvider api) private void load(OsuConfigManager config, IAPIProvider api)
{ {
@ -114,19 +112,9 @@ namespace osu.Game.Online.Chat
if (!notifyOnChat.Value || channel.Type != ChannelType.PM) if (!notifyOnChat.Value || channel.Type != ChannelType.PM)
return false; return false;
var existingNotification = privateMessageNotifications.FirstOrDefault(n => n.Username == message.Sender.Username); var notification = new PrivateMessageNotification(message.Sender.Username, channel);
if (existingNotification == null) notificationOverlay?.Post(notification);
{
var notification = new PrivateMessageNotification(message.Sender.Username, channel, n => privateMessageNotifications.Remove(n));
notificationOverlay?.Post(notification);
privateMessageNotifications.Add(notification);
}
else
{
existingNotification.MessageCount++;
}
return true; return true;
} }
@ -151,25 +139,12 @@ namespace osu.Game.Online.Chat
public class PrivateMessageNotification : SimpleNotification public class PrivateMessageNotification : SimpleNotification
{ {
public PrivateMessageNotification(string username, Channel channel, Action<PrivateMessageNotification> onRemove) public PrivateMessageNotification(string username, Channel channel)
{ {
Icon = FontAwesome.Solid.Envelope; Icon = FontAwesome.Solid.Envelope;
Username = username; Username = username;
MessageCount = 1;
Channel = channel; Channel = channel;
OnRemove = onRemove; Text = $"You received a private message from '{Username}'. Click to read it!";
}
private int messageCount;
public int MessageCount
{
get => messageCount;
set
{
messageCount = value;
Text = $"You received {"private message".ToQuantity(messageCount)} from '{Username}'. Click to read it!";
}
} }
public string Username { get; set; } public string Username { get; set; }
@ -193,11 +168,6 @@ namespace osu.Game.Online.Chat
return true; return true;
}; };
Closed += delegate
{
OnRemove.Invoke(this);
};
} }
} }