Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix discord "view beatmap" button being shown when editing and hide identifiable information is set #30848

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions osu.Desktop/DiscordRichPresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +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)
if (activity.Value.GetBeatmapID(hideIdentifiableInformation) is int beatmapId && beatmapId > 0)
{
presence.Buttons = new[]
{
Expand Down Expand Up @@ -327,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())
Expand Down
12 changes: 12 additions & 0 deletions osu.Game/Users/UserActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +44 to +48
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One may say this should not exist in UserActivity itself, but the only other option I can think of is to define an interface that exposes this method and implement such interface on InGame and EditingBeatmap, and I'm smelling some scent of over-engineering in that so I just chose to define it at a base level for now.


[MessagePackObject]
public class ChoosingBeatmap : UserActivity
{
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
Loading