1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-07 20:12:54 +08:00

Display up-to-date online status in user panels

This commit is contained in:
Dan Balasescu 2025-01-15 16:53:55 +09:00
parent b7a9b77efe
commit 8985a38734
No known key found for this signature in database
4 changed files with 202 additions and 199 deletions

View File

@ -4,17 +4,18 @@
using System; using System;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Utils; using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Metadata;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Tests.Beatmaps; using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Visual.Metadata;
using osu.Game.Users; using osu.Game.Users;
using osuTK; using osuTK;
@ -23,144 +24,138 @@ namespace osu.Game.Tests.Visual.Online
[TestFixture] [TestFixture]
public partial class TestSceneUserPanel : OsuTestScene public partial class TestSceneUserPanel : OsuTestScene
{ {
private readonly Bindable<UserActivity?> activity = new Bindable<UserActivity?>();
private readonly Bindable<UserStatus?> status = new Bindable<UserStatus?>();
private UserGridPanel boundPanel1 = null!;
private TestUserListPanel boundPanel2 = null!;
[Cached] [Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple);
[Cached(typeof(LocalUserStatisticsProvider))]
private readonly TestUserStatisticsProvider statisticsProvider = new TestUserStatisticsProvider();
[Resolved] [Resolved]
private IRulesetStore rulesetStore { get; set; } = null!; private IRulesetStore rulesetStore { get; set; } = null!;
private TestUserStatisticsProvider statisticsProvider = null!;
private TestMetadataClient metadataClient = null!;
private TestUserListPanel panel = null!;
[SetUp] [SetUp]
public void SetUp() => Schedule(() => public void SetUp() => Schedule(() =>
{ {
activity.Value = null; Child = new DependencyProvidingContainer
status.Value = null;
Remove(statisticsProvider, false);
Clear();
Add(statisticsProvider);
Add(new FillFlowContainer
{ {
Anchor = Anchor.Centre, RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre, CachedDependencies =
AutoSizeAxes = Axes.Y, [
RelativeSizeAxes = Axes.X, (typeof(LocalUserStatisticsProvider), statisticsProvider = new TestUserStatisticsProvider()),
Spacing = new Vector2(10f), (typeof(MetadataClient), metadataClient = new TestMetadataClient())
],
Children = new Drawable[] Children = new Drawable[]
{ {
new UserBrickPanel(new APIUser statisticsProvider,
metadataClient,
new FillFlowContainer
{ {
Username = @"flyte", Anchor = Anchor.Centre,
Id = 3103765, Origin = Anchor.Centre,
CoverUrl = @"https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg", AutoSizeAxes = Axes.Y,
}), RelativeSizeAxes = Axes.X,
new UserBrickPanel(new APIUser Spacing = new Vector2(10f),
{ Children = new Drawable[]
Username = @"peppy", {
Id = 2, new UserBrickPanel(new APIUser
Colour = "99EB47", {
CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg", Username = @"flyte",
}), Id = 3103765,
new UserGridPanel(new APIUser CoverUrl = @"https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg",
{ }),
Username = @"flyte", new UserBrickPanel(new APIUser
Id = 3103765, {
CountryCode = CountryCode.JP, Username = @"peppy",
CoverUrl = @"https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg", Id = 2,
IsOnline = true Colour = "99EB47",
}) { Width = 300 }, CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg",
boundPanel1 = new UserGridPanel(new APIUser }),
{ new UserGridPanel(new APIUser
Username = @"peppy", {
Id = 2, Username = @"flyte",
CountryCode = CountryCode.AU, Id = 3103765,
CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg", CountryCode = CountryCode.JP,
IsSupporter = true, CoverUrl = @"https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg",
SupportLevel = 3, IsOnline = true
}) { Width = 300 }, }) { Width = 300 },
boundPanel2 = new TestUserListPanel(new APIUser new UserGridPanel(new APIUser
{ {
Username = @"Evast", Username = @"peppy",
Id = 8195163, Id = 2,
CountryCode = CountryCode.BY, CountryCode = CountryCode.AU,
CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg", CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg",
IsOnline = false, IsSupporter = true,
LastVisit = DateTimeOffset.Now SupportLevel = 3,
}), }) { Width = 300 },
new UserRankPanel(new APIUser panel = new TestUserListPanel(new APIUser
{ {
Username = @"flyte", Username = @"peppy",
Id = 3103765, Id = 2,
CountryCode = CountryCode.JP, CountryCode = CountryCode.AU,
CoverUrl = @"https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg", CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg",
Statistics = new UserStatistics { GlobalRank = 12345, CountryRank = 1234 } LastVisit = DateTimeOffset.Now
}) { Width = 300 }, }),
new UserRankPanel(new APIUser new UserRankPanel(new APIUser
{ {
Username = @"peppy", Username = @"flyte",
Id = 2, Id = 3103765,
Colour = "99EB47", CountryCode = CountryCode.JP,
CountryCode = CountryCode.AU, CoverUrl = @"https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg",
CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg", Statistics = new UserStatistics { GlobalRank = 12345, CountryRank = 1234 }
Statistics = new UserStatistics { GlobalRank = null, CountryRank = null } }) { Width = 300 },
}) { Width = 300 } new UserRankPanel(new APIUser
{
Username = @"peppy",
Id = 2,
Colour = "99EB47",
CountryCode = CountryCode.AU,
CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg",
Statistics = new UserStatistics { GlobalRank = null, CountryRank = null }
}) { Width = 300 }
}
}
} }
}); };
boundPanel1.Status.BindTo(status); metadataClient.BeginWatchingUserPresence();
boundPanel1.Activity.BindTo(activity);
boundPanel2.Status.BindTo(status);
boundPanel2.Activity.BindTo(activity);
}); });
[Test] [Test]
public void TestUserStatus() public void TestUserStatus()
{ {
AddStep("online", () => status.Value = UserStatus.Online); AddStep("online", () => setPresence(UserStatus.Online, null));
AddStep("do not disturb", () => status.Value = UserStatus.DoNotDisturb); AddStep("do not disturb", () => setPresence(UserStatus.DoNotDisturb, null));
AddStep("offline", () => status.Value = UserStatus.Offline); AddStep("offline", () => setPresence(UserStatus.Offline, null));
AddStep("null status", () => status.Value = null);
} }
[Test] [Test]
public void TestUserActivity() public void TestUserActivity()
{ {
AddStep("set online status", () => status.Value = UserStatus.Online); AddStep("idle", () => setPresence(UserStatus.Online, null));
AddStep("watching replay", () => setPresence(UserStatus.Online, new UserActivity.WatchingReplay(createScore(@"nats"))));
AddStep("idle", () => activity.Value = null); AddStep("spectating user", () => setPresence(UserStatus.Online, new UserActivity.SpectatingUser(createScore(@"mrekk"))));
AddStep("watching replay", () => activity.Value = new UserActivity.WatchingReplay(createScore(@"nats"))); AddStep("solo (osu!)", () => setPresence(UserStatus.Online, soloGameStatusForRuleset(0)));
AddStep("spectating user", () => activity.Value = new UserActivity.SpectatingUser(createScore(@"mrekk"))); AddStep("solo (osu!taiko)", () => setPresence(UserStatus.Online, soloGameStatusForRuleset(1)));
AddStep("solo (osu!)", () => activity.Value = soloGameStatusForRuleset(0)); AddStep("solo (osu!catch)", () => setPresence(UserStatus.Online, soloGameStatusForRuleset(2)));
AddStep("solo (osu!taiko)", () => activity.Value = soloGameStatusForRuleset(1)); AddStep("solo (osu!mania)", () => setPresence(UserStatus.Online, soloGameStatusForRuleset(3)));
AddStep("solo (osu!catch)", () => activity.Value = soloGameStatusForRuleset(2)); AddStep("choosing", () => setPresence(UserStatus.Online, new UserActivity.ChoosingBeatmap()));
AddStep("solo (osu!mania)", () => activity.Value = soloGameStatusForRuleset(3)); AddStep("editing beatmap", () => setPresence(UserStatus.Online, new UserActivity.EditingBeatmap(new BeatmapInfo())));
AddStep("choosing", () => activity.Value = new UserActivity.ChoosingBeatmap()); AddStep("modding beatmap", () => setPresence(UserStatus.Online, new UserActivity.ModdingBeatmap(new BeatmapInfo())));
AddStep("editing beatmap", () => activity.Value = new UserActivity.EditingBeatmap(new BeatmapInfo())); AddStep("testing beatmap", () => setPresence(UserStatus.Online, new UserActivity.TestingBeatmap(new BeatmapInfo())));
AddStep("modding beatmap", () => activity.Value = new UserActivity.ModdingBeatmap(new BeatmapInfo()));
AddStep("testing beatmap", () => activity.Value = new UserActivity.TestingBeatmap(new BeatmapInfo()));
} }
[Test] [Test]
public void TestUserActivityChange() public void TestUserActivityChange()
{ {
AddAssert("visit message is visible", () => boundPanel2.LastVisitMessage.IsPresent); AddAssert("visit message is visible", () => panel.LastVisitMessage.IsPresent);
AddStep("set online status", () => status.Value = UserStatus.Online); AddStep("set online status", () => setPresence(UserStatus.Online, null));
AddAssert("visit message is not visible", () => !boundPanel2.LastVisitMessage.IsPresent); AddAssert("visit message is not visible", () => !panel.LastVisitMessage.IsPresent);
AddStep("set choosing activity", () => activity.Value = new UserActivity.ChoosingBeatmap()); AddStep("set choosing activity", () => setPresence(UserStatus.Online, new UserActivity.ChoosingBeatmap()));
AddStep("set offline status", () => status.Value = UserStatus.Offline); AddStep("set offline status", () => setPresence(UserStatus.Offline, null));
AddAssert("visit message is visible", () => boundPanel2.LastVisitMessage.IsPresent); AddAssert("visit message is visible", () => panel.LastVisitMessage.IsPresent);
AddStep("set online status", () => status.Value = UserStatus.Online); AddStep("set online status", () => setPresence(UserStatus.Online, null));
AddAssert("visit message is not visible", () => !boundPanel2.LastVisitMessage.IsPresent); AddAssert("visit message is not visible", () => !panel.LastVisitMessage.IsPresent);
} }
[Test] [Test]
@ -185,6 +180,14 @@ namespace osu.Game.Tests.Visual.Online
AddStep("set statistics to empty", () => statisticsProvider.UpdateStatistics(new UserStatistics(), Ruleset.Value)); AddStep("set statistics to empty", () => statisticsProvider.UpdateStatistics(new UserStatistics(), Ruleset.Value));
} }
private void setPresence(UserStatus status, UserActivity? activity)
{
if (status == UserStatus.Offline)
metadataClient.UserPresenceUpdated(panel.User.OnlineID, null);
else
metadataClient.UserPresenceUpdated(panel.User.OnlineID, new UserPresence { Status = status, Activity = activity });
}
private UserActivity soloGameStatusForRuleset(int rulesetId) => new UserActivity.InSoloGame(new BeatmapInfo(), rulesetStore.GetRuleset(rulesetId)!); private UserActivity soloGameStatusForRuleset(int rulesetId) => new UserActivity.InSoloGame(new BeatmapInfo(), rulesetStore.GetRuleset(rulesetId)!);
private ScoreInfo createScore(string name) => new ScoreInfo(new TestBeatmap(Ruleset.Value).BeatmapInfo) private ScoreInfo createScore(string name) => new ScoreInfo(new TestBeatmap(Ruleset.Value).BeatmapInfo)

