// ON-SCREEN ANONYMISING (characters C3; knobs.md, "This video's own characters, and an item's own"). // // ANONYMITY BELONGS TO THE HANDLE, PROJECT-WIDE. One set of anonymous handles (case-insensitive) is built for a // video (anonymousHandles): every handle an anonymous character of `/narration/characters.json` lists, AND // the author handle of every post item that names an anonymous character by id. Every drawn surface consults that set // -- never an item's `narration.character` alone: the character an item names decides its VOICE, the set decides the // IDENTITY on screen. An unresolvable state (an item naming an anonymous character with no handle of its own, one // handle claimed under two shown names) REFUSES (AnonymityError); it never falls through to the real identity. // // For a handle in the set, wherever a card draws that author -- an item's head and strip, the posts it answers, // quotes and links, a repost line, "Replying to", a thread read's tiles, a scene's tiles, a side card, the vertical // cut, the chapters, a deck popup post (`manifest.posts[]`, its feed too) -- it is the shown name, the handle a // pseudonym made from it ("Anon 1" -> "Anon_1", never drawn beside the name), no verified badge, a neutral avatar // (post-item.mjs avatarHtml: the shown name's initial on the card's muted colour; never their picture). // // In the WORDS a card draws (a post's text and paraphrase, its parents', quoted and linked posts', a popup's text, // their urls) every @mention of an anonymous handle, and every platform URL carrying one (x.com / twitter.com // /…, bsky.app/profile/…, threads.net/@…, truthsocial.com/@…, youtube.com/@…), is rewritten to the // pseudonym in ONE pass (anonymiseWords: a pseudonym that equals another anonymous handle is never rewritten again) // -- one word for one, so every word index (a word zoom's, the read-follow's) holds. // // Pictures that may show the real names are not drawn: with ANY anonymous handle in the video, no post item's // captured thread shot (it pictures posts whose authors cannot all be known) and no popup post's thread shot; a popup // post BY an anonymous handle draws neither its screenshot nor its QR code (both identify the author by themselves). // // An anonymous author is not blurred by the card's privacy rule (post-item.mjs authorRedaction: the shown name says // nothing of who they are); `redact: true` still blurs them. The flags are this pass's alone: any `anonymous` an // incoming manifest carries is stripped first. NOT covered by code: a display name written out inside someone's // words (lint WARNS), names inside attachment images (the operator's to check). What a read SAYS: post-redact.mjs // spokenRead (a synthesized read says the shown name), lint (a recorded or made take that says a handle is an ERROR). // // The pass is made ONCE on the manifest a build (build-video.mjs) or a preview (the app's post-item route) reads, // after a take's manifest is resolved. With no anonymous handle and no stray flag the manifest is returned AS IT IS // (the same object): a cut with none renders byte-identically. // // PURE and dependency-free (beyond cast.mjs / post-say.mjs). import { anonShownClashes, anonShownMap, projectCharactersOf } from "./cast.mjs"; import { handleKey } from "./post-say.mjs"; const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); const str = (v) => (typeof v === "string" ? v : ""); /** An anonymity the pass cannot resolve: the build and Play refuse rather than draw a real name. */ export class AnonymityError extends Error { constructor(message) { super(message); this.name = "AnonymityError"; } } /** The handle an anonymous author is drawn under: the shown name as a handle ("Anon 1" -> "Anon_1"). */ export const pseudonymOf = (shown) => str(shown).replace(/[^A-Za-z0-9_]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 64) || "anon"; /** * THE VIDEO's ANONYMOUS HANDLES: `Map` -- every handle an anonymous character lists, and * the author handle of every post item that names an anonymous character by id, in ANY of `manifests` (the whole * project manifest -- every variant, before rulings, windows or `--only` -- and a take's own: projectAnonymousSet, * project-characters-file.mjs, gives the build, the composer, the lint, Play and the previews this one set). The map * carries `postIds`: the native ids of every post an anonymous author wrote that the manifests know (a status URL of * one is theirs). Throws AnonymityError for what it cannot resolve -- naming characters and items, never a real handle. * * @param {any} doc characters.json's document (null: none) * @param {...any} manifests * @returns {Map & { postIds: Set }} */ export function anonymousHandles(doc, ...manifests) { const chars = projectCharactersOf(doc); const shown = anonShownMap(chars); const out = /** @type {Map & { postIds: Set }} */ (new Map()); const why = new Map(); const put = (h, s, label) => { const k = handleKey(h); if (!k) return; if (out.has(k) && out.get(k) !== s) throw new AnonymityError(`one author's handle is shown as "${out.get(k)}" (${why.get(k)}) and as "${s}" (${label}): one handle, one anonymous character -- fix narration/characters.json or the item`); if (!out.has(k)) why.set(k, label); out.set(k, s); }; for (const c of chars) if (c.anonymous === true) for (const h of c.handles ?? []) put(h, shown.get(c.id), `${c.id}'s handles`); const tls = manifests.flatMap((m) => (Array.isArray(m?.timeline) ? m.timeline : [])); for (const e of tls) { if (e?.type !== "post") continue; const id = str(e.narration?.character).trim().toLowerCase(); if (!id || !shown.has(id)) continue; if (!handleKey(e.handle)) throw new AnonymityError(`${e.id} names the anonymous character ${id} but has no author handle to hide: give the item its handle, or name another character`); put(e.handle, shown.get(id), `${e.id} names ${id}`); } // A shown name (or its pseudonym) that is a real author's handle or display name pins posts on a real person. if (out.size) { const clash = anonShownClashes(chars, manifests, { only: new Set(out.values()) })[0]; if (clash) throw new AnonymityError(clash); } // The posts the anonymous authors wrote, by native id. out.postIds = new Set(); const idOf = (v) => str(v).match(/(?:^|\/)([A-Za-z0-9_-]{4,})$/)?.[1] ?? ""; const statusOf = (u) => str(u).match(/\/(?:status|statuses|post|posts|video|reel|p)\/([A-Za-z0-9_-]+)/)?.[1] ?? ""; for (const m of manifests) { for (const e of [...(Array.isArray(m?.timeline) ? m.timeline : []).filter((x) => x?.type === "post"), ...(Array.isArray(m?.posts) ? m.posts : [])]) { for (const w of [e, ...(Array.isArray(e?.parents) ? e.parents : []), ...(Array.isArray(e?.links) ? e.links : []), e?.quoted].filter(isObj)) { if (!out.has(handleKey(w.handle))) continue; for (const v of [w === e ? idOf(e.post) : "", str(w.id), str(w.originalId), statusOf(w.url)]) if (v && v.length >= 4) out.postIds.add(v.toLowerCase()); } } } return out; } /** An author object drawn as `shown`: the shown name, the pseudonym, no badge, marked `anonymous`. */ function asAnon(who, shown) { const { badge: _b, ...rest } = who; return { ...rest, author: shown, handle: pseudonymOf(shown), anonymous: true }; } const escRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); /** The hosts whose URLs name an account by its handle (the first path segment, `@` or not; Bluesky's `profile/`). */ export const PLATFORM_HOSTS = Object.freeze(["x.com", "twitter.com", "nitter.net", "xcancel.com", "fxtwitter.com", "vxtwitter.com", "fixupx.com", "bsky.app", "threads.net", "threads.com", "truthsocial.com", "youtube.com", "instagram.com", "tiktok.com"]); /** A URL in words: an optional scheme, a host (www./mobile./m. dropped), its path -- never an e-mail's host. */ const URL_SRC = String.raw`(?(?:[a-z0-9-]+\.)+[a-z]{2,})(?\/[^\s<>"'\x60]*)?`; /** * Words a handle is never said bare for (only its @form is replaced): too short to be told from words, or a word itself. * A bare one of these left in a read is a lint WARNING. */ const COMMON_WORDS = new Set(("able about above after again against also always among another answer anything around away back because become been " + "before being below best better between both bring build call came come could daily dark days dead does done down each early easy even ever " + "every face fact fair fall family fast feel fine first five follow food free from front full game girl give good great green group grow " + "half hand happy hard have head hear heart help here high hold home hope hour house idea info into just keep kind king know land last late " + "learn left less life light like line list little live long look lord love made main make many mark mind more most move much music must " + "name near need never news next nice night none note nothing only open other over page part past people place plan play point post power " + "real really right road room said same save says seen self send shop show side sign since some song soon sound start stay still stop " + "story such sure take talk team tell than that their them then there these they thing think this those time today told took tour town " + "true truth turn very view wait walk want watch water week well went were what when where which while white whole wild will with word " + "work world year yes young your guest host stranger friend other someone person people anon user admin official media " + "daily truth movie music sport sports games radio show channel stream live video clip").split(/\s+/)); /** Can a handle be told apart as a bare word in a read (4+ characters, not a common word)? */ export const bareSayable = (h) => str(h).length >= 4 && !COMMON_WORDS.has(str(h).toLowerCase()); const memo = new WeakMap(); /** The one-pass pattern for a set: a URL | an @mention of a handle | (spoken only) a bare handle. */ function patternOf(set, spoken = false) { const cache = memo.get(set) ?? {}; const key = spoken ? "s" : "w"; if (cache[key] !== undefined) return cache[key]; const hs = [...set.keys()].sort((a, b) => b.length - a.length).map(escRe); const bare = spoken ? [...set.keys()].filter(bareSayable).sort((a, b) => b.length - a.length).map(escRe) : []; const alts = [URL_SRC]; if (hs.length) alts.push(String.raw`(?${hs.join("|")})(?![A-Za-z0-9_]|\.[A-Za-z0-9])`); if (bare.length) alts.push(String.raw`(?${bare.join("|")})(?![\w]|\.[A-Za-z0-9])`); const re = new RegExp(alts.join("|"), "giu"); memo.set(set, { ...cache, [key]: re }); return re; } const safeDecode = (s) => { try { return decodeURIComponent(s); } catch { return s; } }; /** * IS THIS URL an anonymous author's (pure)? A platform URL whose account segment (`/`, `/@`, Bluesky's * `/profile/`), `search?q=from:` or `intent/user?screen_name=` names an anonymous handle -- decoded first, * any case -- or one truncated ("x.com/realgu…") whose visible start (4+ characters) begins one; or a status/post URL * of a post an anonymous author wrote (`set.postIds`), on any host. */ export function anonymousUrl(host, path, set) { const h = str(host).toLowerCase().replace(/^(?:www|mobile|m)\./, ""); const raw = str(path); const truncated = /(?:…|\.\.\.)$/.test(raw); const p = safeDecode(raw.replace(/(?:…|\.\.\.)$/, "")); const status = p.match(/\/(?:status|statuses|post|posts|video|reel|p)\/([A-Za-z0-9_-]+)/)?.[1]; if (status && set.postIds?.has(status.toLowerCase())) return true; if (!PLATFORM_HOSTS.includes(h)) return false; const [pathPart, query = ""] = p.split(/\?/, 2); const segs = pathPart.split(/[/#]/).filter(Boolean); const cands = []; if (segs.length) cands.push(h === "bsky.app" && segs[0].toLowerCase() === "profile" ? segs[1] ?? "" : segs[0].replace(/^@/, "")); const q = new URLSearchParams(query.split("#")[0]); const from = (q.get("q") ?? "").match(/from:@?([A-Za-z0-9_.-]+)/i)?.[1]; if (from) cands.push(from); if (q.get("screen_name")) cands.push(q.get("screen_name")); for (const c of cands.map((x) => handleKey(x))) { if (!c) continue; if (set.has(c)) return true; // Truncated where the account segment is the last thing seen: its visible start. if (truncated && segs.length === 1 && c.length >= 4 && [...set.keys()].some((k) => k.startsWith(c))) return true; } return false; } /** One pass over `text` (see anonymiseWords / speakAnonymised): `{ text, handles, urls }` -- what it replaced. */ function rewrite(text, set, spoken) { const handles = new Set(); let urls = 0; const re = patternOf(set, spoken); const out = text.replace(re, (...args) => { const all = args[0]; const g = args.at(-1); if (g.host !== undefined) { // A URL: an anonymous author's is collapsed to its bare host ("x.com/…"); trailing punctuation kept. const path = g.path ?? ""; const tail = path.match(/[.,;:!?)\]]+$/)?.[0] ?? ""; const core = tail ? path.slice(0, -tail.length) : path; if (!core || !anonymousUrl(g.host, core, set)) return all; urls += 1; return `${g.host.toLowerCase().replace(/^(?:www|mobile|m)\./, "")}/…${tail}`; } const h = (g.at ?? g.bare ?? "").toLowerCase(); const s = set.get(h); if (!s) return all; handles.add(h); return spoken ? s : `@${pseudonymOf(s)}`; }); return { text: out, handles: [...handles], urls }; } /** * `text` as a card draws it: every @mention of an anonymous handle made the pseudonym's ("@Anon_1"), every URL of an * anonymous author's (anonymousUrl) collapsed to its bare host ("x.com/…") -- one word for one, in ONE pass (no * replacement is looked at again). The same string when none is in it. * @param {string} text * @param {Map} set anonymousHandles' */ export function anonymiseWords(text, set) { if (typeof text !== "string" || !set?.size || !text) return text; const r = rewrite(text, set, false); return r.handles.length || r.urls ? r.text : text; } /** An object with the words of `keys` anonymised; the object itself when none changed. */ function withWords(o, set, keys = ["text", "paraphrase", "url"]) { if (!isObj(o)) return o; let out = o; for (const k of keys) { const v = anonymiseWords(o[k], set); if (v !== o[k]) out = { ...(out === o ? o : out), [k]: v }; } return out; } /** A who-object without an `anonymous` flag (only this pass sets one); itself when it had none. */ const unflag = (o) => { if (!isObj(o) || !("anonymous" in o)) return o; const { anonymous: _a, ...rest } = o; return rest; }; /** A post item with every incoming `anonymous` flag stripped; itself when it carried none. */ function stripped(e) { if (!isObj(e)) return e; let out = unflag(e); for (const k of ["parents", "links"]) { const list = out[k]; if (!Array.isArray(list) || !list.some((p) => isObj(p) && "anonymous" in p)) continue; out = { ...(out === e ? e : out), [k]: list.map(unflag) }; } for (const k of ["quoted", "repostedBy"]) if (isObj(out[k]) && "anonymous" in out[k]) out = { ...(out === e ? e : out), [k]: unflag(out[k]) }; // A screen's lines (post-screens.mjs): the flag is this pass's alone there too. if (Array.isArray(out.screens) && out.screens.some((sc) => isObj(sc) && Array.isArray(sc.lines) && sc.lines.some((l) => isObj(l) && "anonymous" in l))) { out = { ...(out === e ? e : out), screens: out.screens.map((sc) => (isObj(sc) && Array.isArray(sc.lines) ? { ...sc, lines: sc.lines.map(unflag) } : sc)) }; } return out; } /** * ONE POST ITEM with its anonymous authors drawn under their shown names (pure; see the head). Returns the entry * itself when nothing in it is anonymous. `set`: anonymousHandles'. * * @param {Record} e0 * @param {Map} set */ export function anonymiseEntry(e0, set) { const e = stripped(e0); if (e?.type !== "post" || !set?.size) return e; const of = (h) => set.get(handleKey(h)) ?? null; const ownShown = of(e.handle); let out = e === e0 ? null : e; const edit = () => (out ??= { ...e }); if (ownShown) { const o = edit(); o.author = ownShown; o.handle = pseudonymOf(ownShown); o.anonymous = true; delete o.badge; // No link to their post anywhere: no corner QR (deck.mjs deckQrUrl), no cite or archive link. o.noQr = true; delete o.citeUrl; delete o.siteUrl; delete o.siteChannel; } const refs = (list) => { if (!Array.isArray(list)) return list; let changed = false; const next = list.map((p) => { const s = isObj(p) ? of(p.handle) : null; const q = s ? asAnon(p, s) : p; const w = withWords(q, set); if (w !== p) changed = true; return w; }); return changed ? next : list; }; for (const k of ["parents", "links"]) { const next = refs((out ?? e)[k]); if (next !== (out ?? e)[k]) edit()[k] = next; } for (const k of ["quoted", "repostedBy"]) { const r = (out ?? e)[k]; if (!isObj(r)) continue; const s = of(r.handle); const next = withWords(s ? asAnon(r, s) : r, set); if (next !== r) edit()[k] = next; } const replyShown = str(e.replyingTo) ? of(e.replyingTo) : null; if (replyShown) edit().replyingTo = pseudonymOf(replyShown); // The subjects name handles: an anonymous one is its pseudonym there too (the card's subject accent still finds it). if (Array.isArray(e.subjects) && e.subjects.some((h) => of(h))) edit().subjects = e.subjects.map((h) => (of(h) ? pseudonymOf(of(h)) : h)); // ITS SCREENS (post-screens.mjs): a speaker who is an anonymous handle under the shown name (flagged, drawn as it), every // line's words and a title anonymised as the card's words are. if (Array.isArray(e.screens)) { let changed = false; const screens = e.screens.map((sc) => { if (!isObj(sc) || !Array.isArray(sc.lines)) return sc; let mine = false; const lines = sc.lines.map((l) => { if (!isObj(l)) return l; const s = typeof l.who === "string" ? of(l.who) : null; // A speaker that is not the handle itself ("x.com/", "@") has its words anonymised as a post's are. const who = s ?? anonymiseWords(l.who, set); const text = anonymiseWords(l.text, set); const time = anonymiseWords(l.time, set); if (!s && text === l.text && who === l.who && time === l.time) return l; mine = true; return { ...l, ...(s ? { who: s, anonymous: true } : who !== undefined ? { who } : {}), text, ...(time !== undefined ? { time } : {}) }; }); const title = anonymiseWords(sc.title, set); // Each EXCERPT rewritten as its line is: still a run of the line's words as drawn. const read = Array.isArray(sc.read) ? sc.read.map((x) => (isObj(x) && typeof x.text === "string" ? { ...x, text: anonymiseWords(x.text, set) } : x)) : sc.read; const readChanged = Array.isArray(sc.read) && read.some((x, i) => x !== sc.read[i] && x.text !== sc.read[i].text); if (!mine && title === sc.title && !readChanged) return sc; changed = true; return { ...sc, lines, ...(title !== undefined ? { title } : {}), ...(readChanged ? { read } : {}) }; }); if (changed) edit().screens = screens; // Its takes' screen parts record the line and the speaker they were made from: rewritten as the lines are, so the // drawn copy is judged against itself (the build judges staleness on the cut as written: post-thread.mjs). const takes = Array.isArray(e.narration?.takes) ? e.narration.takes : null; if (takes?.some((t) => Array.isArray(t?.parts) && t.parts.some((pt) => isObj(pt) && (typeof pt.line === "string" || typeof pt.speaker === "string")))) { const next = takes.map((t) => (Array.isArray(t?.parts) ? { ...t, parts: t.parts.map((pt) => { if (!isObj(pt) || (typeof pt.line !== "string" && typeof pt.speaker !== "string")) return pt; const sp = typeof pt.speaker === "string" ? of(pt.speaker) ?? anonymiseWords(pt.speaker, set) : undefined; return { ...pt, ...(typeof pt.line === "string" ? { line: anonymiseWords(pt.line, set) } : {}), ...(sp !== undefined ? { speaker: sp } : {}) }; }) } : t)); const o = edit(); o.narration = { ...e.narration, takes: next }; } } // The words the card draws. const w = withWords(out ?? e, set); if (w !== (out ?? e)) out = w; // A captured thread shot pictures posts whose authors cannot all be known: with any anonymous handle, never drawn. if (typeof e.parentShot === "string") delete edit().parentShot; return out ?? e; } /** A deck POPUP post (`manifest.posts[]`) by an anonymous handle: the shown name, no screenshot, no QR; words anonymised. */ function anonymisePopup(p0, set) { const p = unflag(p0); if (!isObj(p) || !set.size) return p; const s = set.get(handleKey(p.handle)) ?? null; let out = withWords(p, set, ["text", "url"]); if (s) { const { shot: _s, thread: _t, siteUrl: _u, siteChannel: _c, citeUrl: _ci, shotMaxHeight: _h, ...rest } = asAnon(out, s); out = { ...rest, noQr: true }; } // A popup's thread shot pictures the posts above it: with any anonymous handle, never drawn. if (out.thread === true) { const { thread: _t, ...rest } = out; out = rest; } return out === p0 ? p0 : out; } /** * A MANIFEST with every anonymous author drawn under their shown name (see the head), or the same object when the * video has no anonymous handle and nothing carried a stray flag. `doc`: characters.json's document. The set is kept * on the result as `anonymousHandles` (`{ : }`) for the modules that draw a handle of their own (the * promise panel, a chat replay). Throws AnonymityError for what it cannot resolve. * * @param {any} manifest * @param {any} doc * @param {{ set?: (Map & { postIds?: Set }) | null }} [o] */ export function anonymiseManifest(manifest, doc, { set: given = null } = {}) { if (!isObj(manifest)) return manifest; // The PROJECT's set when the caller has it (projectAnonymousSet: the whole manifest, every variant, a take's too); // else this manifest's own. const set = given ?? anonymousHandles(doc, manifest); let changed = false; const tl = Array.isArray(manifest.timeline) ? manifest.timeline.map((e) => { const n = anonymiseEntry(e, set); if (n !== e) changed = true; return n; }) : manifest.timeline; const posts = Array.isArray(manifest.posts) ? manifest.posts.map((p) => { const n = anonymisePopup(p, set); if (n !== p) changed = true; return n; }) : manifest.posts; const stray = "anonymousHandles" in manifest || "anonymousPostIds" in manifest; if (!changed && !set.size && !stray) return manifest; const { anonymousHandles: _x, anonymousPostIds: _y, ...rest } = manifest; return { ...rest, ...(tl !== undefined ? { timeline: tl } : {}), ...(posts !== undefined ? { posts } : {}), ...(set.size ? { anonymousHandles: Object.fromEntries(set), anonymousPostIds: [...(set.postIds ?? [])] } : {}), }; } /** The anonymous set a manifest carries after the pass (`anonymousHandles`, `anonymousPostIds`): anonymousHandles' shape. */ export function anonymousHandlesOf(manifest) { const m = /** @type {Map & { postIds: Set }} */ (new Map(Object.entries(isObj(manifest?.anonymousHandles) ? manifest.anonymousHandles : {}).filter(([, v]) => typeof v === "string"))); m.postIds = new Set(Array.isArray(manifest?.anonymousPostIds) ? manifest.anonymousPostIds.map(String) : []); return m; } /** Deck popup posts (`manifest.posts[]`) as the set has them -- after a preview's unsaved draft is laid on (onscreen.mjs). */ export const anonymisePosts = (posts, set) => (Array.isArray(posts) && set?.size ? posts.map((p) => anonymisePopup(p, set)) : posts); /** * A chat replay's messages (chat.mjs chatSchedule's `clips`) as the anonymous set has them: a message whose author is * an anonymous handle (as a chat names it, any case) under the shown name, every message's words anonymised * (anonymiseWords). The clips themselves when nothing changed. */ export function anonymiseChatClips(clips, set) { if (!Array.isArray(clips) || !set?.size) return clips; let changed = false; const out = clips.map((c) => { if (!Array.isArray(c?.messages)) return c; let mine = false; const messages = c.messages.map((m) => { const s = set.get(handleKey(m?.author)) ?? null; const text = anonymiseWords(m?.text, set); if (!s && text === m?.text) return m; mine = true; return { ...m, ...(s ? { author: s } : {}), text }; }); if (!mine) return c; changed = true; return { ...c, messages }; }); return changed ? out : clips; } /** * WHAT A SYNTHESIZED READ SAYS for an anonymous handle (post-redact.mjs spokenRead): `@realguy` -- and the bare * handle as a whole word, when it can be told from words (bareSayable: 4+ characters, not a common word) -- said as * the shown name ("Anon 1"); an anonymous author's URL collapsed to its host. One pass. `{ text, handles }`: the * anonymous handles it replaced (lower case; none: the same text). * @param {string} text * @param {Map | Record | null} set */ export function speakAnonymised(text, set) { const m = set instanceof Map ? set : new Map(Object.entries(isObj(set) ? set : {}).filter(([k, v]) => k !== "postIds" && typeof v === "string")); if (!(set instanceof Map) && Array.isArray(set?.postIds)) /** @type {any} */ (m).postIds = new Set(set.postIds); if (typeof text !== "string" || !m.size || !text) return { text, handles: [] }; const r = rewrite(text, m, true); return r.handles.length || r.urls ? { text: r.text, handles: r.handles } : { text, handles: [] }; } /** The take a post item plays (narration.pick, else the first; none when off) -- post-narration.mjs pickedTake's rule. */ function playing(e) { const takes = Array.isArray(e?.narration?.takes) ? e.narration.takes : []; if (!takes.length || e?.narration?.off === true) return null; const k = Number.isInteger(e.narration.pick) && e.narration.pick >= 0 && e.narration.pick < takes.length ? e.narration.pick : 0; return isObj(takes[k]) ? takes[k] : null; } const phraseRe = (s) => new RegExp(`(? & { postIds?: Set }) | null }} [o] */ export function anonymityProblems(manifest, doc, { set: given = null } = {}) { let set; try { set = given ?? anonymousHandles(doc, manifest); } catch (e) { return { errors: [e instanceof Error ? e.message : String(e)], warnings: [] }; } if (!set.size) return { errors: [], warnings: [] }; const errors = []; const warnings = []; // The display names the anonymous authors go by in the capture (and a character's own label), with their shown names. const names = new Map(); const addName = (n, shown) => { const t = str(n).trim(); if (t.length >= 3 && t.toLowerCase() !== str(shown).toLowerCase()) names.set(t, shown); }; const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : []; const posts = Array.isArray(manifest?.posts) ? manifest.posts : []; const whoOf = (e) => [e, ...(Array.isArray(e?.parents) ? e.parents : []), ...(Array.isArray(e?.links) ? e.links : []), e?.quoted, e?.repostedBy].filter(isObj); for (const e of [...tl.filter((x) => x?.type === "post"), ...posts]) for (const w of whoOf(e)) if (set.has(handleKey(w.handle))) addName(w.author, set.get(handleKey(w.handle))); const shownOf = anonShownMap(projectCharactersOf(doc)); for (const c of projectCharactersOf(doc)) if (c.anonymous === true) addName(c.name, shownOf.get(c.id)); for (const e of tl) { if (e?.type !== "post") continue; const t = playing(e); if (t) { // WHAT IT SAYS: a synthesized take's spoken text (`said`, kept when it differs from the script), else its script // (a recording says its script) -- and a thread read's parts. Judged as said: no exemption list. const said = [str(t.said) || str(t.script), ...(Array.isArray(t.parts) ? t.parts.map((p) => str(p?.text)) : [])].join("\n"); for (const [h, shown] of set) { const at = new RegExp(`(? isObj(sc) && Array.isArray(sc.lines)); for (const sc of screens) { // A SPEAKER, A TIME, THE TITLE: short fields drawn as written but for an exact handle -- any other form of an // anonymous handle ("SecretKid (alt)", "x.com/secretkid", "@secretkid") or display name in one is an ERROR. // A speaker that IS the handle (any case, an "@" before it) is the pass's: drawn under the shown name -- not an error. const fields = [["its title", sc.title], ...sc.lines.flatMap((l, i) => (isObj(l) ? [[`line ${i}'s speaker`, l.who, l.anonymous === true || (typeof l.who === "string" && set.has(handleKey(l.who)))], [`line ${i}'s time`, l.time]] : []))]; for (const [where, v, flagged] of fields) { if (typeof v !== "string" || !v.trim() || flagged) continue; for (const [n, shown] of names) if (phraseRe(n).test(v)) errors.push(`timeline ${e.id}: screen ${str(sc.id)} ${where} writes ${shown}'s display name -- an anonymous author's: write their handle (a speaker is drawn as "${shown}") or leave it out`); for (const [h, shown] of set) { if (h === "postIds") continue; if (phraseRe(h).test(v)) errors.push(`timeline ${e.id}: screen ${str(sc.id)} ${where} writes ${shown}'s handle -- an anonymous author's: write the handle alone as the speaker (drawn as "${shown}") or leave it out`); } } } const drawn = [...whoOf(e).flatMap((w) => [str(w.text), str(w.paraphrase)]), ...screens.flatMap((sc) => [str(sc.title), ...sc.lines.map((l) => str(l?.text))])].join("\n"); for (const [n, shown] of names) if (phraseRe(n).test(drawn)) warnings.push(`timeline ${e.id}: its words write out ${shown}'s display name -- the card draws words as written: edit them, or redact the name (umtool posts redact)`); if (typeof e.parentShot === "string") warnings.push(`timeline ${e.id}: its captured thread shot is not drawn -- this video has anonymous authors, and a shot may picture them (the card's "Replying to" line stands in)`); } posts.forEach((p, i) => { if (!isObj(p)) return; const s = set.get(handleKey(p.handle)); if (s) warnings.push(`posts[${i}] ${str(p.id)}: by an anonymous author -- drawn as "${s}", without its screenshot and its QR code (both would name them)`); else if (p.thread === true) warnings.push(`posts[${i}] ${str(p.id)}: its thread shot is not drawn -- this video has anonymous authors`); for (const [n, shown] of names) if (phraseRe(n).test(str(p.text))) warnings.push(`posts[${i}] ${str(p.id)}: its words write out ${shown}'s display name`); }); warnings.push(`this video has ${set.size} anonymous author(s): names inside attachments (pictures, receipts, a screenshot's own reply line) are not checked -- they are yours to check`); return { errors, warnings }; }