mirror of https://github.com/ppy/osu
Add message batching per-channel.
This commit is contained in:
parent
729f2eec8d
commit
7a2eedbd7e
|
@ -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<Message[]> NewMessagesArrived;
|
||||
public event Action<IEnumerable<Message>> NewMessagesArrived;
|
||||
|
||||
public void AddNewMessages(params Message[] messages)
|
||||
public void AddNewMessages(IEnumerable<Message> messages)
|
||||
{
|
||||
Messages.AddRange(messages);
|
||||
purgeOldMessages();
|
||||
|
|
|
@ -113,10 +113,11 @@ public void FetchNewMessages(APIAccess api)
|
|||
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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue