| 1 | /**
|
|---|
| 2 | * Guardianship (FEP-633c) — note properties.
|
|---|
| 3 | *
|
|---|
| 4 | * The shaer:helpRequest flag (spec 5.2.1): a ward's call for help, only ever
|
|---|
| 5 | * on direct notes. Everyone who does not speak shaer can ignore it.
|
|---|
| 6 | */
|
|---|
| 7 | import { listGuardians } from './relations.js';
|
|---|
| 8 |
|
|---|
| 9 | /**
|
|---|
| 10 | * shaer:hasGuardians (§2.2): an advisory OBJECT hint that the author is a ward,
|
|---|
| 11 | * so a remote server can route interactions to the guardians WITHOUT fetching
|
|---|
| 12 | * the actor. Stamped on every object a ward publishes; MUST be safely ignorable.
|
|---|
| 13 | */
|
|---|
| 14 | export function hasGuardiansProps(slug) {
|
|---|
| 15 | try { return (slug && listGuardians(slug).length) ? { 'shaer:hasGuardians': true } : {}; }
|
|---|
| 16 | catch { return {}; }
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * May EXTERNAL (non-fediverse) embeds be shown to this account?
|
|---|
| 21 | *
|
|---|
| 22 | * A gated feature in the FEP-633c sense: a ward's world outside the fediverse
|
|---|
| 23 | * is the guardians' call. `setting` is `sites.external_embeds`:
|
|---|
| 24 | * null/undefined → auto: off for a ward, on for anyone else
|
|---|
| 25 | * 0 → off, 1 → on (the guardians decided)
|
|---|
| 26 | *
|
|---|
| 27 | * Pure, so the rule is testable on its own. The gate is applied SERVER-side:
|
|---|
| 28 | * a blocked embed is never serialised into the feed, because an embed that the
|
|---|
| 29 | * client merely hides has still been delivered.
|
|---|
| 30 | */
|
|---|
| 31 | export function externalEmbedsAllowed(setting, isWard) {
|
|---|
| 32 | if (setting === 0 || setting === 1) return setting === 1;
|
|---|
| 33 | return !isWard;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | /**
|
|---|
| 37 | * May a player run INSIDE the app/page for this account? The heavier sibling
|
|---|
| 38 | * of the setting above, and deliberately separate: seeing that a video exists
|
|---|
| 39 | * is not the same decision as handing the screen to a third party's player,
|
|---|
| 40 | * with its engine, its end-screen and its next-video machine. Same shape, same
|
|---|
| 41 | * default (off for a ward), and it only ever matters once embeds are allowed:
|
|---|
| 42 | * you cannot play what you may not see.
|
|---|
| 43 | */
|
|---|
| 44 | export function externalPlaybackAllowed(setting, isWard) {
|
|---|
| 45 | if (setting === 0 || setting === 1) return setting === 1;
|
|---|
| 46 | return !isWard;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | /** True when an incoming object carries the ward hint (§2.2). Register-only for
|
|---|
| 50 | * now; acted on later at reddings-boei / escalation routing. */
|
|---|
| 51 | export function objectHasGuardians(o) {
|
|---|
| 52 | return !!o && (o['shaer:hasGuardians'] === true || o.hasGuardians === true);
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | /** Extra JSON-LD properties for an outgoing note built from an ap_outbox row. */
|
|---|
| 56 | export function helpRequestProps(post) {
|
|---|
| 57 | return (post && post.visibility === 'direct' && post.help_request)
|
|---|
| 58 | ? { 'shaer:helpRequest': true }
|
|---|
| 59 | : {};
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | /** True when an incoming (C2S or S2S) note object carries the flag. */
|
|---|
| 63 | export function isHelpRequest(object) {
|
|---|
| 64 | return !!object && (object['shaer:helpRequest'] === true || object.helpRequest === true);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | /** shaer:wave: a gentle "thinking of you" from a guardian to its ward. A
|
|---|
| 68 | * private nudge, never a feed post; non-shaer clients see a plain DM. */
|
|---|
| 69 | export function waveProps(post) {
|
|---|
| 70 | return (post && post.visibility === 'direct' && post.wave)
|
|---|
| 71 | ? { 'shaer:wave': true }
|
|---|
| 72 | : {};
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | /** True when an incoming note is a wave. */
|
|---|
| 76 | export function isWave(object) {
|
|---|
| 77 | return !!object && (object['shaer:wave'] === true || object.wave === true);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | /** shaer:away (3.6.1): a guardian declaring itself away to its ward, with an
|
|---|
| 81 | * end. Rides a direct note like the help request, so a ward on a plain
|
|---|
| 82 | * server reads a human message; endTime is plain AS2. */
|
|---|
| 83 | export function awayProps(post) {
|
|---|
| 84 | return (post && post.visibility === 'direct' && post.away_until)
|
|---|
| 85 | ? { 'shaer:away': true, endTime: new Date(post.away_until).toISOString() }
|
|---|
| 86 | : {};
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | export default { helpRequestProps, isHelpRequest, waveProps, isWave, awayProps, hasGuardiansProps, objectHasGuardians, externalEmbedsAllowed, externalPlaybackAllowed };
|
|---|