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

View File

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