Add functionality to switch to successfully joined channel

This commit is contained in:
Salman Ahmed 2022-03-10 21:28:38 +03:00
parent 022dd88aef
commit c72e8a8b5e

View File

@ -420,10 +420,11 @@ namespace osu.Game.Online.Chat
/// Joins a channel if it has not already been joined. Must be called from the update thread. /// Joins a channel if it has not already been joined. Must be called from the update thread.
/// </summary> /// </summary>
/// <param name="channel">The channel to join.</param> /// <param name="channel">The channel to join.</param>
/// <param name="switchToJoined">Switch <see cref="CurrentChannel"/> to the joined channel on successful 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) => joinChannel(channel, true); public Channel JoinChannel(Channel channel, bool switchToJoined = false) => joinChannel(channel, switchToJoined, true);
private Channel joinChannel(Channel channel, bool fetchInitialMessages = false) private Channel joinChannel(Channel channel, bool switchToJoined = false, bool fetchInitialMessages = false)
{ {
if (channel == null) return null; if (channel == null) return null;
@ -439,7 +440,7 @@ namespace osu.Game.Online.Chat
case ChannelType.Multiplayer: case ChannelType.Multiplayer:
// join is implicit. happens when you join a multiplayer game. // join is implicit. happens when you join a multiplayer game.
// this will probably change in the future. // this will probably change in the future.
joinChannel(channel, fetchInitialMessages); joinChannel(channel, switchToJoined, fetchInitialMessages);
return channel; return channel;
case ChannelType.PM: case ChannelType.PM:
@ -460,7 +461,7 @@ namespace osu.Game.Online.Chat
default: default:
var req = new JoinChannelRequest(channel); var req = new JoinChannelRequest(channel);
req.Success += () => joinChannel(channel, fetchInitialMessages); req.Success += () => joinChannel(channel, switchToJoined, fetchInitialMessages);
req.Failure += ex => LeaveChannel(channel); req.Failure += ex => LeaveChannel(channel);
api.Queue(req); api.Queue(req);
return channel; return channel;
@ -472,7 +473,8 @@ namespace osu.Game.Online.Chat
this.fetchInitialMessages(channel); this.fetchInitialMessages(channel);
} }
CurrentChannel.Value ??= channel; if (switchToJoined || CurrentChannel.Value == null)
CurrentChannel.Value = channel;
return channel; return channel;
} }