2022-10-28 15:19:15 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
|
|
|
|
namespace osu.Game.Online.Notifications
|
|
|
|
{
|
2022-10-28 16:53:28 +08:00
|
|
|
/// <summary>
|
|
|
|
/// An abstract connector or <see cref="NotificationsClient"/>s.
|
|
|
|
/// </summary>
|
2022-11-02 10:49:57 +08:00
|
|
|
public abstract class NotificationsClientConnector : PersistentEndpointClientConnector
|
2022-10-28 15:19:15 +08:00
|
|
|
{
|
|
|
|
public event Action<Channel>? ChannelJoined;
|
2022-11-07 10:36:55 +08:00
|
|
|
public event Action<Channel>? ChannelParted;
|
2022-10-28 15:19:15 +08:00
|
|
|
public event Action<List<Message>>? NewMessages;
|
|
|
|
public event Action? PresenceReceived;
|
|
|
|
|
2022-10-28 16:53:28 +08:00
|
|
|
protected NotificationsClientConnector(IAPIProvider api)
|
2022-10-28 15:19:15 +08:00
|
|
|
: base(api)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-11-02 10:49:57 +08:00
|
|
|
protected sealed override async Task<PersistentEndpointClient> BuildConnectionAsync(CancellationToken cancellationToken)
|
2022-10-28 15:19:15 +08:00
|
|
|
{
|
2022-10-28 16:53:28 +08:00
|
|
|
var client = await BuildNotificationClientAsync(cancellationToken);
|
2022-10-28 15:19:15 +08:00
|
|
|
|
2022-10-28 16:53:28 +08:00
|
|
|
client.ChannelJoined = c => ChannelJoined?.Invoke(c);
|
2022-11-07 10:36:55 +08:00
|
|
|
client.ChannelParted = c => ChannelParted?.Invoke(c);
|
2022-10-28 16:53:28 +08:00
|
|
|
client.NewMessages = m => NewMessages?.Invoke(m);
|
|
|
|
client.PresenceReceived = () => PresenceReceived?.Invoke();
|
2022-10-28 15:19:15 +08:00
|
|
|
|
2022-10-28 16:53:28 +08:00
|
|
|
return client;
|
2022-10-28 15:19:15 +08:00
|
|
|
}
|
2022-10-28 16:53:28 +08:00
|
|
|
|
|
|
|
protected abstract Task<NotificationsClient> BuildNotificationClientAsync(CancellationToken cancellationToken);
|
2022-10-28 15:19:15 +08:00
|
|
|
}
|
|
|
|
}
|