Remove StartChat()/chat enablement

This commit is contained in:
Dan Balasescu 2022-11-04 18:48:34 +09:00
parent 58396d49dc
commit 72745656e7
4 changed files with 5 additions and 45 deletions

View File

@ -110,8 +110,6 @@ namespace osu.Game.Online.Chat
}
});
connector.StartChat();
apiState.BindTo(api.State);
apiState.BindValueChanged(status =>
{

View File

@ -23,7 +23,6 @@ namespace osu.Game.Online.Notifications
protected readonly IAPIProvider API;
private bool enableChat;
private long lastMessageId;
protected NotificationsClient(IAPIProvider api)
@ -31,28 +30,7 @@ namespace osu.Game.Online.Notifications
API = api;
}
public bool EnableChat
{
get => enableChat;
set
{
if (enableChat == value)
return;
enableChat = value;
if (EnableChat)
Task.Run(StartChatAsync);
}
}
public override async Task ConnectAsync(CancellationToken cancellationToken)
{
if (EnableChat)
await StartChatAsync();
}
protected virtual Task StartChatAsync()
public override Task ConnectAsync(CancellationToken cancellationToken)
{
API.Queue(CreateFetchMessagesRequest(0));
return Task.CompletedTask;

View File

@ -19,21 +19,11 @@ namespace osu.Game.Online.Notifications
public event Action<List<Message>>? NewMessages;
public event Action? PresenceReceived;
private bool chatStarted;
protected NotificationsClientConnector(IAPIProvider api)
: base(api)
{
}
public void StartChat()
{
chatStarted = true;
if (CurrentConnection is NotificationsClient client)
client.EnableChat = true;
}
protected sealed override async Task<PersistentEndpointClient> BuildConnectionAsync(CancellationToken cancellationToken)
{
var client = await BuildNotificationClientAsync(cancellationToken);
@ -41,7 +31,6 @@ namespace osu.Game.Online.Notifications
client.ChannelJoined = c => ChannelJoined?.Invoke(c);
client.NewMessages = m => NewMessages?.Invoke(m);
client.PresenceReceived = () => PresenceReceived?.Invoke();
client.EnableChat = chatStarted;
return client;
}

View File

@ -22,27 +22,22 @@ namespace osu.Game.Online.Notifications.WebSocket
{
private readonly ClientWebSocket socket;
private readonly string endpoint;
private readonly IAPIProvider api;
public WebSocketNotificationsClient(ClientWebSocket socket, string endpoint, IAPIProvider api)
: base(api)
{
this.socket = socket;
this.endpoint = endpoint;
this.api = api;
}
public override async Task ConnectAsync(CancellationToken cancellationToken)
{
await socket.ConnectAsync(new Uri(endpoint), cancellationToken).ConfigureAwait(false);
runReadLoop(cancellationToken);
await base.ConnectAsync(cancellationToken);
}
protected override async Task StartChatAsync()
{
await sendMessage(new StartChatRequest(), CancellationToken.None);
await base.StartChatAsync();
runReadLoop(cancellationToken);
await base.ConnectAsync(cancellationToken);
}
private void runReadLoop(CancellationToken cancellationToken) => Task.Run(async () =>