2016-08-31 18:49:34 +08:00
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
2016-10-07 21:51:10 +08:00
|
|
|
using System;
|
2016-08-31 18:49:34 +08:00
|
|
|
using System.Collections.Generic;
|
2016-10-07 21:51:10 +08:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
2016-08-31 18:49:34 +08:00
|
|
|
using Newtonsoft.Json;
|
2016-10-07 21:51:10 +08:00
|
|
|
using osu.Framework.Configuration;
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests;
|
2016-08-31 18:49:34 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-10-12 14:25:07 +08:00
|
|
|
public const int MAX_HISTORY = 100;
|
|
|
|
|
2016-08-31 18:49:34 +08:00
|
|
|
[JsonConstructor]
|
|
|
|
public Channel()
|
|
|
|
{
|
|
|
|
}
|
2016-10-07 21:51:10 +08:00
|
|
|
|
|
|
|
public event Action<Message[]> NewMessagesArrived;
|
|
|
|
|
|
|
|
public void AddNewMessages(params Message[] messages)
|
|
|
|
{
|
|
|
|
Messages.AddRange(messages);
|
|
|
|
purgeOldMessages();
|
|
|
|
|
|
|
|
NewMessagesArrived?.Invoke(messages);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void purgeOldMessages()
|
|
|
|
{
|
|
|
|
int messageCount = Messages.Count;
|
2016-10-12 14:25:07 +08:00
|
|
|
if (messageCount > MAX_HISTORY)
|
|
|
|
Messages.RemoveRange(0, messageCount - MAX_HISTORY);
|
2016-10-07 21:51:10 +08:00
|
|
|
}
|
2016-08-31 18:49:34 +08:00
|
|
|
}
|
|
|
|
}
|