| 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 | /** True when an incoming object carries the ward hint (§2.2). Register-only for
|
|---|
| 20 | * now; acted on later at reddings-boei / escalation routing. */
|
|---|
| 21 | export function objectHasGuardians(o) {
|
|---|
| 22 | return !!o && (o['shaer:hasGuardians'] === true || o.hasGuardians === true);
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | /** Extra JSON-LD properties for an outgoing note built from an ap_outbox row. */
|
|---|
| 26 | export function helpRequestProps(post) {
|
|---|
| 27 | return (post && post.visibility === 'direct' && post.help_request)
|
|---|
| 28 | ? { 'shaer:helpRequest': true }
|
|---|
| 29 | : {};
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | /** True when an incoming (C2S or S2S) note object carries the flag. */
|
|---|
| 33 | export function isHelpRequest(object) {
|
|---|
| 34 | return !!object && (object['shaer:helpRequest'] === true || object.helpRequest === true);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | /** shaer:wave: a gentle "thinking of you" from a guardian to its ward. A
|
|---|
| 38 | * private nudge, never a feed post; non-shaer clients see a plain DM. */
|
|---|
| 39 | export function waveProps(post) {
|
|---|
| 40 | return (post && post.visibility === 'direct' && post.wave)
|
|---|
| 41 | ? { 'shaer:wave': true }
|
|---|
| 42 | : {};
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | /** True when an incoming note is a wave. */
|
|---|
| 46 | export function isWave(object) {
|
|---|
| 47 | return !!object && (object['shaer:wave'] === true || object.wave === true);
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | export default { helpRequestProps, isHelpRequest, waveProps, isWave, hasGuardiansProps, objectHasGuardians };
|
|---|