View File

@ -47,6 +47,22 @@ namespace osu.Game.Online.Metadata
/// </summary> /// </summary>
public abstract IBindableDictionary<int, UserPresence> FriendStates { get; } public abstract IBindableDictionary<int, UserPresence> FriendStates { get; }
/// <summary>
/// Attempts to retrieve the presence of a user.
/// </summary>
/// <param name="userId">The user ID.</param>
/// <returns>The user presence, or null if not available or the user's offline.</returns>
public UserPresence? GetPresence(int userId)
{
if (FriendStates.TryGetValue(userId, out UserPresence presence))
return presence;
if (UserStates.TryGetValue(userId, out presence))
return presence;
return null;
}
/// <inheritdoc/> /// <inheritdoc/>
public abstract Task UpdateActivity(UserActivity? activity); public abstract Task UpdateActivity(UserActivity? activity);

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Diagnostics; using System.Diagnostics;
@ -40,17 +38,20 @@ namespace osu.Game.Overlays.Dashboard
private readonly IBindableDictionary<int, UserPresence> onlineUsers = new BindableDictionary<int, UserPresence>(); private readonly IBindableDictionary<int, UserPresence> onlineUsers = 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; private SearchContainer<OnlineUserPanel> userFlow = null!;
private BasicSearchTextBox searchTextBox; private BasicSearchTextBox searchTextBox = null!;
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; } = null!;
[Resolved] [Resolved]
private SpectatorClient spectatorClient { get; set; } private SpectatorClient spectatorClient { get; set; } = null!;
[Resolved] [Resolved]
private MetadataClient metadataClient { get; set; } private MetadataClient metadataClient { get; set; } = null!;
[Resolved]
private UserLookupCache users { get; set; } = null!;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider colourProvider)
@ -99,9 +100,6 @@ namespace osu.Game.Overlays.Dashboard
searchTextBox.Current.ValueChanged += text => userFlow.SearchTerm = text.NewValue; searchTextBox.Current.ValueChanged += text => userFlow.SearchTerm = text.NewValue;
} }
[Resolved]
private UserLookupCache users { get; set; }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
@ -120,7 +118,7 @@ namespace osu.Game.Overlays.Dashboard
searchTextBox.TakeFocus(); searchTextBox.TakeFocus();
} }
private void onUserUpdated(object sender, NotifyDictionaryChangedEventArgs<int, UserPresence> e) => Schedule(() => private void onUserUpdated(object? sender, NotifyDictionaryChangedEventArgs<int, UserPresence> e) => Schedule(() =>
{ {
switch (e.Action) switch (e.Action)
{ {
@ -133,38 +131,13 @@ namespace osu.Game.Overlays.Dashboard
users.GetUserAsync(userId).ContinueWith(task => users.GetUserAsync(userId).ContinueWith(task =>
{ {
APIUser user = task.GetResultSafely(); if (task.GetResultSafely() is APIUser user)
Schedule(() => userFlow.Add(userPanels[userId] = createUserPanel(user)));
if (user == null)
return;
Schedule(() =>
{
userFlow.Add(userPanels[userId] = createUserPanel(user).With(p =>
{
p.Status.Value = onlineUsers.GetValueOrDefault(userId).Status;
p.Activity.Value = onlineUsers.GetValueOrDefault(userId).Activity;
}));
});
}); });
} }
break; break;
case NotifyDictionaryChangedAction.Replace:
Debug.Assert(e.NewItems != null);
foreach (var kvp in e.NewItems)
{
if (userPanels.TryGetValue(kvp.Key, out var panel))
{
panel.Activity.Value = kvp.Value.Activity;
panel.Status.Value = kvp.Value.Status;
}
}
break;
case NotifyDictionaryChangedAction.Remove: case NotifyDictionaryChangedAction.Remove:
Debug.Assert(e.OldItems != null); Debug.Assert(e.OldItems != null);
@ -179,7 +152,7 @@ namespace osu.Game.Overlays.Dashboard
} }
}); });
private void onPlayingUsersChanged(object sender, NotifyCollectionChangedEventArgs e) private void onPlayingUsersChanged(object? sender, NotifyCollectionChangedEventArgs e)
{ {
switch (e.Action) switch (e.Action)
{ {
@ -219,9 +192,6 @@ 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; }
@ -268,10 +238,7 @@ namespace osu.Game.Overlays.Dashboard
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre
// this is SHOCKING
Activity = { BindTarget = Activity },
Status = { BindTarget = Status },
}, },
new PurpleRoundedButton new PurpleRoundedButton
{ {

View File

@ -1,10 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
#nullable disable using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -14,44 +12,56 @@ 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;
namespace osu.Game.Users namespace osu.Game.Users
{ {
public abstract partial class ExtendedUserPanel : UserPanel public abstract partial class ExtendedUserPanel : UserPanel
{ {
public readonly Bindable<UserStatus?> Status = new Bindable<UserStatus?>(); protected TextFlowContainer LastVisitMessage { get; private set; } = null!;
public readonly IBindable<UserActivity> Activity = new Bindable<UserActivity>(); private StatusIcon statusIcon = null!;
private StatusText statusMessage = null!;
protected TextFlowContainer LastVisitMessage { get; private set; } [Resolved]
private MetadataClient? metadata { get; set; }
private StatusIcon statusIcon; [Resolved]
private StatusText statusMessage; private IAPIProvider? api { get; set; }
private UserStatus? lastStatus;
private UserActivity? lastActivity;
private DateTimeOffset? lastVisit;
protected ExtendedUserPanel(APIUser user) protected ExtendedUserPanel(APIUser user)
: base(user) : base(user)
{ {
lastVisit = user.LastVisit;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
BorderColour = ColourProvider?.Light1 ?? Colours.GreyVioletLighter; BorderColour = ColourProvider?.Light1 ?? Colours.GreyVioletLighter;
Status.ValueChanged += status => displayStatus(status.NewValue, Activity.Value);
Activity.ValueChanged += activity => displayStatus(Status.Value, activity.NewValue);
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Status.TriggerChange(); updatePresence();
// Colour should be applied immediately on first load. // Colour should be applied immediately on first load.
statusIcon.FinishTransforms(); statusIcon.FinishTransforms();
} }
protected override void Update()
{
base.Update();
updatePresence();
}
protected Container CreateStatusIcon() => statusIcon = new StatusIcon(); protected Container CreateStatusIcon() => statusIcon = new StatusIcon();
protected FillFlowContainer CreateStatusMessage(bool rightAlignedChildren) protected FillFlowContainer CreateStatusMessage(bool rightAlignedChildren)
@ -70,15 +80,6 @@ namespace osu.Game.Users
text.Origin = alignment; text.Origin = alignment;
text.AutoSizeAxes = Axes.Both; text.AutoSizeAxes = Axes.Both;
text.Alpha = 0; text.Alpha = 0;
if (User.LastVisit.HasValue)
{
text.AddText(@"Last seen ");
text.AddText(new DrawableDate(User.LastVisit.Value, italic: false)
{
Shadow = false
});
}
})); }));
statusContainer.Add(statusMessage = new StatusText statusContainer.Add(statusMessage = new StatusText
@ -91,37 +92,53 @@ namespace osu.Game.Users
return statusContainer; return statusContainer;
} }
private void displayStatus(UserStatus? status, UserActivity activity = null) private void updatePresence()
{ {
if (status != null) UserPresence? presence;
if (User.Equals(api?.LocalUser.Value))
presence = new UserPresence { Status = api.Status.Value, Activity = api.Activity.Value };
else
presence = metadata?.GetPresence(User.OnlineID);
UserStatus status = presence?.Status ?? UserStatus.Offline;
UserActivity? activity = presence?.Activity;
if (status == lastStatus && activity == lastActivity)
return;
if (status == UserStatus.Offline && lastVisit != null)
{ {
LastVisitMessage.FadeTo(status == UserStatus.Offline && User.LastVisit.HasValue ? 1 : 0); LastVisitMessage.FadeTo(1);
LastVisitMessage.Clear();
// Set status message based on activity (if we have one) and status is not offline LastVisitMessage.AddText(@"Last seen ");
if (activity != null && status != UserStatus.Offline) LastVisitMessage.AddText(new DrawableDate(lastVisit.Value, italic: false)
{ {
statusMessage.Text = activity.GetStatus(); Shadow = false
statusMessage.TooltipText = activity.GetDetails(); });
statusIcon.FadeColour(activity.GetAppropriateColour(Colours), 500, Easing.OutQuint); }
return; else
} LastVisitMessage.FadeTo(0);
// Otherwise use only status // Set status message based on activity (if we have one) and status is not offline
if (activity != null && status != UserStatus.Offline)
{
statusMessage.Text = activity.GetStatus();
statusMessage.TooltipText = activity.GetDetails() ?? string.Empty;
statusIcon.FadeColour(activity.GetAppropriateColour(Colours), 500, Easing.OutQuint);
}
// Otherwise use only status
else
{
statusMessage.Text = status.GetLocalisableDescription(); statusMessage.Text = status.GetLocalisableDescription();
statusMessage.TooltipText = string.Empty; statusMessage.TooltipText = string.Empty;
statusIcon.FadeColour(status.Value.GetAppropriateColour(Colours), 500, Easing.OutQuint); statusIcon.FadeColour(status.GetAppropriateColour(Colours), 500, Easing.OutQuint);
return;
} }
// Fallback to web status if local one is null lastStatus = status;
if (User.IsOnline) lastActivity = activity;
{ lastVisit = status != UserStatus.Offline ? DateTimeOffset.Now : lastVisit;
Status.Value = UserStatus.Online;
return;
}
Status.Value = UserStatus.Offline;
} }
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)