From 1d2818dc70dbafecb5a60db70c9229917bdcc487 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 4 Nov 2022 19:02:26 +0900 Subject: [PATCH] Reschedule ack request on completion --- osu.Game/Online/Chat/ChannelManager.cs | 32 ++++++++++++++++++-------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/osu.Game/Online/Chat/ChannelManager.cs b/osu.Game/Online/Chat/ChannelManager.cs index a9603506c6..035957a7c4 100644 --- a/osu.Game/Online/Chat/ChannelManager.cs +++ b/osu.Game/Online/Chat/ChannelManager.cs @@ -72,7 +72,7 @@ public class ChannelManager : CompositeComponent, IChannelPostTarget private readonly IBindable apiState = new Bindable(); private bool channelsInitialised; - private ScheduledDelegate ackDelegate; + private ScheduledDelegate scheduledAck; public ChannelManager(IAPIProvider api) { @@ -112,16 +112,28 @@ private void load() }); apiState.BindTo(api.State); - apiState.BindValueChanged(status => - { - ackDelegate?.Cancel(); + apiState.BindValueChanged(_ => performChatAckRequest(), true); + } - if (status.NewValue == APIState.Online) - { - Scheduler.Add(ackDelegate = new ScheduledDelegate(() => api.Queue(new ChatAckRequest()), 0, 60000)); - // Todo: Handle silences. - } - }, true); + private void performChatAckRequest() + { + if (apiState.Value != APIState.Online) + return; + + scheduledAck?.Cancel(); + + var req = new ChatAckRequest(); + req.Success += _ => scheduleNextRequest(); + req.Failure += _ => scheduleNextRequest(); + api.Queue(req); + + // Todo: Handle silences. + + void scheduleNextRequest() + { + scheduledAck?.Cancel(); + scheduledAck = Scheduler.AddDelayed(performChatAckRequest, 60000); + } } ///