# Discord presence

Settings live on **Settings → Discord**. The legacy switches (`enableDiscordRpc`,
`hideDiscordRpcInIncognito`, `rpcShow*`) stay on `DbSettings`; everything new is in
`DbSettings.features.discord`. Defaults keep the previous presence text, buttons and
timestamp.

## Transports

| Platform | Transport | Login |
|---|---|---|
| Android, iOS | Discord gateway websocket with the active account | In-app Discord login page, or a pasted token |
| Web | Discord gateway websocket with the active account | Pasted token (a page cannot read discord.com storage) |
| Desktop | Local Discord client IPC socket when no account is active; the gateway when one is | Pasted token (JavaFX WebKit cannot finish Discord's captcha login) |

- The shared `GatewayDiscordRpcService` (`services/discord`) holds one websocket per active
  token, identifies, heartbeats and re-sends the latest presence after every reconnect.
  Close codes 4004/4010–4014 stop retries and ask the user to log in again.
- Covers are uploaded through Discord's `external-assets` endpoint and shown as `mp:` media
  proxy images. If that call fails (for example a browser blocking the cross-origin request),
  the presence is sent without an image.
- Presence lives while the app process is running. There is no foreground service; Android may
  drop the socket in deep sleep and it reconnects on the next update.
- Animetail's pinned build uses Discord's proprietary Social SDK, which needs a partner-approved
  application and native binaries. Yokan uses the gateway approach Animetail used before
  (KizzyRPC). Discord does not officially allow automating user accounts; the add-account dialog
  says so. Tokens are the user's own; no upstream credentials ship with Yokan.

## Accounts

- Several accounts can be stored; exactly one is active (radio button). Removing the active one
  activates the next. Re-adding the same Discord user replaces its token.
- The account name comes from `/users/@me`. When that is unreachable (offline, browser CORS),
  the user id is decoded from the token. A 401 rejects the token.
- Tokens are installation-local: `features` is never synced or overwritten by a restore, and
  backups strip `discord.accounts` (`DbDiscordPreferences.forExport`). `toString` never prints
  tokens.

## Presence content

`discordActivity()` builds one transport-neutral activity from the settings:

- **Custom message** replaces "Reading/Watching <title>" (and "Idle").
- **Show progress / title / cover** keep their previous meaning.
- **Show elapsed time** sends the session start timestamp.
- **Show buttons** with up to two user-defined label/URL buttons (default: the previous
  "Get Yokan" and "Join us").
- **Online status** (online/idle/do not disturb) is sent on the gateway. The desktop IPC socket
  cannot change the user's status.

## Privacy

- Global incognito with "Hide RPC in incognito" publishes nothing (as before).
- "Never show titles" and **private categories** (including Uncategorized) replace the title
  with the idle activity: no title, cover or progress reaches Discord.
