1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-10 20:57: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 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> offlineAlertQueue = new HashSet<APIUser>();
@ -63,8 +63,8 @@ namespace osu.Game.Online
friends.BindTo(api.Friends);
friends.BindCollectionChanged(onFriendsChanged, true);
friendStates.BindTo(metadataClient.FriendStates);
friendStates.BindCollectionChanged(onFriendStatesChanged, true);
friendPresences.BindTo(metadataClient.FriendPresences);
friendPresences.BindCollectionChanged(onFriendPresenceChanged, true);
}
protected override void Update()
@ -85,7 +85,7 @@ namespace osu.Game.Online
if (friend.TargetUser is not APIUser user)
continue;
if (friendStates.TryGetValue(friend.TargetID, out _))
if (friendPresences.TryGetValue(friend.TargetID, out _))
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)
{

View File

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

View File

@ -23,14 +23,14 @@ namespace osu.Game.Online.Metadata
public override IBindable<bool> IsWatchingUserPresence => isWatchingUserPresence;
private readonly BindableBool isWatchingUserPresence = new BindableBool();
public override UserPresence LocalUserState => localUserState;
private UserPresence localUserState;
public override UserPresence LocalUserPresence => localUserPresence;
private UserPresence localUserPresence;
public override IBindableDictionary<int, UserPresence> UserStates => userStates;
private readonly BindableDictionary<int, UserPresence> userStates = new BindableDictionary<int, UserPresence>();
public override IBindableDictionary<int, UserPresence> UserPresences => userPresences;
private readonly BindableDictionary<int, UserPresence> userPresences = new BindableDictionary<int, UserPresence>();
public override IBindableDictionary<int, UserPresence> FriendStates => friendStates;
private readonly BindableDictionary<int, UserPresence> friendStates = new BindableDictionary<int, UserPresence>();
public override IBindableDictionary<int, UserPresence> FriendPresences => friendPresences;
private readonly BindableDictionary<int, UserPresence> friendPresences = new BindableDictionary<int, UserPresence>();
public override IBindable<DailyChallengeInfo?> DailyChallengeInfo => dailyChallengeInfo;
private readonly Bindable<DailyChallengeInfo?> dailyChallengeInfo = new Bindable<DailyChallengeInfo?>();
@ -110,10 +110,10 @@ namespace osu.Game.Online.Metadata
Schedule(() =>
{
isWatchingUserPresence.Value = false;
userStates.Clear();
friendStates.Clear();
userPresences.Clear();
friendPresences.Clear();
dailyChallengeInfo.Value = null;
localUserState = default;
localUserPresence = default;
});
return;
}
@ -208,16 +208,16 @@ namespace osu.Game.Online.Metadata
if (presence?.Status != null)
{
if (userId == api.LocalUser.Value.OnlineID)
localUserState = presence.Value;
localUserPresence = presence.Value;
else
userStates[userId] = presence.Value;
userPresences[userId] = presence.Value;
}
else
{
if (userId == api.LocalUser.Value.OnlineID)
localUserState = default;
localUserPresence = default;
else
userStates.Remove(userId);
userPresences.Remove(userId);
}
});
@ -229,9 +229,9 @@ namespace osu.Game.Online.Metadata
Schedule(() =>
{
if (presence?.Status != null)
friendStates[userId] = presence.Value;
friendPresences[userId] = presence.Value;
else
friendStates.Remove(userId);
friendPresences.Remove(userId);
});
return Task.CompletedTask;
@ -256,7 +256,7 @@ namespace osu.Game.Online.Metadata
throw new OperationCanceledException();
// must be scheduled before any remote calls to avoid mis-ordering.
Schedule(() => userStates.Clear());
Schedule(() => userPresences.Clear());
Debug.Assert(connection != null);
await connection.InvokeAsync(nameof(IMetadataServer.EndWatchingUserPresence)).ConfigureAwait(false);
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 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 SearchContainer<OnlineUserPanel> userFlow = null!;
@ -104,8 +104,8 @@ namespace osu.Game.Overlays.Dashboard
{
base.LoadComplete();
onlineUsers.BindTo(metadataClient.UserStates);
onlineUsers.BindCollectionChanged(onUserUpdated, true);
onlineUserPresences.BindTo(metadataClient.UserPresences);
onlineUserPresences.BindCollectionChanged(onUserPresenceUpdated, true);
playingUsers.BindTo(spectatorClient.PlayingUsers);
playingUsers.BindCollectionChanged(onPlayingUsersChanged, true);
@ -118,7 +118,7 @@ namespace osu.Game.Overlays.Dashboard
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)
{

View File

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

View File

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