summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Kundiman <erik@megapahit.org>2025-08-07 11:00:14 +0800
committerErik Kundiman <erik@megapahit.org>2025-08-07 11:00:14 +0800
commit3bec50abbb8bb4c4166c4e66cab8d21cc22bb6d5 (patch)
tree993ab5f4ae59ff3b04b2b5b730fc1e24cdd32777
parent12a6e340d7268b2dad2395a04e88e325ffc4c5f7 (diff)
Rich Presence w/o requiring access to friends list
Thank you Signal Linden for the pointer from https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1Client.html#af0a85e30f2b3d8a0b502fd23744ee58e "Note: On Desktop, rich presence can be set before calling Client::Connect, but it will be cleared if the Client connects. When Client is not connected, this sets the rich presence in the current user's Discord client when available." This lead me to setting the Application ID here https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1Client.html#ad452335c06b28be0406dab824acccc49 in place of setting it on https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1AuthorizationArgs.html which would lead Authorize, GetToken, UpdateToken, Connect, and so on. This means we don't even need the SecAPI saveCredential, loadCredential and deleteCredential parts now.
-rw-r--r--indra/newview/llappviewer.cpp97
-rw-r--r--indra/newview/llfloaterpreference.cpp2
2 files changed, 10 insertions, 89 deletions
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 8dec75e64e..c9bdc29bea 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -5933,100 +5933,21 @@ void LLAppViewer::initDiscordSocial()
gDiscordPartyMaxSize = 0;
gDiscordTimestampsStart = time(nullptr);
gDiscordClient = std::make_shared<discordpp::Client>();
- gDiscordClient->SetStatusChangedCallback([](discordpp::Client::Status status, discordpp::Client::Error, int32_t) {
- if (status == discordpp::Client::Status::Ready)
- {
- updateDiscordActivity();
- }
- });
- if (gSavedSettings.getBOOL("EnableDiscord"))
- {
- auto credential = gSecAPIHandler->loadCredential("Discord");
- if (credential.notNull())
- {
- gDiscordClient->UpdateToken(discordpp::AuthorizationTokenType::Bearer, credential->getAuthenticator()["token"].asString(), [](discordpp::ClientResult result) {
- if (result.Successful())
- gDiscordClient->Connect();
- else
- LL_WARNS("Discord") << result.Error() << LL_ENDL;
- });
- }
- else
- {
- LL_WARNS("Discord") << "Integration was enabled, but no credentials. Disabling integration." << LL_ENDL;
- gSavedSettings.setBOOL("EnableDiscord", false);
- }
- }
+ gDiscordClient->SetApplicationId(1393451183741599796);
+ updateDiscordActivity();
}
-void LLAppViewer::toggleDiscordIntegration(const LLSD& value)
+void LLAppViewer::updateDiscordActivity()
{
- static const uint64_t APPLICATION_ID = 1393451183741599796;
- if (value.asBoolean())
- {
- discordpp::AuthorizationArgs args{};
- args.SetClientId(APPLICATION_ID);
- args.SetScopes(discordpp::Client::GetDefaultPresenceScopes());
- auto codeVerifier = gDiscordClient->CreateAuthorizationCodeVerifier();
- args.SetCodeChallenge(codeVerifier.Challenge());
- gDiscordClient->Authorize(args, [codeVerifier](auto result, auto code, auto redirectUri) {
- if (result.Successful())
- {
- gDiscordClient->GetToken(APPLICATION_ID, code, codeVerifier.Verifier(), redirectUri, [](discordpp::ClientResult result, std::string accessToken, std::string, discordpp::AuthorizationTokenType, int32_t, std::string) {
- if (result.Successful())
- {
- gDiscordClient->UpdateToken(discordpp::AuthorizationTokenType::Bearer, accessToken, [accessToken](discordpp::ClientResult result) {
- if (result.Successful())
- {
- LLSD authenticator = LLSD::emptyMap();
- authenticator["token"] = accessToken;
- gSecAPIHandler->saveCredential(gSecAPIHandler->createCredential("Discord", LLSD::emptyMap(), authenticator), true);
- gDiscordClient->Connect();
- }
- else
- {
- LL_WARNS("Discord") << result.Error() << LL_ENDL;
- }
- });
- }
- else
- {
- LL_WARNS("Discord") << result.Error() << LL_ENDL;
- }
- });
- }
- else
- {
- LL_WARNS("Discord") << result.Error() << LL_ENDL;
- gSavedSettings.setBOOL("EnableDiscord", false);
- }
- });
- }
- else
+ LL_PROFILE_ZONE_SCOPED;
+
+ static LLCachedControl<bool> integration_enabled(gSavedSettings, "EnableDiscord", true);
+ if (!integration_enabled)
{
- gDiscordClient->Disconnect();
- auto credential = gSecAPIHandler->loadCredential("Discord");
- if (credential.notNull())
- {
- gDiscordClient->RevokeToken(APPLICATION_ID, credential->getAuthenticator()["token"].asString(), [](discordpp::ClientResult result) {
- if (result.Successful())
- LL_INFOS("Discord") << "Access token successfully revoked." << LL_ENDL;
- else
- LL_WARNS("Discord") << "No access token to revoke." << LL_ENDL;
- });
- auto cred = new LLCredential("Discord");
- gSecAPIHandler->deleteCredential(cred);
- }
- else
- {
- LL_WARNS("Discord") << "Credentials are already nonexistent." << LL_ENDL;
- }
+ gDiscordClient->ClearRichPresence();
+ return;
}
-}
-void LLAppViewer::updateDiscordActivity()
-{
- LL_PROFILE_ZONE_SCOPED;
discordpp::Activity activity;
activity.SetType(discordpp::ActivityTypes::Playing);
discordpp::ActivityTimestamps timestamps;
diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp
index 2a6360cef8..585032870e 100644
--- a/indra/newview/llfloaterpreference.cpp
+++ b/indra/newview/llfloaterpreference.cpp
@@ -367,7 +367,7 @@ LLFloaterPreference::LLFloaterPreference(const LLSD& key)
mCommitCallbackRegistrar.add("Pref.DeleteTranscripts", boost::bind(&LLFloaterPreference::onDeleteTranscripts, this));
mCommitCallbackRegistrar.add("UpdateFilter", boost::bind(&LLFloaterPreference::onUpdateFilterTerm, this, false)); // <FS:ND/> Hook up for filtering
#ifdef LL_DISCORD
- gSavedSettings.getControl("EnableDiscord")->getCommitSignal()->connect(boost::bind(&LLAppViewer::toggleDiscordIntegration, _2));
+ gSavedSettings.getControl("EnableDiscord")->getCommitSignal()->connect(boost::bind(&LLAppViewer::updateDiscordActivity));
gSavedSettings.getControl("ShowDiscordActivityDetails")->getCommitSignal()->connect(boost::bind(&LLAppViewer::updateDiscordActivity));
gSavedSettings.getControl("ShowDiscordActivityState")->getCommitSignal()->connect(boost::bind(&LLAppViewer::updateDiscordActivity));
#endif