1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-18 16:52:54 +08:00

Remove Status and Activity bindables from APIUser

As for the tests, I'm (ab)using the `IsOnline` state for the time being
to restore functionality.
This commit is contained in:
Dan Balasescu 2025-01-14 23:44:14 +09:00
parent ad14720714
commit 20108e3b74
No known key found for this signature in database
11 changed files with 46 additions and 84 deletions

View File

@ -54,8 +54,8 @@ namespace osu.Desktop
[Resolved] [Resolved]
private OsuConfigManager config { get; set; } = null!; private OsuConfigManager config { get; set; } = null!;
private readonly IBindable<UserStatus?> status = new Bindable<UserStatus?>(); private readonly IBindable<UserStatus> status = new Bindable<UserStatus>();
private readonly IBindable<UserActivity> activity = new Bindable<UserActivity>(); private readonly IBindable<UserActivity?> activity = new Bindable<UserActivity?>();
private readonly Bindable<DiscordRichPresenceMode> privacyMode = new Bindable<DiscordRichPresenceMode>(); private readonly Bindable<DiscordRichPresenceMode> privacyMode = new Bindable<DiscordRichPresenceMode>();
private readonly RichPresence presence = new RichPresence private readonly RichPresence presence = new RichPresence
@ -108,14 +108,8 @@ namespace osu.Desktop
config.BindWith(OsuSetting.DiscordRichPresence, privacyMode); config.BindWith(OsuSetting.DiscordRichPresence, privacyMode);
user = api.LocalUser.GetBoundCopy(); user = api.LocalUser.GetBoundCopy();
user.BindValueChanged(u => status.BindTo(api.Status);
{ activity.BindTo(api.Activity);
status.UnbindBindings();
status.BindTo(u.NewValue.Status);
activity.UnbindBindings();
activity.BindTo(u.NewValue.Activity);
}, true);
ruleset.BindValueChanged(_ => schedulePresenceUpdate()); ruleset.BindValueChanged(_ => schedulePresenceUpdate());
status.BindValueChanged(_ => schedulePresenceUpdate()); status.BindValueChanged(_ => schedulePresenceUpdate());

View File

@ -89,7 +89,7 @@ namespace osu.Game.Tests.Visual.Menus
AddStep("clear handler", () => dummyAPI.HandleRequest = null); AddStep("clear handler", () => dummyAPI.HandleRequest = null);
assertDropdownState(UserAction.Online); assertDropdownState(UserAction.Online);
AddStep("change user state", () => dummyAPI.LocalUser.Value.Status.Value = UserStatus.DoNotDisturb); AddStep("change user state", () => dummyAPI.Status.Value = UserStatus.DoNotDisturb);
assertDropdownState(UserAction.DoNotDisturb); assertDropdownState(UserAction.DoNotDisturb);
} }

View File

@ -62,10 +62,7 @@ namespace osu.Game.Tests.Visual.Online
CountryCode = countryCode, CountryCode = countryCode,
CoverUrl = cover, CoverUrl = cover,
Colour = color ?? "000000", Colour = color ?? "000000",
Status = IsOnline = true
{
Value = UserStatus.Online
},
}; };
return new ClickableAvatar(user, showPanel) return new ClickableAvatar(user, showPanel)

View File

