Move beatmap ID lookup to `UesrActivity`

This commit is contained in:
Salman Alshamrani 2024-11-27 16:54:51 -05:00
parent 62837c7e53
commit 24c0799680
2 changed files with 13 additions and 17 deletions

View File

@ -167,9 +167,7 @@ private void updatePresence(bool hideIdentifiableInformation)
presence.State = clampLength(activity.Value.GetStatus(hideIdentifiableInformation));
presence.Details = clampLength(activity.Value.GetDetails(hideIdentifiableInformation) ?? string.Empty);
if (getBeatmapID(activity.Value) is int beatmapId
&& beatmapId > 0
&& !(activity.Value is UserActivity.EditingBeatmap && hideIdentifiableInformation))
if (activity.Value.GetBeatmapID(hideIdentifiableInformation) is int beatmapId && beatmapId > 0)
{
presence.Buttons = new[]
{
@ -329,20 +327,6 @@ private static bool tryParseRoomSecret(string secretJson, out long roomId, out s
return true;
}
private static int? getBeatmapID(UserActivity activity)
{
switch (activity)
{
case UserActivity.InGame game:
return game.BeatmapID;
case UserActivity.EditingBeatmap edit:
return edit.BeatmapID;
}
return null;
}
protected override void Dispose(bool isDisposing)
{
if (multiplayerClient.IsNotNull())

View File

@ -41,6 +41,12 @@ public abstract class UserActivity
public virtual Color4 GetAppropriateColour(OsuColour colours) => colours.GreenDarker;
/// <summary>
/// Returns the ID of the beatmap involved in this activity, if applicable and/or available.
/// </summary>
/// <param name="hideIdentifiableInformation"></param>
public virtual int? GetBeatmapID(bool hideIdentifiableInformation = false) => null;
[MessagePackObject]
public class ChoosingBeatmap : UserActivity
{
@ -76,6 +82,7 @@ protected InGame() { }
public override string GetStatus(bool hideIdentifiableInformation = false) => RulesetPlayingVerb;
public override string GetDetails(bool hideIdentifiableInformation = false) => BeatmapDisplayTitle;
public override int? GetBeatmapID(bool hideIdentifiableInformation = false) => BeatmapID;
}
[MessagePackObject]
@ -156,6 +163,11 @@ public override string GetDetails(bool hideIdentifiableInformation = false) => h
// For now let's assume that showing the beatmap a user is editing could reveal unwanted information.
? string.Empty
: BeatmapDisplayTitle;
public override int? GetBeatmapID(bool hideIdentifiableInformation = false) => hideIdentifiableInformation
// For now let's assume that showing the beatmap a user is editing could reveal unwanted information.
? null
: BeatmapID;
}
[MessagePackObject]