Merge pull request #22085 from peppy/fix-channel-init-request-pile-up

Fix retry loop for channel initialisation resulting in request pile-up
This commit is contained in:
Salman Ahmed 2023-01-09 23:11:29 +03:00 committed by GitHub
commit 426ac5ee54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -71,7 +71,6 @@ namespace osu.Game.Online.Chat
private UserLookupCache users { get; set; }
private readonly IBindable<APIState> apiState = new Bindable<APIState>();
private bool channelsInitialised;
private ScheduledDelegate scheduledAck;
private long? lastSilenceMessageId;
@ -95,15 +94,7 @@ namespace osu.Game.Online.Chat
connector.NewMessages += msgs => Schedule(() => addMessages(msgs));
connector.PresenceReceived += () => Schedule(() =>
{
if (!channelsInitialised)
{
channelsInitialised = true;
// we want this to run after the first presence so we can see if the user is in any channels already.
initializeChannels();
}
});
connector.PresenceReceived += () => Schedule(initializeChannels);
connector.Start();
@ -335,6 +326,11 @@ namespace osu.Game.Online.Chat
private void initializeChannels()
{
// This request is self-retrying until it succeeds.
// To avoid requests piling up when not logged in (ie. API is unavailable) exit early.
if (!api.IsLoggedIn)
return;
var req = new ListChannelsRequest();
bool joinDefaults = JoinedChannels.Count == 0;
@ -350,10 +346,11 @@ namespace osu.Game.Online.Chat
joinChannel(ch);
}
};
req.Failure += error =>
{
Logger.Error(error, "Fetching channel list failed");
initializeChannels();
Scheduler.AddDelayed(initializeChannels, 60000);
};
api.Queue(req);