1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 08:52:55 +08:00

Merge pull request #19702 from peppy/api-access-user-thread-safety

Add thread safety to `APIAccess.LocalUser`
This commit is contained in:
Dan Balasescu 2022-08-11 13:25:27 +09:00 committed by GitHub
commit b18f9b39dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -142,10 +142,10 @@ namespace osu.Game.Online.API
// Show a placeholder user if saved credentials are available.
// This is useful for storing local scores and showing a placeholder username after starting the game,
// until a valid connection has been established.
localUser.Value = new APIUser
setLocalUser(new APIUser
{
Username = ProvidedUsername,
};
});
}
// save the username at this point, if the user requested for it to be.
@ -188,12 +188,12 @@ namespace osu.Game.Online.API
else
failConnectionProcess();
};
userReq.Success += u =>
userReq.Success += user =>
{
localUser.Value = u;
// todo: save/pull from settings
localUser.Value.Status.Value = new UserStatusOnline();
user.Status.Value = new UserStatusOnline();
setLocalUser(user);
failureCount = 0;
};
@ -453,7 +453,7 @@ namespace osu.Game.Online.API
// Scheduled prior to state change such that the state changed event is invoked with the correct user and their friends present
Schedule(() =>
{
localUser.Value = createGuestUser();
setLocalUser(createGuestUser());
friends.Clear();
});
@ -463,6 +463,8 @@ namespace osu.Game.Online.API
private static APIUser createGuestUser() => new GuestUser();
private void setLocalUser(APIUser user) => Scheduler.Add(() => localUser.Value = user, false);
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);

View File

@ -13,19 +13,16 @@ namespace osu.Game.Online.API
{
/// <summary>
/// The local user.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// </summary>
IBindable<APIUser> LocalUser { get; }
/// <summary>
/// The user's friends.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// </summary>
IBindableList<APIUser> Friends { get; }
/// <summary>
/// The current user's activity.
/// This is not thread-safe and should be scheduled locally if consumed from a drawable component.
/// </summary>
IBindable<UserActivity> Activity { get; }