mirror of
https://github.com/osukey/osukey.git
synced 2025-08-02 22:26:41 +09:00
General improvements to chat querying and logic organisation.
This commit is contained in:
@ -1,8 +1,14 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
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
|
||||
{
|
||||
@ -28,5 +34,26 @@ namespace osu.Game.Online.Chat
|
||||
public Channel()
|
||||
{
|
||||
}
|
||||
|
||||
public event Action<Message[]> NewMessagesArrived;
|
||||
|
||||
public void AddNewMessages(params Message[] messages)
|
||||
{
|
||||
Messages.AddRange(messages);
|
||||
purgeOldMessages();
|
||||
|
||||
NewMessagesArrived?.Invoke(messages);
|
||||
}
|
||||
|
||||
private void purgeOldMessages()
|
||||
{
|
||||
const int max_history = 50;
|
||||
|
||||
int messageCount = Messages.Count;
|
||||
if (messageCount > 50)
|
||||
{
|
||||
Messages.RemoveRange(0, messageCount - max_history);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user