mirror of
https://github.com/ppy/osu.git
synced 2025-02-01 21:15:07 +08:00
Remove populated property, and other changes
This commit is contained in:
parent
0d812bce9f
commit
1b53c0ff74
@ -44,7 +44,7 @@ namespace osu.Game.Online.Chat
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An event that fires when new messages arrived.
|
/// An event that fires when new messages arrived.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action<IEnumerable<Message>, bool> NewMessagesArrived;
|
public event Action<IEnumerable<Message>> NewMessagesArrived;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An event that fires when a pending message gets resolved.
|
/// 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.
|
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;
|
public override string ToString() => Name;
|
||||||
|
|
||||||
[JsonProperty(@"name")]
|
[JsonProperty(@"name")]
|
||||||
@ -110,7 +105,7 @@ namespace osu.Game.Online.Chat
|
|||||||
pendingMessages.Add(message);
|
pendingMessages.Add(message);
|
||||||
Messages.Add(message);
|
Messages.Add(message);
|
||||||
|
|
||||||
NewMessagesArrived?.Invoke(new[] { message }, Populated);
|
NewMessagesArrived?.Invoke(new[] { message });
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MessagesLoaded;
|
public bool MessagesLoaded;
|
||||||
@ -133,11 +128,8 @@ namespace osu.Game.Online.Chat
|
|||||||
|
|
||||||
purgeOldMessages();
|
purgeOldMessages();
|
||||||
|
|
||||||
NewMessagesArrived?.Invoke(messages, Populated);
|
NewMessagesArrived?.Invoke(messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Populated)
|
|
||||||
Populated = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -51,7 +51,6 @@ namespace osu.Game.Online.Chat
|
|||||||
localUser = api.LocalUser;
|
localUser = api.LocalUser;
|
||||||
|
|
||||||
// Listen for new messages
|
// Listen for new messages
|
||||||
|
|
||||||
channelManager.JoinedChannels.ItemsAdded += (joinedChannels) =>
|
channelManager.JoinedChannels.ItemsAdded += (joinedChannels) =>
|
||||||
{
|
{
|
||||||
foreach (var channel in 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())
|
if (messages == null || !messages.Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!populated)
|
|
||||||
return;
|
|
||||||
|
|
||||||
HandleMessages(messages.First().ChannelId, messages);
|
HandleMessages(messages.First().ChannelId, messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +90,7 @@ namespace osu.Game.Online.Chat
|
|||||||
|
|
||||||
public void HandleMessages(Channel channel, IEnumerable<Message> messages)
|
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)
|
if (IsActive && channelManager.CurrentChannel.Value == channel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -108,13 +104,20 @@ namespace osu.Game.Online.Chat
|
|||||||
|
|
||||||
void onClick()
|
void onClick()
|
||||||
{
|
{
|
||||||
chatOverlay.ScrollToAndHighlightMessage(channel, message);
|
notificationOverlay.Hide();
|
||||||
chatOverlay.Show();
|
chatOverlay.Show();
|
||||||
|
channelManager.CurrentChannel.Value = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (notifyOnChat.Value && channel.Type == ChannelType.PM)
|
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)
|
if (existingNotification == null)
|
||||||
{
|
{
|
||||||
@ -125,9 +128,12 @@ namespace osu.Game.Online.Chat
|
|||||||
{
|
{
|
||||||
existingNotification.MessageCount++;
|
existingNotification.MessageCount++;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notifyOnMention.Value && anyCaseInsensitive(words, localUsername))
|
if (notifyOnMention.Value && anyCaseInsensitive(words, localUsername))
|
||||||
{
|
{
|
||||||
var notification = new MentionNotification(message.Sender.Username, onClick);
|
var notification = new MentionNotification(message.Sender.Username, onClick);
|
||||||
@ -135,6 +141,7 @@ namespace osu.Game.Online.Chat
|
|||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(highlightWords.Value))
|
if (!string.IsNullOrWhiteSpace(highlightWords.Value))
|
||||||
{
|
{
|
||||||
var matchedWord = hasCaseInsensitive(words, getWords(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);
|
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;
|
public override bool IsImportant => false;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours, NotificationOverlay notificationOverlay)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
IconBackgound.Colour = colours.PurpleDark;
|
IconBackgound.Colour = colours.PurpleDark;
|
||||||
Activated = delegate
|
Activated = delegate
|
||||||
{
|
{
|
||||||
notificationOverlay.Hide();
|
|
||||||
onClick?.Invoke();
|
onClick?.Invoke();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -202,6 +241,7 @@ namespace osu.Game.Online.Chat
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
messageCount = value;
|
messageCount = value;
|
||||||
|
|
||||||
if (messageCount > 1)
|
if (messageCount > 1)
|
||||||
{
|
{
|
||||||
Text = $"You received {messageCount} private messages from '{Username}'. Click to read it!";
|
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;
|
public override bool IsImportant => false;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours, NotificationOverlay notificationOverlay, ChatOverlay chatOverlay)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
IconBackgound.Colour = colours.PurpleDark;
|
IconBackgound.Colour = colours.PurpleDark;
|
||||||
Activated = delegate
|
Activated = delegate
|
||||||
{
|
{
|
||||||
notificationOverlay.Hide();
|
|
||||||
chatOverlay.Show();
|
|
||||||
onClick?.Invoke();
|
onClick?.Invoke();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -248,15 +285,12 @@ namespace osu.Game.Online.Chat
|
|||||||
public override bool IsImportant => false;
|
public override bool IsImportant => false;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours, NotificationOverlay notificationOverlay, ChatOverlay chatOverlay)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
IconBackgound.Colour = colours.PurpleDark;
|
IconBackgound.Colour = colours.PurpleDark;
|
||||||
Activated = delegate
|
Activated = delegate
|
||||||
{
|
{
|
||||||
notificationOverlay.Hide();
|
|
||||||
chatOverlay.Show();
|
|
||||||
onClick?.Invoke();
|
onClick?.Invoke();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -8,17 +8,12 @@ using System.Linq;
|
|||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Cursor;
|
using osu.Game.Graphics.Cursor;
|
||||||
using osu.Game.Online.Chat;
|
using osu.Game.Online.Chat;
|
||||||
using osu.Game.Overlays.Notifications;
|
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Online.API;
|
|
||||||
using osu.Game.Configuration;
|
|
||||||
using osu.Game.Users;
|
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Colour;
|
using osu.Framework.Graphics.Colour;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
@ -67,7 +62,7 @@ namespace osu.Game.Overlays.Chat
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
newMessagesArrived(Channel.Messages, Channel.Populated);
|
newMessagesArrived(Channel.Messages);
|
||||||
|
|
||||||
Channel.NewMessagesArrived += newMessagesArrived;
|
Channel.NewMessagesArrived += newMessagesArrived;
|
||||||
Channel.MessageRemoved += messageRemoved;
|
Channel.MessageRemoved += messageRemoved;
|
||||||
@ -97,7 +92,7 @@ namespace osu.Game.Overlays.Chat
|
|||||||
Colour = colours.ChatBlue.Lighten(0.7f),
|
Colour = colours.ChatBlue.Lighten(0.7f),
|
||||||
};
|
};
|
||||||
|
|
||||||
private void newMessagesArrived(IEnumerable<Message> newMessages, bool populated)
|
private void newMessagesArrived(IEnumerable<Message> newMessages)
|
||||||
{
|
{
|
||||||
bool shouldScrollToEnd = scroll.IsScrolledToEnd(10) || !chatLines.Any() || newMessages.Any(m => m is LocalMessage);
|
bool shouldScrollToEnd = scroll.IsScrolledToEnd(10) || !chatLines.Any() || newMessages.Any(m => m is LocalMessage);
|
||||||
|
|
||||||
@ -157,16 +152,6 @@ namespace osu.Game.Overlays.Chat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ScrollToAndHighlightMessage(Message message)
|
|
||||||
{
|
|
||||||
if (message is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var chatLine = findChatLine(message);
|
|
||||||
scroll.ScrollTo(chatLine);
|
|
||||||
chatLine.FlashColour(HighlightColour, 7500, Easing.InExpo);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void messageRemoved(Message removed)
|
private void messageRemoved(Message removed)
|
||||||
{
|
{
|
||||||
findChatLine(removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire();
|
findChatLine(removed)?.FadeColour(Color4.Red, 400).FadeOut(600).Expire();
|
||||||
|
@ -22,7 +22,6 @@ using osu.Game.Overlays.Chat.Selection;
|
|||||||
using osu.Game.Overlays.Chat.Tabs;
|
using osu.Game.Overlays.Chat.Tabs;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
@ -61,8 +60,6 @@ namespace osu.Game.Overlays
|
|||||||
private Container channelSelectionContainer;
|
private Container channelSelectionContainer;
|
||||||
protected ChannelSelectionOverlay ChannelSelectionOverlay;
|
protected ChannelSelectionOverlay ChannelSelectionOverlay;
|
||||||
|
|
||||||
private Message highlightingMessage { get; set; }
|
|
||||||
|
|
||||||
public override bool Contains(Vector2 screenSpacePos) => chatContainer.ReceivePositionalInputAt(screenSpacePos)
|
public override bool Contains(Vector2 screenSpacePos) => chatContainer.ReceivePositionalInputAt(screenSpacePos)
|
||||||
|| (ChannelSelectionOverlay.State.Value == Visibility.Visible && ChannelSelectionOverlay.ReceivePositionalInputAt(screenSpacePos));
|
|| (ChannelSelectionOverlay.State.Value == Visibility.Visible && ChannelSelectionOverlay.ReceivePositionalInputAt(screenSpacePos));
|
||||||
|
|
||||||
@ -255,14 +252,16 @@ namespace osu.Game.Overlays
|
|||||||
if (ChannelTabControl.Current.Value != e.NewValue)
|
if (ChannelTabControl.Current.Value != e.NewValue)
|
||||||
Scheduler.Add(() => ChannelTabControl.Current.Value = e.NewValue);
|
Scheduler.Add(() => ChannelTabControl.Current.Value = e.NewValue);
|
||||||
|
|
||||||
var loaded = GetChannelDrawable(e.NewValue);
|
var loaded = loadedChannels.Find(drawable => drawable.Channel == e.NewValue);
|
||||||
|
|
||||||
if (loaded == null)
|
if (loaded == null)
|
||||||
{
|
{
|
||||||
currentChannelContainer.FadeOut(500, Easing.OutQuint);
|
currentChannelContainer.FadeOut(500, Easing.OutQuint);
|
||||||
loading.Show();
|
loading.Show();
|
||||||
|
|
||||||
loaded = loadChannelDrawable(e.NewValue);
|
loaded = new DrawableChannel(e.NewValue);
|
||||||
|
loadedChannels.Add(loaded);
|
||||||
|
|
||||||
LoadComponentAsync(loaded, l =>
|
LoadComponentAsync(loaded, l =>
|
||||||
{
|
{
|
||||||
if (currentChannel.Value != e.NewValue)
|
if (currentChannel.Value != e.NewValue)
|
||||||
@ -273,12 +272,6 @@ namespace osu.Game.Overlays
|
|||||||
currentChannelContainer.Clear(false);
|
currentChannelContainer.Clear(false);
|
||||||
currentChannelContainer.Add(loaded);
|
currentChannelContainer.Add(loaded);
|
||||||
currentChannelContainer.FadeIn(500, Easing.OutQuint);
|
currentChannelContainer.FadeIn(500, Easing.OutQuint);
|
||||||
|
|
||||||
if (highlightingMessage != null && highlightingMessage.ChannelId == e.NewValue.Id)
|
|
||||||
{
|
|
||||||
loaded.ScrollToAndHighlightMessage(highlightingMessage);
|
|
||||||
highlightingMessage = null;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -446,34 +439,6 @@ namespace osu.Game.Overlays
|
|||||||
textbox.Text = string.Empty;
|
textbox.Text = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns the loaded drawable for a channel. Creates new instance if <paramref name="createIfUnloaded"/> is true. Otherwise returns null if not found.
|
|
||||||
/// </summary>
|
|
||||||
public DrawableChannel GetChannelDrawable(Channel channel, bool createIfUnloaded = false)
|
|
||||||
{
|
|
||||||
var result = loadedChannels.Find(drawable => drawable.Channel == channel);
|
|
||||||
|
|
||||||
if (createIfUnloaded && result == null)
|
|
||||||
{
|
|
||||||
result = loadChannelDrawable(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private DrawableChannel loadChannelDrawable(Channel channel)
|
|
||||||
{
|
|
||||||
var loaded = new DrawableChannel(channel);
|
|
||||||
loadedChannels.Add(loaded);
|
|
||||||
return loaded;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ScrollToAndHighlightMessage(Channel channel, Message message)
|
|
||||||
{
|
|
||||||
highlightingMessage = message;
|
|
||||||
channelManager.CurrentChannel.Value = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TabsArea : Container
|
private class TabsArea : Container
|
||||||
{
|
{
|
||||||
// IsHovered is used
|
// IsHovered is used
|
||||||
|
Loading…
Reference in New Issue
Block a user