From cced8609f6d2190156d24c75d5a048166761eb74 Mon Sep 17 00:00:00 2001 From: Jai Sharma Date: Wed, 11 May 2022 22:51:15 +0100 Subject: [PATCH] Add `setCurrent` param to `ChannelManager.JoinChannel` --- osu.Game/Online/Chat/ChannelManager.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/osu.Game/Online/Chat/ChannelManager.cs b/osu.Game/Online/Chat/ChannelManager.cs index 47e45e67d16a..1fe784f68bba 100644 --- a/osu.Game/Online/Chat/ChannelManager.cs +++ b/osu.Game/Online/Chat/ChannelManager.cs @@ -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. /// /// The channel to join. + /// Set the channel to join as the current channel if the current channel is null. /// The joined channel. Note that this may not match the parameter channel as it is a backed object. - 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; @@ -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: @@ -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; @@ -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; }