mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 00:53:56 +09:00
Remove StartChat()/chat enablement
This commit is contained in:
@ -110,8 +110,6 @@ namespace osu.Game.Online.Chat
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connector.StartChat();
|
|
||||||
|
|
||||||
apiState.BindTo(api.State);
|
apiState.BindTo(api.State);
|
||||||
apiState.BindValueChanged(status =>
|
apiState.BindValueChanged(status =>
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,6 @@ namespace osu.Game.Online.Notifications
|
|||||||
|
|
||||||
protected readonly IAPIProvider API;
|
protected readonly IAPIProvider API;
|
||||||
|
|
||||||
private bool enableChat;
|
|
||||||
private long lastMessageId;
|
private long lastMessageId;
|
||||||
|
|
||||||
protected NotificationsClient(IAPIProvider api)
|
protected NotificationsClient(IAPIProvider api)
|
||||||
@ -31,28 +30,7 @@ namespace osu.Game.Online.Notifications
|
|||||||
API = api;
|
API = api;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool EnableChat
|
public override Task ConnectAsync(CancellationToken cancellationToken)
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
API.Queue(CreateFetchMessagesRequest(0));
|
API.Queue(CreateFetchMessagesRequest(0));
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
@ -19,21 +19,11 @@ namespace osu.Game.Online.Notifications
|
|||||||
public event Action<List<Message>>? NewMessages;
|
public event Action<List<Message>>? NewMessages;
|
||||||
public event Action? PresenceReceived;
|
public event Action? PresenceReceived;
|
||||||
|
|
||||||
private bool chatStarted;
|
|
||||||
|
|
||||||
protected NotificationsClientConnector(IAPIProvider api)
|
protected NotificationsClientConnector(IAPIProvider api)
|
||||||
: base(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)
|
protected sealed override async Task<PersistentEndpointClient> BuildConnectionAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var client = await BuildNotificationClientAsync(cancellationToken);
|
var client = await BuildNotificationClientAsync(cancellationToken);
|
||||||
@ -41,7 +31,6 @@ namespace osu.Game.Online.Notifications
|
|||||||
client.ChannelJoined = c => ChannelJoined?.Invoke(c);
|
client.ChannelJoined = c => ChannelJoined?.Invoke(c);
|
||||||
client.NewMessages = m => NewMessages?.Invoke(m);
|
client.NewMessages = m => NewMessages?.Invoke(m);
|
||||||
client.PresenceReceived = () => PresenceReceived?.Invoke();
|
client.PresenceReceived = () => PresenceReceived?.Invoke();
|
||||||
client.EnableChat = chatStarted;
|
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
@ -22,27 +22,22 @@ namespace osu.Game.Online.Notifications.WebSocket
|
|||||||
{
|
{
|
||||||
private readonly ClientWebSocket socket;
|
private readonly ClientWebSocket socket;
|
||||||
private readonly string endpoint;
|
private readonly string endpoint;
|
||||||
private readonly IAPIProvider api;
|
|
||||||
|
|
||||||
public WebSocketNotificationsClient(ClientWebSocket socket, string endpoint, IAPIProvider api)
|
public WebSocketNotificationsClient(ClientWebSocket socket, string endpoint, IAPIProvider api)
|
||||||
: base(api)
|
: base(api)
|
||||||
{
|
{
|
||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
this.endpoint = endpoint;
|
this.endpoint = endpoint;
|
||||||
this.api = api;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task ConnectAsync(CancellationToken cancellationToken)
|
public override async Task ConnectAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await socket.ConnectAsync(new Uri(endpoint), cancellationToken).ConfigureAwait(false);
|
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 sendMessage(new StartChatRequest(), CancellationToken.None);
|
||||||
await base.StartChatAsync();
|
|
||||||
|
runReadLoop(cancellationToken);
|
||||||
|
|
||||||
|
await base.ConnectAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runReadLoop(CancellationToken cancellationToken) => Task.Run(async () =>
|
private void runReadLoop(CancellationToken cancellationToken) => Task.Run(async () =>
|
||||||
|
Reference in New Issue
Block a user