Merge pull request #890 from peppy/async-channel-load

Load initial channel content asynchronously
This commit is contained in:
Dan Balasescu 2017-06-05 10:16:06 +09:00 committed by GitHub
commit 1cf10263cb
2 changed files with 28 additions and 13 deletions

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.Chat;
@ -43,11 +44,15 @@ public DrawableChannel(Channel channel)
channel.NewMessagesArrived += newMessagesArrived;
}
[BackgroundDependencyLoader]
private void load()
{
newMessagesArrived(Channel.Messages);
}
protected override void LoadComplete()
{
base.LoadComplete();
newMessagesArrived(Channel.Messages);
scrollToEnd();
}
@ -59,13 +64,13 @@ protected override void Dispose(bool isDisposing)
private void newMessagesArrived(IEnumerable<Message> newMessages)
{
if (!IsLoaded) return;
var displayMessages = newMessages.Skip(Math.Max(0, newMessages.Count() - Channel.MAX_HISTORY));
//up to last Channel.MAX_HISTORY messages
flow.Add(displayMessages.Select(m => new ChatLine(m)));
if (!IsLoaded) return;
if (scroll.IsScrolledToEnd(10) || !flow.Children.Any())
scrollToEnd();

View File

@ -266,20 +266,30 @@ protected Channel CurrentChannel
if (channelTabs.ChannelSelectorActive) return;
if (currentChannel != null)
currentChannelContainer.Clear(false);
currentChannel = value;
inputTextBox.Current.Disabled = currentChannel.ReadOnly;
channelTabs.Current.Value = value;
var loaded = loadedChannels.Find(d => d.Channel == value);
if (loaded == null)
loadedChannels.Add(loaded = new DrawableChannel(currentChannel));
{
currentChannelContainer.FadeOut(500, EasingTypes.OutQuint);
inputTextBox.Current.Disabled = currentChannel.ReadOnly;
currentChannelContainer.Add(loaded);
channelTabs.Current.Value = value;
loaded = new DrawableChannel(currentChannel);
loadedChannels.Add(loaded);
LoadComponentAsync(loaded, l =>
{
currentChannelContainer.Clear(false);
currentChannelContainer.Add(l);
currentChannelContainer.FadeIn(500, EasingTypes.OutQuint);
});
}
else
{
currentChannelContainer.Clear(false);
currentChannelContainer.Add(loaded);
}
}
}