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

Add thread safety to APIAccess.LocalUser

This commit is contained in:
Dean Herbert 2022-08-11 12:44:58 +09:00
parent 1721a91168
commit e5b534bb26
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; }