1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Merge pull request #9195 from peppy/fix-multi-chat-history

Fix chat history not being loaded for multiplayer matches
This commit is contained in:
Dan Balasescu 2020-06-03 22:49:27 +09:00 committed by GitHub
commit c4698e61ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 25 deletions

View File

@ -246,7 +246,12 @@ namespace osu.Game.Tests.Visual.Online
{ {
((BindableList<Channel>)ChannelManager.AvailableChannels).AddRange(channels); ((BindableList<Channel>)ChannelManager.AvailableChannels).AddRange(channels);
Child = ChatOverlay = new TestChatOverlay { RelativeSizeAxes = Axes.Both, }; InternalChildren = new Drawable[]
{
ChannelManager,
ChatOverlay = new TestChatOverlay { RelativeSizeAxes = Axes.Both, },
};
ChatOverlay.Show(); ChatOverlay.Show();
} }
} }

View File

@ -93,12 +93,6 @@ namespace osu.Game.Online.Chat
{ {
if (!(e.NewValue is ChannelSelectorTabItem.ChannelSelectorTabChannel)) if (!(e.NewValue is ChannelSelectorTabItem.ChannelSelectorTabChannel))
JoinChannel(e.NewValue); JoinChannel(e.NewValue);
if (e.NewValue?.MessagesLoaded == false)
{
// let's fetch a small number of messages to bring us up-to-date with the backlog.
fetchInitalMessages(e.NewValue);
}
} }
/// <summary> /// <summary>
@ -240,7 +234,6 @@ namespace osu.Game.Online.Chat
} }
JoinChannel(channel); JoinChannel(channel);
CurrentChannel.Value = channel;
break; break;
case "help": case "help":
@ -275,7 +268,7 @@ namespace osu.Game.Online.Chat
// join any channels classified as "defaults" // join any channels classified as "defaults"
if (joinDefaults && defaultChannels.Any(c => c.Equals(channel.Name, StringComparison.OrdinalIgnoreCase))) if (joinDefaults && defaultChannels.Any(c => c.Equals(channel.Name, StringComparison.OrdinalIgnoreCase)))
JoinChannel(ch); joinChannel(ch);
} }
}; };
req.Failure += error => req.Failure += error =>
@ -296,7 +289,7 @@ namespace osu.Game.Online.Chat
/// <param name="channel">The channel </param> /// <param name="channel">The channel </param>
private void fetchInitalMessages(Channel channel) private void fetchInitalMessages(Channel channel)
{ {
if (channel.Id <= 0) return; if (channel.Id <= 0 || channel.MessagesLoaded) return;
var fetchInitialMsgReq = new GetMessagesRequest(channel); var fetchInitialMsgReq = new GetMessagesRequest(channel);
fetchInitialMsgReq.Success += messages => fetchInitialMsgReq.Success += messages =>
@ -351,9 +344,10 @@ namespace osu.Game.Online.Chat
/// Joins a channel if it has not already been joined. /// Joins a channel if it has not already been joined.
/// </summary> /// </summary>
/// <param name="channel">The channel to join.</param> /// <param name="channel">The channel to join.</param>
/// <param name="alreadyJoined">Whether the channel has already been joined server-side. Will skip a join request.</param>
/// <returns>The joined channel. Note that this may not match the parameter channel as it is a backed object.</returns> /// <returns>The joined channel. Note that this may not match the parameter channel as it is a backed object.</returns>
public Channel JoinChannel(Channel channel, bool alreadyJoined = false) public Channel JoinChannel(Channel channel) => joinChannel(channel, true);
private Channel joinChannel(Channel channel, bool fetchInitialMessages = false)
{ {
if (channel == null) return null; if (channel == null) return null;
@ -361,21 +355,36 @@ namespace osu.Game.Online.Chat
// ensure we are joined to the channel // ensure we are joined to the channel
if (!channel.Joined.Value) if (!channel.Joined.Value)
{
if (alreadyJoined)
channel.Joined.Value = true;
else
{ {
switch (channel.Type) switch (channel.Type)
{ {
case ChannelType.Public: case ChannelType.Multiplayer:
// join is implicit. happens when you join a multiplayer game.
// this will probably change in the future.
channel.Joined.Value = true;
joinChannel(channel, fetchInitialMessages);
return channel;
case ChannelType.Private:
// can't do this yet.
break;
default:
var req = new JoinChannelRequest(channel, api.LocalUser.Value); var req = new JoinChannelRequest(channel, api.LocalUser.Value);
req.Success += () => JoinChannel(channel, true); req.Success += () =>
{
channel.Joined.Value = true;
joinChannel(channel, fetchInitialMessages);
};
req.Failure += ex => LeaveChannel(channel); req.Failure += ex => LeaveChannel(channel);
api.Queue(req); api.Queue(req);
return channel; return channel;
} }
} }
else
{
if (fetchInitialMessages)
fetchInitalMessages(channel);
} }
if (CurrentChannel.Value == null) if (CurrentChannel.Value == null)
@ -420,7 +429,8 @@ namespace osu.Game.Online.Chat
foreach (var channel in updates.Presence) foreach (var channel in updates.Presence)
{ {
// we received this from the server so should mark the channel already joined. // we received this from the server so should mark the channel already joined.
JoinChannel(channel, true); channel.Joined.Value = true;
joinChannel(channel);
} }
//todo: handle left channels //todo: handle left channels