mirror of https://github.com/ppy/osu
Centralise the maximum chat history variable.
This commit is contained in:
parent
24771a62cf
commit
1c0b769451
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue