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