Skip to content

Commit

Permalink
Add setCurrent param to ChannelManager.JoinChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
jai-x committed May 11, 2022
1 parent 2481201 commit cced860
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions osu.Game/Online/Chat/ChannelManager.cs
Expand Up @@ -420,10 +420,11 @@ private Channel getChannel(Channel lookup, bool addToAvailable = false, bool add
/// Joins a channel if it has not already been joined. Must be called from the update thread.
/// </summary>
/// <param name="channel">The channel to join.</param>
/// <param name="setCurrent">Set the channel to join as the current channel if the current channel is null.</param>
/// <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 setCurrent = true) => joinChannel(channel, true, setCurrent);

private Channel joinChannel(Channel channel, bool fetchInitialMessages = false)
private Channel joinChannel(Channel channel, bool fetchInitialMessages = false, bool setCurrent = true)
{
if (channel == null) return null;

Expand All @@ -439,7 +440,7 @@ private Channel joinChannel(Channel channel, bool fetchInitialMessages = false)
case ChannelType.Multiplayer:
// join is implicit. happens when you join a multiplayer game.
// this will probably change in the future.
joinChannel(channel, fetchInitialMessages);
joinChannel(channel, fetchInitialMessages, setCurrent);
return channel;

case ChannelType.PM:
Expand All @@ -460,7 +461,7 @@ private Channel joinChannel(Channel channel, bool fetchInitialMessages = false)

default:
var req = new JoinChannelRequest(channel);
req.Success += () => joinChannel(channel, fetchInitialMessages);
req.Success += () => joinChannel(channel, fetchInitialMessages, setCurrent);
req.Failure += ex => LeaveChannel(channel);
api.Queue(req);
return channel;
Expand All @@ -472,7 +473,8 @@ private Channel joinChannel(Channel channel, bool fetchInitialMessages = false)
this.fetchInitialMessages(channel);
}

CurrentChannel.Value ??= channel;
if (setCurrent)
CurrentChannel.Value ??= channel;

return channel;
}
Expand Down

0 comments on commit cced860

Please sign in to comment.