From 7a2eedbd7eee0d75ff43c77a96db99fa55bdb47f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 20 Feb 2017 21:09:34 +0900 Subject: [PATCH] Add message batching per-channel. --- osu.Game/Online/Chat/Channel.cs | 9 ++------- osu.Game/Overlays/ChatOverlay.cs | 9 +++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/osu.Game/Online/Chat/Channel.cs b/osu.Game/Online/Chat/Channel.cs index 9060bcd4f1..d895b93336 100644 --- a/osu.Game/Online/Chat/Channel.cs +++ b/osu.Game/Online/Chat/Channel.cs @@ -3,12 +3,7 @@ using System; using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; using Newtonsoft.Json; -using osu.Framework.Configuration; -using osu.Game.Online.API; -using osu.Game.Online.API.Requests; namespace osu.Game.Online.Chat { @@ -37,9 +32,9 @@ public Channel() { } - public event Action NewMessagesArrived; + public event Action> NewMessagesArrived; - public void AddNewMessages(params Message[] messages) + public void AddNewMessages(IEnumerable messages) { Messages.AddRange(messages); purgeOldMessages(); diff --git a/osu.Game/Overlays/ChatOverlay.cs b/osu.Game/Overlays/ChatOverlay.cs index e1593f1654..40226eb1cf 100644 --- a/osu.Game/Overlays/ChatOverlay.cs +++ b/osu.Game/Overlays/ChatOverlay.cs @@ -113,10 +113,11 @@ public void FetchNewMessages(APIAccess api) fetchReq = new GetMessagesRequest(careChannels, lastMessageId); fetchReq.Success += delegate (List messages) { - foreach (Message m in messages) - { - careChannels.Find(c => c.Id == m.ChannelId).AddNewMessages(m); - } + var ids = messages.Select(m => m.ChannelId).Distinct(); + + //batch messages per channel. + foreach (var id in ids) + careChannels.Find(c => c.Id == id)?.AddNewMessages(messages.Where(m => m.ChannelId == id)); lastMessageId = messages.LastOrDefault()?.Id ?? lastMessageId;