1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-11 00:17:19 +08:00

Merge branch 'remove-status-from-apiuser' into user-panel-status

This commit is contained in:
Dean Herbert 2025-01-17 17:32:39 +09:00
commit 66a72bffa8
No known key found for this signature in database
6 changed files with 51 additions and 53 deletions

View File

@ -46,7 +46,7 @@ namespace osu.Game.Online
private readonly Bindable<bool> notifyOnFriendPresenceChange = new BindableBool(); private readonly Bindable<bool> notifyOnFriendPresenceChange = new BindableBool();
private readonly IBindableList<APIRelation> friends = new BindableList<APIRelation>(); private readonly IBindableList<APIRelation> friends = new BindableList<APIRelation>();
private readonly IBindableDictionary<int, UserPresence> friendStates = new BindableDictionary<int, UserPresence>(); private readonly IBindableDictionary<int, UserPresence> friendPresences = new BindableDictionary<int, UserPresence>();
private readonly HashSet<APIUser> onlineAlertQueue = new HashSet<APIUser>(); private readonly HashSet<APIUser> onlineAlertQueue = new HashSet<APIUser>();
private readonly HashSet<APIUser> offlineAlertQueue = new HashSet<APIUser>(); private readonly HashSet<APIUser> offlineAlertQueue = new HashSet<APIUser>();
@ -63,8 +63,8 @@ namespace osu.Game.Online
friends.BindTo(api.Friends); friends.BindTo(api.Friends);
friends.BindCollectionChanged(onFriendsChanged, true); friends.BindCollectionChanged(onFriendsChanged, true);
friendStates.BindTo(metadataClient.FriendStates); friendPresences.BindTo(metadataClient.FriendPresences);
friendStates.BindCollectionChanged(onFriendStatesChanged, true); friendPresences.BindCollectionChanged(onFriendPresenceChanged, true);
} }
protected override void Update() protected override void Update()
@ -85,7 +85,7 @@ namespace osu.Game.Online
if (friend.TargetUser is not APIUser user) if (friend.TargetUser is not APIUser user)
continue; continue;
if (friendStates.TryGetValue(friend.TargetID, out _)) if (friendPresences.TryGetValue(friend.TargetID, out _))
markUserOnline(user); markUserOnline(user);
} }
@ -105,7 +105,7 @@ namespace osu.Game.Online
} }
} }
private void onFriendStatesChanged(object? sender, NotifyDictionaryChangedEventArgs<int, UserPresence> e) private void onFriendPresenceChanged(object? sender, NotifyDictionaryChangedEventArgs<int, UserPresence> e)
{ {
switch (e.Action) switch (e.Action)
{ {

View File

@ -45,17 +45,17 @@ namespace osu.Game.Online.Metadata
/// <summary> /// <summary>
/// The <see cref="UserPresence"/> information about the current user. /// The <see cref="UserPresence"/> information about the current user.
/// </summary> /// </summary>
public abstract UserPresence LocalUserState { get; } public abstract UserPresence LocalUserPresence { get; }
/// <summary> /// <summary>
/// Dictionary keyed by user ID containing all of the <see cref="UserPresence"/> information about currently online users received from the server. /// Dictionary keyed by user ID containing all of the <see cref="UserPresence"/> information about currently online users received from the server.
/// </summary> /// </summary>
public abstract IBindableDictionary<int, UserPresence> UserStates { get; } public abstract IBindableDictionary<int, UserPresence> UserPresences { get; }
/// <summary> /// <summary>
/// Dictionary keyed by user ID containing all of the <see cref="UserPresence"/> information about currently online friends received from the server. /// Dictionary keyed by user ID containing all of the <see cref="UserPresence"/> information about currently online friends received from the server.
/// </summary> /// </summary>
public abstract IBindableDictionary<int, UserPresence> FriendStates { get; } public abstract IBindableDictionary<int, UserPresence> FriendPresences { get; }
/// <summary> /// <summary>
/// Attempts to retrieve the presence of a user. /// Attempts to retrieve the presence of a user.
@ -65,12 +65,12 @@ namespace osu.Game.Online.Metadata
public UserPresence? GetPresence(int userId) public UserPresence? GetPresence(int userId)
{ {
if (userId == api.LocalUser.Value.OnlineID) if (userId == api.LocalUser.Value.OnlineID)
return LocalUserState; return LocalUserPresence;
if (FriendStates.TryGetValue(userId, out UserPresence presence)) if (FriendPresences.TryGetValue(userId, out UserPresence presence))
return presence; return presence;
if (UserStates.TryGetValue(userId, out presence)) if (UserPresences.TryGetValue(userId, out presence))
return presence; return presence;
return null; return null;

View File

@ -23,14 +23,14 @@ namespace osu.Game.Online.Metadata
public override IBindable<bool> IsWatchingUserPresence => isWatchingUserPresence; public override IBindable<bool> IsWatchingUserPresence => isWatchingUserPresence;
private readonly BindableBool isWatchingUserPresence = new BindableBool(); private readonly BindableBool isWatchingUserPresence = new BindableBool();
public override UserPresence LocalUserState => localUserState; public override UserPresence LocalUserPresence => localUserPresence;
private UserPresence localUserState; private UserPresence localUserPresence;
public override IBindableDictionary<int, UserPresence> UserStates => userStates; public override IBindableDictionary<int, UserPresence> UserPresences => userPresences;
private readonly BindableDictionary<int, UserPresence> userStates = new BindableDictionary<int, UserPresence>(); private readonly BindableDictionary<int, UserPresence> userPresences = new BindableDictionary<int, UserPresence>();
public override IBindableDictionary<int, UserPresence> FriendStates => friendStates; public override IBindableDictionary<int, UserPresence> FriendPresences => friendPresences;
private readonly BindableDictionary<int, UserPresence> friendStates = new BindableDictionary<int, UserPresence>(); private readonly BindableDictionary<int, UserPresence> friendPresences = new BindableDictionary<int, UserPresence>();
public override IBindable<DailyChallengeInfo?> DailyChallengeInfo => dailyChallengeInfo; public override IBindable<DailyChallengeInfo?> DailyChallengeInfo => dailyChallengeInfo;
private readonly Bindable<DailyChallengeInfo?> dailyChallengeInfo = new Bindable<DailyChallengeInfo?>(); private readonly Bindable<DailyChallengeInfo?> dailyChallengeInfo = new Bindable<DailyChallengeInfo?>();
@ -110,10 +110,10 @@ namespace osu.Game.Online.Metadata
Schedule(() => Schedule(() =>
{ {
isWatchingUserPresence.Value = false; isWatchingUserPresence.Value = false;
userStates.Clear(); userPresences.Clear();
friendStates.Clear(); friendPresences.Clear();
dailyChallengeInfo.Value = null; dailyChallengeInfo.Value = null;
localUserState = default; localUserPresence = default;
}); });
return; return;
} }
@ -208,16 +208,16 @@ namespace osu.Game.Online.Metadata
if (presence?.Status != null) if (presence?.Status != null)
{ {
if (userId == api.LocalUser.Value.OnlineID) if (userId == api.LocalUser.Value.OnlineID)
localUserState = presence.Value; localUserPresence = presence.Value;
else else
userStates[userId] = presence.Value; userPresences[userId] = presence.Value;
} }
else else
{ {
if (userId == api.LocalUser.Value.OnlineID) if (userId == api.LocalUser.Value.OnlineID)
localUserState = default; localUserPresence = default;
else else
userStates.Remove(userId); userPresences.Remove(userId);
} }
}); });
@ -229,9 +229,9 @@ namespace osu.Game.Online.Metadata
Schedule(() => Schedule(() =>
{ {
if (presence?.Status != null) if (presence?.Status != null)
friendStates[userId] = presence.Value; friendPresences[userId] = presence.Value;
else else
friendStates.Remove(userId); friendPresences.Remove(userId);
}); });
return Task.CompletedTask; return Task.CompletedTask;
@ -256,7 +256,7 @@ namespace osu.Game.Online.Metadata
throw new OperationCanceledException(); throw new OperationCanceledException();
// must be scheduled before any remote calls to avoid mis-ordering. // must be scheduled before any remote calls to avoid mis-ordering.
Schedule(() => userStates.Clear()); Schedule(() => userPresences.Clear());
Debug.Assert(connection != null); Debug.Assert(connection != null);
await connection.InvokeAsync(nameof(IMetadataServer.EndWatchingUserPresence)).ConfigureAwait(false); await connection.InvokeAsync(nameof(IMetadataServer.EndWatchingUserPresence)).ConfigureAwait(false);
Logger.Log($@"{nameof(OnlineMetadataClient)} stopped watching user presence", LoggingTarget.Network); Logger.Log($@"{nameof(OnlineMetadataClient)} stopped watching user presence", LoggingTarget.Network);

