Sharing settings and public profile pages (phase 1, step 5)

- sharing.html: switch sharing on/off, see the handle (with the
  "permanent once followed" warning and a note that following comes
  later), choose who sees posts (followers only by default; help text
  on why approval matters), follower approval, directory and search
  opt-ins, display name and bio; save status shown by the button
- profile.html?u=<name>: the public page browsers land on from an actor
  URL: name, handle (with copy), bio and how to follow; never asks the
  visitor to sign in
- "Sharing" appears in the nav only when the server federates
  (remembered per tab)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
mattandClaude Opus 5.5 committed 2026-09-25 20:32:40 +01:00
1 parent 0b10469514
commit c0b9e85519
6 files changed
+361

No files matched your search

+33
View File
@@ -20,6 +20,7 @@ export async function signedInPage(active) {
const header = document.getElementById("site-header");
replace(header, brand(), nav(active));
const user = await api("/auth/me");
addSharingLink(header.querySelector("nav ul"), active);
header.append(
h(
"div",
@@ -61,3 +62,35 @@ async function signOut() {
location.href = "login.html";
}
}
// "Sharing" only appears when the server federates. Remembered per tab.
const FEDERATION_KEY = "scrobbler.federation";
async function federationAvailable() {
try {
const cached = sessionStorage.getItem(FEDERATION_KEY);
if (cached !== null) return cached === "1";
} catch {
// Storage unavailable: just ask.
}
let available = false;
try {
await api("/federation/settings");
available = true;
} catch {
available = false;
}
try {
sessionStorage.setItem(FEDERATION_KEY, available ? "1" : "0");
} catch {
// Not remembered; asked again next page.
}
return available;
}
async function addSharingLink(list, active) {
if (!list || !(await federationAvailable())) return;
const href = "sharing.html";
list.append(h("li", {}, h("a", { href, "aria-current": href === active ? "page" : false }, "Sharing")));
}
+43
View File
@@ -0,0 +1,43 @@
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,
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),
);
}
+82
View File
@@ -0,0 +1,82 @@
import { api, describeError } from "./api.js";
import { errorBox, h, replace } from "./dom.js";
import { signedInPage } from "./layout.js";
const form = document.getElementById("sharing");
const messages = document.getElementById("messages");
const handlePanel = document.getElementById("handle-panel");
const FIELDS = ["enabled", "visibility", "manually_approves_followers", "discoverable", "indexable", "display_name", "bio"];
await signedInPage("sharing.html");
let settings;
try {
settings = await api("/federation/settings");
} catch (error) {
replace(
messages,
error.status === 404
? h("p", { class: "notice" }, "This server doesn't share to the fediverse. Ask whoever runs it to turn it on.")
: errorBox(error.message),
);
}
if (settings) {
fill(settings);
form.hidden = false;
form.elements.enabled.addEventListener("change", () => showHandle(form.elements.enabled.checked));
form.addEventListener("submit", save);
}
function fill(values) {
for (const name of FIELDS) {
const field = form.elements[name];
if (name === "visibility") {
form.querySelector(`input[name=visibility][value="${values.visibility}"]`).checked = true;
} else if (field.type === "checkbox") {
field.checked = Boolean(values[name]);
} else {
field.value = values[name] ?? "";
}
}
document.getElementById("handle").textContent = values.handle;
replace(
document.getElementById("profile-link"),
"Your public profile page: ",
h("a", { href: values.profile_url }, values.profile_url.replace(/^https?:\/\//, "")),
);
showHandle(values.enabled);
}
function showHandle(on) {
handlePanel.hidden = !on;
}
async function save(event) {
event.preventDefault();
const button = form.querySelector("button[type=submit]");
const changes = {
enabled: form.elements.enabled.checked,
visibility: form.querySelector("input[name=visibility]:checked").value,
manually_approves_followers: form.elements.manually_approves_followers.checked,
discoverable: form.elements.discoverable.checked,
indexable: form.elements.indexable.checked,
display_name: form.elements.display_name.value.trim() || null,
bio: form.elements.bio.value.trim() || null,
};
const status = document.getElementById("save-status");
button.disabled = true;
status.textContent = "Saving";
replace(messages);
try {
const saved = await api("/federation/settings", { method: "PATCH", body: changes });
fill(saved);
status.textContent = saved.enabled ? `Saved. You're sharing as ${saved.handle}.` : "Saved. Sharing is off.";
} catch (error) {
status.textContent = "";
replace(messages, errorBox(describeError(error)));
messages.scrollIntoView({ behavior: "smooth", block: "start" });
} finally {
button.disabled = false;
}
}