mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 21:32:57 +08:00
Use instance list instead of exposing NotifcationOverlay's notifications
This commit is contained in:
parent
2b5d541857
commit
5d244f48f7
@ -42,6 +42,8 @@ namespace osu.Game.Online.Chat
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsActive => chatOverlay?.IsPresent == true;
|
public bool IsActive => chatOverlay?.IsPresent == true;
|
||||||
|
|
||||||
|
private List<PrivateMessageNotification> privateMessageNotifications = new List<PrivateMessageNotification>();
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuConfigManager config, IAPIProvider api)
|
private void load(OsuConfigManager config, IAPIProvider api)
|
||||||
{
|
{
|
||||||
@ -96,12 +98,17 @@ namespace osu.Game.Online.Chat
|
|||||||
|
|
||||||
foreach (var message in messages)
|
foreach (var message in messages)
|
||||||
{
|
{
|
||||||
var words = getWords(message.Content);
|
// ignore messages that already have been read
|
||||||
|
if (message.Id < channel.LastReadId)
|
||||||
|
return;
|
||||||
|
|
||||||
var localUsername = localUser.Value.Username;
|
var localUsername = localUser.Value.Username;
|
||||||
|
|
||||||
if (message.Sender.Username == localUsername)
|
if (message.Sender.Username == localUsername)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
var words = getWords(message.Content);
|
||||||
|
|
||||||
void onClick()
|
void onClick()
|
||||||
{
|
{
|
||||||
notificationOverlay.Hide();
|
notificationOverlay.Hide();
|
||||||
@ -109,20 +116,19 @@ namespace osu.Game.Online.Chat
|
|||||||
channelManager.CurrentChannel.Value = channel;
|
channelManager.CurrentChannel.Value = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (notifyOnChat.Value && channel.Type == ChannelType.PM)
|
if (notifyOnChat.Value && channel.Type == ChannelType.PM)
|
||||||
{
|
{
|
||||||
// Scheduling because of possible "race-condition" (NotificationOverlay didn't add the notification yet).
|
// Scheduling because of possible "race-condition" (NotificationOverlay didn't add the notification yet).
|
||||||
Schedule(() =>
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
var existingNotification = notificationOverlay.Notifications.OfType<PrivateMessageNotification>()
|
var existingNotification = privateMessageNotifications.OfType<PrivateMessageNotification>()
|
||||||
.FirstOrDefault(n => n.Username == message.Sender.Username);
|
.FirstOrDefault(n => n.Username == message.Sender.Username);
|
||||||
|
|
||||||
if (existingNotification == null)
|
if (existingNotification == null)
|
||||||
{
|
{
|
||||||
var notification = new PrivateMessageNotification(message.Sender.Username, onClick);
|
var notification = new PrivateMessageNotification(message.Sender.Username, onClick);
|
||||||
notificationOverlay?.Post(notification);
|
notificationOverlay?.Post(notification);
|
||||||
|
privateMessageNotifications.Add(notification);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -130,7 +136,6 @@ namespace osu.Game.Online.Chat
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,9 +201,9 @@ namespace osu.Game.Online.Chat
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static string hasCaseInsensitive(IEnumerable<string> x, IEnumerable<string> y) => x.FirstOrDefault(x2 => anyCaseInsensitive(y, x2));
|
private static string hasCaseInsensitive(IEnumerable<string> x, IEnumerable<string> y) => x.FirstOrDefault(x2 => anyCaseInsensitive(y, x2));
|
||||||
|
|
||||||
private static bool anyCaseInsensitive(IEnumerable<string> x, string y) => x.Any(x2 => x2.Equals(y, StringComparison.InvariantCultureIgnoreCase));
|
private static bool anyCaseInsensitive(IEnumerable<string> x, string y) => x.Any(x2 => x2.Equals(y, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
private class HighlightNotification : SimpleNotification
|
public class HighlightNotification : SimpleNotification
|
||||||
{
|
{
|
||||||
public HighlightNotification(string highlighter, string word, Action onClick)
|
public HighlightNotification(string highlighter, string word, Action onClick)
|
||||||
{
|
{
|
||||||
@ -223,7 +228,7 @@ namespace osu.Game.Online.Chat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PrivateMessageNotification : SimpleNotification
|
public class PrivateMessageNotification : SimpleNotification
|
||||||
{
|
{
|
||||||
public PrivateMessageNotification(string username, Action onClick)
|
public PrivateMessageNotification(string username, Action onClick)
|
||||||
{
|
{
|
||||||
@ -260,18 +265,22 @@ namespace osu.Game.Online.Chat
|
|||||||
public override bool IsImportant => false;
|
public override bool IsImportant => false;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours, MessageNotifier notifier)
|
||||||
{
|
{
|
||||||
IconBackgound.Colour = colours.PurpleDark;
|
IconBackgound.Colour = colours.PurpleDark;
|
||||||
Activated = delegate
|
Activated = delegate
|
||||||
{
|
{
|
||||||
onClick?.Invoke();
|
onClick?.Invoke();
|
||||||
|
|
||||||
|
if (notifier.privateMessageNotifications.Contains(this))
|
||||||
|
notifier.privateMessageNotifications.Remove(this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MentionNotification : SimpleNotification
|
public class MentionNotification : SimpleNotification
|
||||||
{
|
{
|
||||||
public MentionNotification(string username, Action onClick)
|
public MentionNotification(string username, Action onClick)
|
||||||
{
|
{
|
||||||
|
@ -23,8 +23,6 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
public const float TRANSITION_LENGTH = 600;
|
public const float TRANSITION_LENGTH = 600;
|
||||||
|
|
||||||
public IEnumerable<Notification> Notifications => sections.Children.SelectMany(s => s.Notifications);
|
|
||||||
|
|
||||||
private FlowContainer<NotificationSection> sections;
|
private FlowContainer<NotificationSection> sections;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -21,8 +21,6 @@ namespace osu.Game.Overlays.Notifications
|
|||||||
|
|
||||||
private FlowContainer<Notification> notifications;
|
private FlowContainer<Notification> notifications;
|
||||||
|
|
||||||
public IEnumerable<Notification> Notifications => notifications.Children;
|
|
||||||
|
|
||||||
public int DisplayedCount => notifications.Count(n => !n.WasClosed);
|
public int DisplayedCount => notifications.Count(n => !n.WasClosed);
|
||||||
public int UnreadCount => notifications.Count(n => !n.WasClosed && !n.Read);
|
public int UnreadCount => notifications.Count(n => !n.WasClosed && !n.Read);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user