View File

@ -35,7 +35,7 @@ namespace osu.Game.Overlays.Dashboard
private const float padding = 10; private const float padding = 10;
private readonly IBindableList<int> playingUsers = new BindableList<int>(); private readonly IBindableList<int> playingUsers = new BindableList<int>();
private readonly IBindableDictionary<int, UserPresence> onlineUsers = new BindableDictionary<int, UserPresence>(); private readonly IBindableDictionary<int, UserPresence> onlineUserPresences = new BindableDictionary<int, UserPresence>();
private readonly Dictionary<int, OnlineUserPanel> userPanels = new Dictionary<int, OnlineUserPanel>(); private readonly Dictionary<int, OnlineUserPanel> userPanels = new Dictionary<int, OnlineUserPanel>();
private SearchContainer<OnlineUserPanel> userFlow = null!; private SearchContainer<OnlineUserPanel> userFlow = null!;
@ -104,8 +104,8 @@ namespace osu.Game.Overlays.Dashboard
{ {
base.LoadComplete(); base.LoadComplete();
onlineUsers.BindTo(metadataClient.UserStates); onlineUserPresences.BindTo(metadataClient.UserPresences);
onlineUsers.BindCollectionChanged(onUserUpdated, true); onlineUserPresences.BindCollectionChanged(onUserPresenceUpdated, true);
playingUsers.BindTo(spectatorClient.PlayingUsers); playingUsers.BindTo(spectatorClient.PlayingUsers);
playingUsers.BindCollectionChanged(onPlayingUsersChanged, true); playingUsers.BindCollectionChanged(onPlayingUsersChanged, true);
@ -118,7 +118,7 @@ namespace osu.Game.Overlays.Dashboard
searchTextBox.TakeFocus(); searchTextBox.TakeFocus();
} }
private void onUserUpdated(object? sender, NotifyDictionaryChangedEventArgs<int, UserPresence> e) => Schedule(() => private void onUserPresenceUpdated(object? sender, NotifyDictionaryChangedEventArgs<int, UserPresence> e) => Schedule(() =>
{ {
switch (e.Action) switch (e.Action)
{ {

View File

@ -19,14 +19,14 @@ namespace osu.Game.Tests.Visual.Metadata
public override IBindable<bool> IsWatchingUserPresence => isWatchingUserPresence; public override IBindable<bool> IsWatchingUserPresence => isWatchingUserPresence;
private readonly BindableBool isWatchingUserPresence = new BindableBool(); private readonly BindableBool isWatchingUserPresence = new BindableBool();
public override UserPresence LocalUserState => localUserState; public override UserPresence LocalUserPresence => localUserPresence;
private UserPresence localUserState; private UserPresence localUserPresence;
public override IBindableDictionary<int, UserPresence> UserStates => userStates; public override IBindableDictionary<int, UserPresence> UserPresences => userPresences;
private readonly BindableDictionary<int, UserPresence> userStates = new BindableDictionary<int, UserPresence>(); private readonly BindableDictionary<int, UserPresence> userPresences = new BindableDictionary<int, UserPresence>();
public override IBindableDictionary<int, UserPresence> FriendStates => friendStates; public override IBindableDictionary<int, UserPresence> FriendPresences => friendPresences;
private readonly BindableDictionary<int, UserPresence> friendStates = new BindableDictionary<int, UserPresence>(); private readonly BindableDictionary<int, UserPresence> friendPresences = new BindableDictionary<int, UserPresence>();
public override Bindable<DailyChallengeInfo?> DailyChallengeInfo => dailyChallengeInfo; public override Bindable<DailyChallengeInfo?> DailyChallengeInfo => dailyChallengeInfo;
private readonly Bindable<DailyChallengeInfo?> dailyChallengeInfo = new Bindable<DailyChallengeInfo?>(); private readonly Bindable<DailyChallengeInfo?> dailyChallengeInfo = new Bindable<DailyChallengeInfo?>();
@ -48,11 +48,12 @@ namespace osu.Game.Tests.Visual.Metadata
public override Task UpdateActivity(UserActivity? activity) public override Task UpdateActivity(UserActivity? activity)
{ {
localUserPresence = localUserPresence with { Activity = activity };
if (isWatchingUserPresence.Value) if (isWatchingUserPresence.Value)
{ {
userStates.TryGetValue(api.LocalUser.Value.Id, out var localUserPresence); if (userPresences.ContainsKey(api.LocalUser.Value.Id))
localUserPresence = localUserPresence with { Activity = activity }; userPresences[api.LocalUser.Value.Id] = localUserPresence;
userStates[api.LocalUser.Value.Id] = localUserPresence;
} }
return Task.CompletedTask; return Task.CompletedTask;
@ -60,11 +61,12 @@ namespace osu.Game.Tests.Visual.Metadata
public override Task UpdateStatus(UserStatus? status) public override Task UpdateStatus(UserStatus? status)
{ {
localUserPresence = localUserPresence with { Status = status };
if (isWatchingUserPresence.Value) if (isWatchingUserPresence.Value)
{ {
userStates.TryGetValue(api.LocalUser.Value.Id, out var localUserPresence); if (userPresences.ContainsKey(api.LocalUser.Value.Id))
localUserPresence = localUserPresence with { Status = status }; userPresences[api.LocalUser.Value.Id] = localUserPresence;
userStates[api.LocalUser.Value.Id] = localUserPresence;
} }
return Task.CompletedTask; return Task.CompletedTask;
@ -77,16 +79,16 @@ namespace osu.Game.Tests.Visual.Metadata
if (presence?.Status != null) if (presence?.Status != null)
{ {
if (userId == api.LocalUser.Value.OnlineID) if (userId == api.LocalUser.Value.OnlineID)
localUserState = presence.Value; localUserPresence = presence.Value;
else else
userStates[userId] = presence.Value; userPresences[userId] = presence.Value;
} }
else else
{ {
if (userId == api.LocalUser.Value.OnlineID) if (userId == api.LocalUser.Value.OnlineID)
localUserState = default; localUserPresence = default;
else else
userStates.Remove(userId); userPresences.Remove(userId);
} }
} }
@ -96,9 +98,9 @@ namespace osu.Game.Tests.Visual.Metadata
public override Task FriendPresenceUpdated(int userId, UserPresence? presence) public override Task FriendPresenceUpdated(int userId, UserPresence? presence)
{ {
if (presence.HasValue) if (presence.HasValue)
friendStates[userId] = presence.Value; friendPresences[userId] = presence.Value;
else else
friendStates.Remove(userId); friendPresences.Remove(userId);
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -12,7 +12,6 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Users.Drawables; using osu.Game.Users.Drawables;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Metadata; using osu.Game.Online.Metadata;
@ -28,9 +27,6 @@ namespace osu.Game.Users
[Resolved] [Resolved]
private MetadataClient? metadata { get; set; } private MetadataClient? metadata { get; set; }
[Resolved]
private IAPIProvider? api { get; set; }
private UserStatus? lastStatus; private UserStatus? lastStatus;
private UserActivity? lastActivity; private UserActivity? lastActivity;
private DateTimeOffset? lastVisit; private DateTimeOffset? lastVisit;