Files
Scrobbler/frontend/js/profile.js
T
mattandClaude Sonnet 5 f04e53a972
CI / validate-monitoring (push) Successful in 14s
CI / lint (push) Successful in 21s
CI / federation-interop (push) Successful in 1m21s
CI / test (push) Successful in 4m2s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
Web UI for now playing (phase 4, step 5)
Sharing page gets a "Now playing" section: off / show on profile /
show on profile and post, as a single choice matching the settings
column - generalised sharing.js's visibility-only radio-group handling
to a small RADIO_GROUPS list so now_playing_mode reuses the same fill/
save logic rather than adding a second special case.

Public profile API and profile.html gain a live "now playing" field,
sourced from the same actors.now_playing_text() the actor document
uses and gated the same way (now_playing_mode off means never showing
it, whatever's actually playing).

Refactored actors.py along the way: now_playing_field() takes settings
directly and does its own off-mode gating, rather than build_document()
doing it externally - one place decides whether the field is shown,
reused by the actor document, the push Update, and now the public
profile API.

Verified by hand in a real browser: settings round-trip through the
Sharing page's new radio group, the public profile page shows "Now
playing: Reckoner by Radiohead" once now_playing_mode is on, and the
raw actor document (curl, Accept: application/activity+json) carries
the same PropertyValue attachment.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
2026-09-26 17:22:02 +01:00

47 lines
1.6 KiB
JavaScript

import { api } from "./api.js";
import { errorBox, h, replace } from "./dom.js";
import { publicPage } from "./layout.js";
const root = document.getElementById("profile");
const username = new URLSearchParams(location.search).get("u") ?? "";
// A public page: never sends visitors to sign in.
publicPage();
try {
const profile = await api(`/federation/profiles/${encodeURIComponent(username)}`, { auth: false });
document.title = `${profile.display_name} · Scrobbler`;
const copy = h("button", { type: "button", class: "button button-quiet" }, "Copy handle");
copy.addEventListener("click", async () => {
try {
await navigator.clipboard.writeText(profile.handle);
copy.textContent = "Copied";
} catch {
copy.textContent = "Select and copy it above";
}
});
replace(
root,
h("h1", {}, profile.display_name),
h("div", { class: "approve-app handle" }, profile.handle),
profile.bio ? h("p", { class: "lede profile-bio" }, profile.bio) : null,
profile.now_playing
? h("p", { class: "now-playing" }, "Now playing: ", h("strong", {}, profile.now_playing))
: null,
h("h2", { class: "profile-follow" }, "Follow from the fediverse"),
h(
"p",
{ class: "muted" },
"Search for the handle above in Mastodon or any other fediverse app, then follow.",
),
h("div", { class: "button-row" }, copy),
);
} catch (error) {
replace(
root,
error.status === 404
? [h("h1", {}, "No profile here"), h("p", { class: "lede" }, "No one on this server shares their listening under that name.")]
: errorBox(error.message),
);
}