1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 03:15:36 +08:00

Move room code from activity code, prevent duplicate RPC updates

This commit is contained in:
jvyden 2024-03-19 16:03:32 -04:00
parent 808d6e0943
commit 0ecfa580d7
No known key found for this signature in database
GPG Key ID: 18BCF2BE0262B278

View File

@ -2,12 +2,14 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using System.Text;
using DiscordRPC;
using DiscordRPC.Message;
using Newtonsoft.Json;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Development;
using osu.Framework.Graphics;
using osu.Framework.Logging;
using osu.Game;
@ -48,6 +50,8 @@ namespace osu.Desktop
private readonly Bindable<DiscordRichPresenceMode> privacyMode = new Bindable<DiscordRichPresenceMode>();
private int usersCurrentlyInLobby = 0;
private readonly RichPresence presence = new RichPresence
{
Assets = new Assets { LargeImageKey = "osu_logo_lazer" },
@ -115,10 +119,10 @@ namespace osu.Desktop
Logger.Log("Updating Discord RPC", LoggingTarget.Network, LogLevel.Debug);
if (activity.Value != null)
{
bool hideIdentifiableInformation = privacyMode.Value == DiscordRichPresenceMode.Limited || status.Value == UserStatus.DoNotDisturb;
if (activity.Value != null)
{
presence.State = truncate(activity.Value.GetStatus(hideIdentifiableInformation));
presence.Details = truncate(activity.Value.GetDetails(hideIdentifiableInformation) ?? string.Empty);
@ -137,10 +141,20 @@ namespace osu.Desktop
{
presence.Buttons = null;
}
}
else
{
presence.State = "Idle";
presence.Details = string.Empty;
}
if (!hideIdentifiableInformation && multiplayerClient.Room != null)
{
MultiplayerRoom room = multiplayerClient.Room;
if (room.Users.Count == usersCurrentlyInLobby)
return;
presence.Party = new Party
{
Privacy = string.IsNullOrEmpty(room.Settings.Password) ? Party.PrivacySetting.Public : Party.PrivacySetting.Private,
@ -158,17 +172,13 @@ namespace osu.Desktop
};
presence.Secrets.JoinSecret = JsonConvert.SerializeObject(roomSecret);
usersCurrentlyInLobby = room.Users.Count;
}
else
{
presence.Party = null;
presence.Secrets.JoinSecret = null;
}
}
else
{
presence.State = "Idle";
presence.Details = string.Empty;
usersCurrentlyInLobby = 0;
}
// update user information