Fix `PopulateUser` not populating immediately when `immediate` is specified (due to scheduling)

This commit is contained in:
Dean Herbert 2021-10-27 17:45:46 +09:00
parent 3130616300
commit 35168948fe
1 changed files with 24 additions and 13 deletions

View File

@ -226,8 +226,30 @@ public void PopulateUser(User user, Action success = null, Action failure = null
{
var req = new GetUserRequest(user.Id, Ruleset.Value);
req.Success += res =>
if (immediate)
{
API.Perform(req);
populate();
}
else
{
req.Success += res => { populate(); };
req.Failure += _ =>
{
user.Id = 1;
failure?.Invoke();
};
API.Queue(req);
}
void populate()
{
var res = req.Response;
if (res == null)
return;
user.Id = res.Id;
user.Username = res.Username;
@ -236,18 +258,7 @@ public void PopulateUser(User user, Action success = null, Action failure = null
user.Cover = res.Cover;
success?.Invoke();
};
req.Failure += _ =>
{
user.Id = 1;
failure?.Invoke();
};
if (immediate)
API.Perform(req);
else
API.Queue(req);
}
}
protected override void LoadComplete()