mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 15:44:04 +09:00
Remove populated property, and other changes
This commit is contained in:
@ -44,7 +44,7 @@ namespace osu.Game.Online.Chat
|
||||
/// <summary>
|
||||
/// An event that fires when new messages arrived.
|
||||
/// </summary>
|
||||
public event Action<IEnumerable<Message>, bool> NewMessagesArrived;
|
||||
public event Action<IEnumerable<Message>> NewMessagesArrived;
|
||||
|
||||
/// <summary>
|
||||
/// An event that fires when a pending message gets resolved.
|
||||
@ -58,11 +58,6 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
public bool ReadOnly => false; //todo not yet used.
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the channel's previous messages have been loaded.
|
||||
/// </summary>
|
||||
public bool Populated { get; set; } = false;
|
||||
|
||||
public override string ToString() => Name;
|
||||
|
||||
[JsonProperty(@"name")]
|
||||
@ -110,7 +105,7 @@ namespace osu.Game.Online.Chat
|
||||
pendingMessages.Add(message);
|
||||
Messages.Add(message);
|
||||
|
||||
NewMessagesArrived?.Invoke(new[] { message }, Populated);
|
||||
NewMessagesArrived?.Invoke(new[] { message });
|
||||
}
|
||||
|
||||
public bool MessagesLoaded;
|
||||
@ -133,11 +128,8 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
purgeOldMessages();
|
||||
|
||||
NewMessagesArrived?.Invoke(messages, Populated);
|
||||
NewMessagesArrived?.Invoke(messages);
|
||||
}
|
||||
|
||||
if (!Populated)
|
||||
Populated = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -51,7 +51,6 @@ namespace osu.Game.Online.Chat
|
||||
localUser = api.LocalUser;
|
||||
|
||||
// Listen for new messages
|
||||
|
||||
channelManager.JoinedChannels.ItemsAdded += (joinedChannels) =>
|
||||
{
|
||||
foreach (var channel in joinedChannels)
|
||||
@ -65,14 +64,11 @@ namespace osu.Game.Online.Chat
|
||||
};
|
||||
}
|
||||
|
||||
private void channel_NewMessagesArrived(IEnumerable<Message> messages, bool populated)
|
||||
private void channel_NewMessagesArrived(IEnumerable<Message> messages)
|
||||
{
|
||||
if (messages == null || !messages.Any())
|
||||
return;
|
||||
|
||||
if (!populated)
|
||||
return;
|
||||
|
||||
HandleMessages(messages.First().ChannelId, messages);
|
||||
}
|
||||
|
||||
@ -94,7 +90,7 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
public void HandleMessages(Channel channel, IEnumerable<Message> messages)
|
||||
{
|
||||
// don't show if visible or not visible
|
||||
// don't show if the ChatOverlay and the channel is visible.
|
||||
if (IsActive && channelManager.CurrentChannel.Value == channel)
|
||||
return;
|
||||
|
||||
@ -108,26 +104,36 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
void onClick()
|
||||
{
|
||||
chatOverlay.ScrollToAndHighlightMessage(channel, message);
|
||||
notificationOverlay.Hide();
|
||||
chatOverlay.Show();
|
||||
channelManager.CurrentChannel.Value = channel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (notifyOnChat.Value && channel.Type == ChannelType.PM)
|
||||
{
|
||||
var existingNotification = notificationOverlay.Notifications.OfType<PrivateMessageNotification>().FirstOrDefault(n => n.Username == message.Sender.Username);
|
||||
// Scheduling because of possible "race-condition" (NotificationOverlay didn't add the notification yet).
|
||||
Schedule(() =>
|
||||
{
|
||||
var existingNotification = notificationOverlay.Notifications.OfType<PrivateMessageNotification>()
|
||||
.FirstOrDefault(n => n.Username == message.Sender.Username);
|
||||
|
||||
if (existingNotification == null)
|
||||
{
|
||||
var notification = new PrivateMessageNotification(message.Sender.Username, onClick);
|
||||
notificationOverlay?.Post(notification);
|
||||
}
|
||||
else
|
||||
{
|
||||
existingNotification.MessageCount++;
|
||||
}
|
||||
if (existingNotification == null)
|
||||
{
|
||||
var notification = new PrivateMessageNotification(message.Sender.Username, onClick);
|
||||
notificationOverlay?.Post(notification);
|
||||
}
|
||||
else
|
||||
{
|
||||
existingNotification.MessageCount++;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (notifyOnMention.Value && anyCaseInsensitive(words, localUsername))
|
||||
{
|
||||
var notification = new MentionNotification(message.Sender.Username, onClick);
|
||||
@ -135,6 +141,7 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(highlightWords.Value))
|
||||
{
|
||||
var matchedWord = hasCaseInsensitive(words, getWords(highlightWords.Value));
|
||||
@ -146,6 +153,40 @@ namespace osu.Game.Online.Chat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//making sure if the notification drawer bugs out, we merge it afterwards again.
|
||||
Schedule(() => mergeNotifications());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks current notifications if they aren't merged, and merges them together again.
|
||||
/// </summary>
|
||||
private void mergeNotifications()
|
||||
{
|
||||
if (notificationOverlay == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var pmn = notificationOverlay.Notifications.OfType<PrivateMessageNotification>();
|
||||
|
||||
foreach (var notification in pmn)
|
||||
{
|
||||
var duplicates = pmn.Where(n => n.Username == notification.Username);
|
||||
|
||||
if (duplicates.Count() < 2)
|
||||
continue;
|
||||
|
||||
var first = duplicates.First();
|
||||
foreach (var notification2 in duplicates)
|
||||
{
|
||||
if (notification2 == first)
|
||||
continue;
|
||||
|
||||
first.MessageCount += notification2.MessageCount;
|
||||
notification2.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string[] getWords(string input) => input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
@ -171,14 +212,12 @@ namespace osu.Game.Online.Chat
|
||||
public override bool IsImportant => false;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, NotificationOverlay notificationOverlay)
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
IconBackgound.Colour = colours.PurpleDark;
|
||||
Activated = delegate
|
||||
{
|
||||
notificationOverlay.Hide();
|
||||
onClick?.Invoke();
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
@ -202,6 +241,7 @@ namespace osu.Game.Online.Chat
|
||||
set
|
||||
{
|
||||
messageCount = value;
|
||||
|
||||
if (messageCount > 1)
|
||||
{
|
||||
Text = $"You received {messageCount} private messages from '{Username}'. Click to read it!";
|
||||
@ -220,15 +260,12 @@ namespace osu.Game.Online.Chat
|
||||
public override bool IsImportant => false;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, NotificationOverlay notificationOverlay, ChatOverlay chatOverlay)
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
IconBackgound.Colour = colours.PurpleDark;
|
||||
Activated = delegate
|
||||
{
|
||||
notificationOverlay.Hide();
|
||||
chatOverlay.Show();
|
||||
onClick?.Invoke();
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
@ -248,15 +285,12 @@ namespace osu.Game.Online.Chat
|
||||
public override bool IsImportant => false;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, NotificationOverlay notificationOverlay, ChatOverlay chatOverlay)
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
IconBackgound.Colour = colours.PurpleDark;
|
||||
Activated = delegate
|
||||
{
|
||||
notificationOverlay.Hide();
|
||||
chatOverlay.Show();
|
||||
onClick?.Invoke();
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user