Reschedule ack request on completion

This commit is contained in:
Dan Balasescu 2022-11-04 19:02:26 +09:00
parent 66bbe34116
commit 1d2818dc70
1 changed files with 22 additions and 10 deletions

View File

@ -72,7 +72,7 @@ public class ChannelManager : CompositeComponent, IChannelPostTarget
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
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);
}
}
/// <summary>