| [6b5d7da] | 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 | */
|
|---|
| [af5b79b] | 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 |
|
|---|
| [fc40410] | 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 |
|
|---|
| [af5b79b] | 36 | /** True when an incoming object carries the ward hint (§2.2). Register-only for
|
|---|
| 37 | * now; acted on later at reddings-boei / escalation routing. */
|
|---|
| 38 | export function objectHasGuardians(o) {
|
|---|
| 39 | return !!o && (o['shaer:hasGuardians'] === true || o.hasGuardians === true);
|
|---|
| 40 | }
|
|---|
| [6b5d7da] | 41 |
|
|---|
| 42 | /** Extra JSON-LD properties for an outgoing note built from an ap_outbox row. */
|
|---|
| 43 | export function helpRequestProps(post) {
|
|---|
| 44 | return (post && post.visibility === 'direct' && post.help_request)
|
|---|
| 45 | ? { 'shaer:helpRequest': true }
|
|---|
| 46 | : {};
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | /** True when an incoming (C2S or S2S) note object carries the flag. */
|
|---|
| 50 | export function isHelpRequest(object) {
|
|---|
| 51 | return !!object && (object['shaer:helpRequest'] === true || object.helpRequest === true);
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| [e62f65d] | 54 | /** shaer:wave: a gentle "thinking of you" from a guardian to its ward. A
|
|---|
| 55 | * private nudge, never a feed post; non-shaer clients see a plain DM. */
|
|---|
| 56 | export function waveProps(post) {
|
|---|
| 57 | return (post && post.visibility === 'direct' && post.wave)
|
|---|
| 58 | ? { 'shaer:wave': true }
|
|---|
| 59 | : {};
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | /** True when an incoming note is a wave. */
|
|---|
| 63 | export function isWave(object) {
|
|---|
| 64 | return !!object && (object['shaer:wave'] === true || object.wave === true);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| [fc40410] | 67 | export default { helpRequestProps, isHelpRequest, waveProps, isWave, hasGuardiansProps, objectHasGuardians, externalEmbedsAllowed };
|
|---|