1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 03:47:26 +08:00
osu-lazer/osu.Game/Online/Chat/Channel.cs

53 lines
1.3 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-08-31 18:49:34 +08:00
using System;
2016-08-31 18:49:34 +08:00
using System.Collections.Generic;
using Newtonsoft.Json;
namespace osu.Game.Online.Chat
{
public class Channel
{
[JsonProperty(@"name")]
public string Name;
[JsonProperty(@"description")]
public string Topic;
[JsonProperty(@"type")]
public string Type;
[JsonProperty(@"channel_id")]
public int Id;
public List<Message> Messages = new List<Message>();
2016-09-28 14:33:02 +08:00
//internal bool Joined;
2016-08-31 18:49:34 +08:00
2017-02-20 20:07:44 +08:00
public const int MAX_HISTORY = 300;
2016-08-31 18:49:34 +08:00
[JsonConstructor]
public Channel()
{
}
2017-02-20 20:09:34 +08:00
public event Action<IEnumerable<Message>> NewMessagesArrived;
2017-02-20 20:09:34 +08:00
public void AddNewMessages(IEnumerable<Message> messages)
{
Messages.AddRange(messages);
purgeOldMessages();
NewMessagesArrived?.Invoke(messages);
}
private void purgeOldMessages()
{
int messageCount = Messages.Count;
if (messageCount > MAX_HISTORY)
Messages.RemoveRange(0, messageCount - MAX_HISTORY);
}
2016-08-31 18:49:34 +08:00
}
}