From e3adf5a98502d714c6849095f257a2ad343b5038 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 7 Nov 2022 11:36:55 +0900 Subject: [PATCH] Handle channel parts --- osu.Game/Online/Chat/ChannelManager.cs | 2 ++ osu.Game/Online/Notifications/NotificationsClient.cs | 3 +++ .../Online/Notifications/NotificationsClientConnector.cs | 2 ++ .../WebSocket/WebSocketNotificationsClient.cs | 9 +++++++++ 4 files changed, 16 insertions(+) diff --git a/osu.Game/Online/Chat/ChannelManager.cs b/osu.Game/Online/Chat/ChannelManager.cs index db2436333b..93033dffa0 100644 --- a/osu.Game/Online/Chat/ChannelManager.cs +++ b/osu.Game/Online/Chat/ChannelManager.cs @@ -99,6 +99,8 @@ namespace osu.Game.Online.Chat joinChannel(localChannel); }); + connector.ChannelParted += ch => Schedule(() => LeaveChannel(getChannel(ch))); + connector.NewMessages += msgs => Schedule(() => addMessages(msgs)); connector.PresenceReceived += () => Schedule(() => diff --git a/osu.Game/Online/Notifications/NotificationsClient.cs b/osu.Game/Online/Notifications/NotificationsClient.cs index cb5e94fb1d..5182bfa0e5 100644 --- a/osu.Game/Online/Notifications/NotificationsClient.cs +++ b/osu.Game/Online/Notifications/NotificationsClient.cs @@ -18,6 +18,7 @@ namespace osu.Game.Online.Notifications public abstract class NotificationsClient : PersistentEndpointClient { public Action? ChannelJoined; + public Action? ChannelParted; public Action>? NewMessages; public Action? PresenceReceived; @@ -65,6 +66,8 @@ namespace osu.Game.Online.Notifications ChannelJoined?.Invoke(channel); } + protected void HandleChannelParted(Channel channel) => ChannelParted?.Invoke(channel); + protected void HandleMessages(List messages) { NewMessages?.Invoke(messages); diff --git a/osu.Game/Online/Notifications/NotificationsClientConnector.cs b/osu.Game/Online/Notifications/NotificationsClientConnector.cs index d4c846a7a2..d2c2e6673c 100644 --- a/osu.Game/Online/Notifications/NotificationsClientConnector.cs +++ b/osu.Game/Online/Notifications/NotificationsClientConnector.cs @@ -16,6 +16,7 @@ namespace osu.Game.Online.Notifications public abstract class NotificationsClientConnector : PersistentEndpointClientConnector { public event Action? ChannelJoined; + public event Action? ChannelParted; public event Action>? NewMessages; public event Action? PresenceReceived; @@ -29,6 +30,7 @@ namespace osu.Game.Online.Notifications var client = await BuildNotificationClientAsync(cancellationToken); client.ChannelJoined = c => ChannelJoined?.Invoke(c); + client.ChannelParted = c => ChannelParted?.Invoke(c); client.NewMessages = m => NewMessages?.Invoke(m); client.PresenceReceived = () => PresenceReceived?.Invoke(); diff --git a/osu.Game/Online/Notifications/WebSocket/WebSocketNotificationsClient.cs b/osu.Game/Online/Notifications/WebSocket/WebSocketNotificationsClient.cs index eefe684795..8f4b3c2f97 100644 --- a/osu.Game/Online/Notifications/WebSocket/WebSocketNotificationsClient.cs +++ b/osu.Game/Online/Notifications/WebSocket/WebSocketNotificationsClient.cs @@ -122,6 +122,15 @@ namespace osu.Game.Online.Notifications.WebSocket HandleJoinedChannel(joinedChannel); break; + case @"chat.channel.part": + Debug.Assert(message.Data != null); + + Channel? partedChannel = JsonConvert.DeserializeObject(message.Data.ToString()); + Debug.Assert(partedChannel != null); + + HandleChannelParted(partedChannel); + break; + case @"chat.message.new": Debug.Assert(message.Data != null);