@ -76,7 +76,7 @@ namespace osu.Game.Tests.Visual.Online
Id = 3103765, Id = 3103765,
CountryCode = CountryCode.JP, CountryCode = CountryCode.JP,
CoverUrl = @"https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg", CoverUrl = @"https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg",
Status = { Value = UserStatus.Online } IsOnline = true
}) { Width = 300 }, }) { Width = 300 },
boundPanel1 = new UserGridPanel(new APIUser boundPanel1 = new UserGridPanel(new APIUser
{ {

View File

@ -60,6 +60,7 @@ namespace osu.Game.Online.API
public IBindable<APIUser> LocalUser => localUser; public IBindable<APIUser> LocalUser => localUser;
public IBindableList<APIRelation> Friends => friends; public IBindableList<APIRelation> Friends => friends;
public Bindable<UserStatus> Status { get; } = new Bindable<UserStatus>(UserStatus.Online);
public IBindable<UserActivity> Activity => activity; public IBindable<UserActivity> Activity => activity;
public INotificationsClient NotificationsClient { get; } public INotificationsClient NotificationsClient { get; }
@ -73,7 +74,6 @@ namespace osu.Game.Online.API
private Bindable<UserActivity> activity { get; } = new Bindable<UserActivity>(); private Bindable<UserActivity> activity { get; } = new Bindable<UserActivity>();
private Bindable<UserStatus?> configStatus { get; } = new Bindable<UserStatus?>(); private Bindable<UserStatus?> configStatus { get; } = new Bindable<UserStatus?>();
private Bindable<UserStatus?> localUserStatus { get; } = new Bindable<UserStatus?>();
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password)); protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
@ -121,17 +121,6 @@ namespace osu.Game.Online.API
state.Value = APIState.Connecting; state.Value = APIState.Connecting;
} }
localUser.BindValueChanged(u =>
{
u.OldValue?.Activity.UnbindFrom(activity);
u.NewValue.Activity.BindTo(activity);
u.OldValue?.Status.UnbindFrom(localUserStatus);
u.NewValue.Status.BindTo(localUserStatus);
}, true);
localUserStatus.BindTo(configStatus);
var thread = new Thread(run) var thread = new Thread(run)
{ {
Name = "APIAccess", Name = "APIAccess",
@ -342,9 +331,8 @@ namespace osu.Game.Online.API
{ {
Debug.Assert(ThreadSafety.IsUpdateThread); Debug.Assert(ThreadSafety.IsUpdateThread);
me.Status.Value = configStatus.Value ?? UserStatus.Online;
localUser.Value = me; localUser.Value = me;
Status.Value = configStatus.Value ?? UserStatus.Online;
state.Value = me.SessionVerified ? APIState.Online : APIState.RequiresSecondFactorAuth; state.Value = me.SessionVerified ? APIState.Online : APIState.RequiresSecondFactorAuth;
failureCount = 0; failureCount = 0;
@ -381,9 +369,10 @@ namespace osu.Game.Online.API
localUser.Value = new APIUser localUser.Value = new APIUser
{ {
Username = ProvidedUsername, Username = ProvidedUsername
Status = { Value = configStatus.Value ?? UserStatus.Online }
}; };
Status.Value = configStatus.Value ?? UserStatus.Online;
} }
public void Perform(APIRequest request) public void Perform(APIRequest request)

View File

@ -28,7 +28,9 @@ namespace osu.Game.Online.API
public BindableList<APIRelation> Friends { get; } = new BindableList<APIRelation>(); public BindableList<APIRelation> Friends { get; } = new BindableList<APIRelation>();
public Bindable<UserActivity> Activity { get; } = new Bindable<UserActivity>(); public Bindable<UserStatus> Status { get; } = new Bindable<UserStatus>(UserStatus.Online);
public Bindable<UserActivity?> Activity { get; } = new Bindable<UserActivity?>();
public DummyNotificationsClient NotificationsClient { get; } = new DummyNotificationsClient(); public DummyNotificationsClient NotificationsClient { get; } = new DummyNotificationsClient();
INotificationsClient IAPIProvider.NotificationsClient => NotificationsClient; INotificationsClient IAPIProvider.NotificationsClient => NotificationsClient;
@ -69,15 +71,6 @@ namespace osu.Game.Online.API
/// </summary> /// </summary>
public IBindable<APIState> State => state; public IBindable<APIState> State => state;
public DummyAPIAccess()
{
LocalUser.BindValueChanged(u =>
{
u.OldValue?.Activity.UnbindFrom(Activity);
u.NewValue.Activity.BindTo(Activity);
}, true);
}
public virtual void Queue(APIRequest request) public virtual void Queue(APIRequest request)
{ {
request.AttachAPI(this); request.AttachAPI(this);
@ -204,7 +197,7 @@ namespace osu.Game.Online.API
IBindable<APIUser> IAPIProvider.LocalUser => LocalUser; IBindable<APIUser> IAPIProvider.LocalUser => LocalUser;
IBindableList<APIRelation> IAPIProvider.Friends => Friends; IBindableList<APIRelation> IAPIProvider.Friends => Friends;
IBindable<UserActivity> IAPIProvider.Activity => Activity; IBindable<UserActivity?> IAPIProvider.Activity => Activity;
/// <summary> /// <summary>
/// Skip 2FA requirement for next login. /// Skip 2FA requirement for next login.

View File

@ -24,10 +24,15 @@ namespace osu.Game.Online.API
/// </summary> /// </summary>
IBindableList<APIRelation> Friends { get; } IBindableList<APIRelation> Friends { get; }
/// <summary>
/// The current user's status.
/// </summary>
Bindable<UserStatus> Status { get; }
/// <summary> /// <summary>
/// The current user's activity. /// The current user's activity.
/// </summary> /// </summary>
IBindable<UserActivity> Activity { get; } IBindable<UserActivity?> Activity { get; }
/// <summary> /// <summary>
/// The language supplied by this provider to API requests. /// The language supplied by this provider to API requests.

View File

@ -8,7 +8,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.Extensions; using osu.Game.Extensions;
using osu.Game.Users; using osu.Game.Users;
@ -56,10 +55,6 @@ namespace osu.Game.Online.API.Requests.Responses
set => countryCodeString = value.ToString(); set => countryCodeString = value.ToString();
} }
public readonly Bindable<UserStatus?> Status = new Bindable<UserStatus?>();
public readonly Bindable<UserActivity> Activity = new Bindable<UserActivity>();
[JsonProperty(@"profile_colour")] [JsonProperty(@"profile_colour")]
public string Colour; public string Colour;

View File

@ -37,8 +37,9 @@ namespace osu.Game.Online.Metadata
private IHubClientConnector? connector; private IHubClientConnector? connector;
private Bindable<int> lastQueueId = null!; private Bindable<int> lastQueueId = null!;
private IBindable<APIUser> localUser = null!; private IBindable<APIUser> localUser = null!;
private IBindable<UserStatus> userStatus = null!;
private IBindable<UserActivity?> userActivity = null!; private IBindable<UserActivity?> userActivity = null!;
private IBindable<UserStatus?>? userStatus;
private HubConnection? connection => connector?.CurrentConnection; private HubConnection? connection => connector?.CurrentConnection;
@ -75,22 +76,20 @@ namespace osu.Game.Online.Metadata
lastQueueId = config.GetBindable<int>(OsuSetting.LastProcessedMetadataId); lastQueueId = config.GetBindable<int>(OsuSetting.LastProcessedMetadataId);
localUser = api.LocalUser.GetBoundCopy(); localUser = api.LocalUser.GetBoundCopy();
userStatus = api.Status.GetBoundCopy();
userActivity = api.Activity.GetBoundCopy()!; userActivity = api.Activity.GetBoundCopy()!;
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
localUser.BindValueChanged(_ =>
userStatus.BindValueChanged(status =>
{ {
if (localUser.Value is not GuestUser) if (localUser.Value is not GuestUser)
{ UpdateStatus(status.NewValue);
userStatus = localUser.Value.Status.GetBoundCopy();
userStatus.BindValueChanged(status => UpdateStatus(status.NewValue), true);
}
else
userStatus = null;
}, true); }, true);
userActivity.BindValueChanged(activity => userActivity.BindValueChanged(activity =>
{ {
if (localUser.Value is not GuestUser) if (localUser.Value is not GuestUser)
@ -117,7 +116,7 @@ namespace osu.Game.Online.Metadata
if (localUser.Value is not GuestUser) if (localUser.Value is not GuestUser)
{ {
UpdateActivity(userActivity.Value); UpdateActivity(userActivity.Value);
UpdateStatus(userStatus?.Value); UpdateStatus(userStatus.Value);
} }
if (lastQueueId.Value >= 0) if (lastQueueId.Value >= 0)

View File

@ -140,15 +140,11 @@ namespace osu.Game.Overlays.Dashboard
Schedule(() => Schedule(() =>
{ {
// explicitly refetch the user's status. userFlow.Add(userPanels[userId] = createUserPanel(user).With(p =>
// things may have changed in between the time of scheduling and the time of actual execution.
if (onlineUsers.TryGetValue(userId, out var updatedStatus))
{ {
user.Activity.Value = updatedStatus.Activity; p.Status.Value = onlineUsers.GetValueOrDefault(userId).Status;
user.Status.Value = updatedStatus.Status; p.Activity.Value = onlineUsers.GetValueOrDefault(userId).Activity;
} }));
userFlow.Add(userPanels[userId] = createUserPanel(user));
}); });
}); });
} }
@ -162,8 +158,8 @@ namespace osu.Game.Overlays.Dashboard
{ {
if (userPanels.TryGetValue(kvp.Key, out var panel)) if (userPanels.TryGetValue(kvp.Key, out var panel))
{ {
panel.User.Activity.Value = kvp.Value.Activity; panel.Activity.Value = kvp.Value.Activity;
panel.User.Status.Value = kvp.Value.Status; panel.Status.Value = kvp.Value.Status;
} }
} }
@ -223,6 +219,9 @@ namespace osu.Game.Overlays.Dashboard
{ {
public readonly APIUser User; public readonly APIUser User;
public readonly Bindable<UserStatus?> Status = new Bindable<UserStatus?>();
public readonly Bindable<UserActivity> Activity = new Bindable<UserActivity>();
public BindableBool CanSpectate { get; } = new BindableBool(); public BindableBool CanSpectate { get; } = new BindableBool();
public IEnumerable<LocalisableString> FilterTerms { get; } public IEnumerable<LocalisableString> FilterTerms { get; }
@ -271,8 +270,8 @@ namespace osu.Game.Overlays.Dashboard
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
// this is SHOCKING // this is SHOCKING
Activity = { BindTarget = User.Activity }, Activity = { BindTarget = Activity },
Status = { BindTarget = User.Status }, Status = { BindTarget = Status },
}, },
new PurpleRoundedButton new PurpleRoundedButton
{ {

View File

@ -15,7 +15,6 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation; using osu.Game.Localisation;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings;
using osu.Game.Users; using osu.Game.Users;
using osuTK; using osuTK;
@ -38,9 +37,7 @@ namespace osu.Game.Overlays.Login
/// </summary> /// </summary>
public Action? RequestHide; public Action? RequestHide;
private IBindable<APIUser> user = null!; private readonly Bindable<UserStatus> status = new Bindable<UserStatus>();
private readonly Bindable<UserStatus?> status = new Bindable<UserStatus?>();
private readonly IBindable<APIState> apiState = new Bindable<APIState>(); private readonly IBindable<APIState> apiState = new Bindable<APIState>();
[Resolved] [Resolved]
@ -71,13 +68,7 @@ namespace osu.Game.Overlays.Login
apiState.BindTo(api.State); apiState.BindTo(api.State);
apiState.BindValueChanged(onlineStateChanged, true); apiState.BindValueChanged(onlineStateChanged, true);
user = api.LocalUser.GetBoundCopy(); status.BindTo(api.Status);
user.BindValueChanged(u =>
{
status.UnbindBindings();
status.BindTo(u.NewValue.Status);
}, true);
status.BindValueChanged(e => updateDropdownCurrent(e.NewValue), true); status.BindValueChanged(e => updateDropdownCurrent(e.NewValue), true);
} }
@ -163,17 +154,17 @@ namespace osu.Game.Overlays.Login
switch (action.NewValue) switch (action.NewValue)
{ {
case UserAction.Online: case UserAction.Online:
api.LocalUser.Value.Status.Value = UserStatus.Online; status.Value = UserStatus.Online;
dropdown.StatusColour = colours.Green; dropdown.StatusColour = colours.Green;
break; break;
case UserAction.DoNotDisturb: case UserAction.DoNotDisturb:
api.LocalUser.Value.Status.Value = UserStatus.DoNotDisturb; status.Value = UserStatus.DoNotDisturb;
dropdown.StatusColour = colours.Red; dropdown.StatusColour = colours.Red;
break; break;
case UserAction.AppearOffline: case UserAction.AppearOffline:
api.LocalUser.Value.Status.Value = UserStatus.Offline; status.Value = UserStatus.Offline;
dropdown.StatusColour = colours.Gray7; dropdown.StatusColour = colours.Gray7;
break; break;