1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 06:07:25 +08:00

Rename MAX_HISTORY to MaxHistory, added some logging on failures, use a lamda in ChatOverlay instead of a method pointer.

This commit is contained in:
miterosan 2018-07-09 20:39:16 +02:00
parent d4f9bcdee1
commit f681ef41ac
4 changed files with 13 additions and 22 deletions

View File

@ -14,13 +14,14 @@ namespace osu.Game.Online.Chat
{
public class Channel
{
public readonly int MAX_HISTORY = 300;
public readonly int MaxHistory = 300;
/// <summary>
/// Contains every joined user except the current logged in user.
/// </summary>
public readonly ObservableCollection<User> JoinedUsers = new ObservableCollection<User>();
public readonly SortedList<Message> Messages = new SortedList<Message>(Comparer<Message>.Default);
private readonly List<LocalEchoMessage> pendingMessages = new List<LocalEchoMessage>();
public event Action<IEnumerable<Message>> NewMessagesArrived;
public event Action<LocalEchoMessage, Message> PendingMessageResolved;
@ -43,8 +44,6 @@ namespace osu.Game.Online.Chat
[JsonProperty(@"channel_id")]
public long Id;
private readonly List<LocalEchoMessage> pendingMessages = new List<LocalEchoMessage>();
[JsonConstructor]
public Channel()
{
@ -101,12 +100,7 @@ namespace osu.Game.Online.Chat
}
if (Messages.Contains(final))
{
// message already inserted, so let's throw away this update.
// we may want to handle this better in the future, but for the time being api requests are single-threaded so order is assumed.
MessageRemoved?.Invoke(echo);
return;
}
throw new InvalidOperationException("Attempted to add the same message again");
Messages.Add(final);
PendingMessageResolved?.Invoke(echo, final);
@ -116,8 +110,8 @@ namespace osu.Game.Online.Chat
{
// never purge local echos
int messageCount = Messages.Count - pendingMessages.Count;
if (messageCount > MAX_HISTORY)
Messages.RemoveRange(0, messageCount - MAX_HISTORY);
if (messageCount > MaxHistory)
Messages.RemoveRange(0, messageCount - MaxHistory);
}

View File

@ -112,7 +112,11 @@ namespace osu.Game.Online.Chat
CurrentChannel.Value.AddLocalEcho(message);
var req = new PostMessageRequest(message);
req.Failure += e => CurrentChannel.Value?.ReplaceMessage(message, null);
req.Failure += exception =>
{
Logger.Error(exception, "Posting message failed.");
CurrentChannel.Value?.ReplaceMessage(message, null);
};
req.Success += m => CurrentChannel.Value?.ReplaceMessage(message, m);
api.Queue(req);
}
@ -305,7 +309,6 @@ namespace osu.Game.Online.Chat
public ChannelNotFoundException(string channelName)
: base($"A channel with the name {channelName} could not be found.")
{
}
}
}

View File

@ -79,7 +79,7 @@ namespace osu.Game.Overlays.Chat
private void newMessagesArrived(IEnumerable<Message> newMessages)
{
// Add up to last Channel.MAX_HISTORY messages
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY));
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MaxHistory));
flow.AddRange(displayMessages.Select(m => new ChatLine(m)));
@ -89,7 +89,7 @@ namespace osu.Game.Overlays.Chat
scrollToEnd();
var staleMessages = flow.Children.Where(c => c.LifetimeEnd == double.MaxValue).ToArray();
int count = staleMessages.Length - Channel.MAX_HISTORY;
int count = staleMessages.Length - Channel.MaxHistory;
for (int i = 0; i < count; i++)
{

View File

@ -186,12 +186,6 @@ namespace osu.Game.Overlays
channelSelection.OnRequestLeave = channel => channelManager.JoinedChannels.Remove(channel);
}
private void availableChannelsChanged(object sender, NotifyCollectionChangedEventArgs args)
{
channelSelection.UpdateAvailableChannels(channelManager.);
}
private void joinedChannelsChanged(object sender, NotifyCollectionChangedEventArgs args)
{
switch (args.Action)
@ -337,7 +331,7 @@ namespace osu.Game.Overlays
this.channelManager = channelManager;
channelManager.CurrentChannel.ValueChanged += currentChatChanged;
channelManager.JoinedChannels.CollectionChanged += joinedChannelsChanged;
channelManager.AvailableChannels.CollectionChanged += availableChannelsChanged;
channelManager.AvailableChannels.CollectionChanged += (sender, args) => channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
Add(channelManager);
}