From a1b646f88b00ffda96f5e0186bc21137762b61ff Mon Sep 17 00:00:00 2001 From: rowkav09 Date: Sat, 10 Oct 2026 11:48:13 +0100 Subject: [PATCH] fix: populate the mediaType template token from the presence kind Providers normalize playback into the presence model's kind field, so the documented {mediaType} token rendered blank for real playback; only older callers passing a raw mediaType field got a value. The token now reads the normalized kind first and keeps the raw field as the fallback. Fixes #1119 --- src/template.js | 4 +++- test/discord-activity-name.test.js | 7 +++++++ test/template.test.js | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/template.js b/src/template.js index 4ed5e962..584bf20d 100644 --- a/src/template.js +++ b/src/template.js @@ -75,7 +75,9 @@ export function createTemplateValues(presence, { labels = {} } = {}) { episode: presence.episode == null ? "" : String(presence.episode), episodeCode: episodeCode(presence.season, presence.episode), provider: presence.provider ?? "", - mediaType: presence.mediaType ?? "", + // Normalized presence carries the kind; the raw mediaType field is the + // fallback for older callers passing a plain object. + mediaType: presence.kind ?? presence.mediaType ?? "", state: presence.state ?? "", stateLabel: stateLabels[presence.state] ?? presence.state ?? "", position: formatDuration(presence.positionMs), diff --git a/test/discord-activity-name.test.js b/test/discord-activity-name.test.js index 5a8db520..9c5afb03 100644 --- a/test/discord-activity-name.test.js +++ b/test/discord-activity-name.test.js @@ -58,3 +58,10 @@ test("statusDisplayType is sent even when there is no name (no artist, or an emp assert.equal(noArtist.statusDisplayType, "state"); assert.equal(formatDiscordActivity(song(), { name: "", statusDisplayType: "details" }).statusDisplayType, "details"); }); + +test("the {mediaType} token renders the normalized kind in the Discord name (#1119)", () => { + for (const kind of ["track", "movie", "episode", "show", "unknown"]) { + const presence = createPresence({ state: "playing", kind, title: "T", provider: "plex", updatedAt: "2026-10-02T12:00:00Z" }); + assert.equal(formatDiscordActivity(presence, { name: "{mediaType}" }).name, kind); + } +}); diff --git a/test/template.test.js b/test/template.test.js index 8f74d60a..e7f6195f 100644 --- a/test/template.test.js +++ b/test/template.test.js @@ -135,3 +135,9 @@ test("{service} for a provider id that names an Object.prototype property is pla assert.equal(service, id.charAt(0).toUpperCase() + id.slice(1)); } }); + +test("mediaType comes from the normalized presence kind, raw field as fallback (#1119)", () => { + assert.equal(createTemplateValues({ kind: "track", state: "playing" }).mediaType, "track"); + assert.equal(createTemplateValues({ kind: "movie", state: "playing" }).mediaType, "movie"); + assert.equal(createTemplateValues({ mediaType: "episode", state: "paused" }).mediaType, "episode"); +});