From ec890cd459ce8f5d48470b37e67cbda562e4787e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 24 Nov 2025 11:33:43 +0100 Subject: [PATCH] Clear chat state when local user changes Closes https://github.com/ppy/osu/issues/35081. --- osu.Game/Online/Chat/ChannelManager.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/osu.Game/Online/Chat/ChannelManager.cs b/osu.Game/Online/Chat/ChannelManager.cs index eb5d6d1b9c..aec7928ba8 100644 --- a/osu.Game/Online/Chat/ChannelManager.cs +++ b/osu.Game/Online/Chat/ChannelManager.cs @@ -70,6 +70,7 @@ namespace osu.Game.Online.Chat [Resolved] private UserLookupCache users { get; set; } + private readonly IBindable localUser = new Bindable(); private readonly IBindable apiState = new Bindable(); private readonly IBindableList localUserBlocks = new BindableList(); private ScheduledDelegate scheduledAck; @@ -95,6 +96,9 @@ namespace osu.Game.Online.Chat chatClient.PresenceReceived += () => Schedule(initializeChannels); chatClient.RequestPresence(); + localUser.BindTo(api.LocalUser); + localUser.BindValueChanged(userChanged); + apiState.BindTo(api.State); apiState.BindValueChanged(_ => SendAck(), true); @@ -102,6 +106,22 @@ namespace osu.Game.Online.Chat localUserBlocks.BindCollectionChanged((_, args) => Schedule(() => onBlocksChanged(args))); } + private void userChanged(ValueChangedEvent userChange) + { + if (userChange.OldValue?.Equals(userChange.NewValue) == true) + return; + + CurrentChannel.Value = null; + + foreach (var joinedChannel in joinedChannels) + joinedChannel.Joined.Value = false; + + joinedChannels.Clear(); + // additionally clear the history of last joined channels so that the new user can't reopen the old user's channels + // (would likely fail web-side on perms anyway, but why even get that far) + closedChannels.Clear(); + } + /// /// Opens a channel or switches to the channel if already opened. ///