1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 12:33:01 +08:00

Handle channel parts

This commit is contained in:
Dan Balasescu 2022-11-07 11:36:55 +09:00
parent d426977f03
commit e3adf5a985
4 changed files with 16 additions and 0 deletions

View File

@ -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(() =>

View File

@ -18,6 +18,7 @@ namespace osu.Game.Online.Notifications
public abstract class NotificationsClient : PersistentEndpointClient
{
public Action<Channel>? ChannelJoined;
public Action<Channel>? ChannelParted;
public Action<List<Message>>? 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<Message> messages)
{
NewMessages?.Invoke(messages);

View File

@ -16,6 +16,7 @@ namespace osu.Game.Online.Notifications
public abstract class NotificationsClientConnector : PersistentEndpointClientConnector
{
public event Action<Channel>? ChannelJoined;
public event Action<Channel>? ChannelParted;
public event Action<List<Message>>? 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();

View File

@ -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<Channel>(message.Data.ToString());
Debug.Assert(partedChannel != null);
HandleChannelParted(partedChannel);
break;
case @"chat.message.new":
Debug.Assert(message.Data != null);