1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 17:32:54 +08:00

Add message batching per-channel.

This commit is contained in:
Dean Herbert 2017-02-20 21:09:34 +09:00
parent 729f2eec8d
commit 7a2eedbd7e
No known key found for this signature in database
GPG Key ID: 46D71BF4958ABB49
2 changed files with 7 additions and 11 deletions

View File

@ -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 @@ namespace osu.Game.Online.Chat
{
}
public event Action<Message[]> NewMessagesArrived;
public event Action<IEnumerable<Message>> NewMessagesArrived;
public void AddNewMessages(params Message[] messages)
public void AddNewMessages(IEnumerable<Message> messages)
{
Messages.AddRange(messages);
purgeOldMessages();

View File

@ -113,10 +113,11 @@ namespace osu.Game.Overlays
fetchReq = new GetMessagesRequest(careChannels, lastMessageId);
fetchReq.Success += delegate (List<Message> 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;