Centralise the maximum chat history variable.

This commit is contained in:
Dean Herbert 2016-10-12 15:25:07 +09:00
parent 24771a62cf
commit 1c0b769451
2 changed files with 7 additions and 9 deletions

View File

@ -30,6 +30,8 @@ public class Channel
//internal bool Joined;
public const int MAX_HISTORY = 100;
[JsonConstructor]
public Channel()
{
@ -47,13 +49,9 @@ public void AddNewMessages(params Message[] messages)
private void purgeOldMessages()
{
const int max_history = 50;
int messageCount = Messages.Count;
if (messageCount > 50)
{
Messages.RemoveRange(0, messageCount - max_history);
}
if (messageCount > MAX_HISTORY)
Messages.RemoveRange(0, messageCount - MAX_HISTORY);
}
}
}

View File

@ -67,13 +67,13 @@ private void newMessages(IEnumerable<Message> newMessages)
{
if (!IsLoaded) return;
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - 20));
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY));
//up to last 20 messages
//up to last Channel.MAX_HISTORY messages
foreach (Message m in displayMessages)
flow.Add(new ChatLine(m));
while (flow.Children.Count() > 20)
while (flow.Children.Count() > Channel.MAX_HISTORY)
flow.Remove(flow.Children.First());
}
}