Changeset 780a7c6 in Klonkt for src/services/ActivityPubService.js
- Timestamp:
- 07/24/2026 07:44:15 PM (7 weeks ago)
- Branches:
- main
- Children:
- b5924eb
- Parents:
- c26cc18
- File:
-
- 1 edited
-
src/services/ActivityPubService.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/services/ActivityPubService.js
rc26cc18 r780a7c6 1320 1320 // guardianship module does not recognize falls through to the old paths. 1321 1321 if (type === 'Offer' || type === 'Accept' || type === 'Reject') { 1322 let gslug = slugParam || null; 1323 if (!gslug && type === 'Offer') { 1322 // Every LOCAL party this activity is addressed to gets its own copy of the 1323 // handshake (a ward and a co-guardian may both live here). Gather candidate 1324 // local slugs from the inbox owner, the `to` list, and the ward. 1325 const cand = new Set(); 1326 if (slugParam) cand.add(slugParam); 1327 for (const t of (Array.isArray(act.to) ? act.to : (act.to ? [act.to] : []))) { 1328 if (typeof t === 'string') { const s = slugFromActorUrl(t); if (s) cand.add(s); } 1329 } 1330 if (type === 'Offer') { 1324 1331 const rel = Guardianship.parseRelationship(act.object); 1325 if (rel) gslug = slugFromActorUrl(rel.ward); 1326 } 1327 if (!gslug) { 1328 const offerId = typeof act.object === 'string' ? act.object : (act.object && act.object.id); 1329 const rows = offerId ? Guardianship.findByOfferId?.(offerId) || [] : []; 1330 if (rows.length) gslug = rows[0].slug; 1331 if (!gslug) for (const t of (Array.isArray(act.to) ? act.to : (act.to ? [act.to] : []))) { 1332 const s = slugFromActorUrl(t); if (s) { gslug = s; break; } 1333 } 1334 } 1335 if (gslug) { 1336 const gsite = db.prepare('SELECT * FROM sites WHERE slug = ?').get(gslug); 1337 if (gsite && await Guardianship.handleGuardianshipInbox(gsite, act).catch(() => false)) { 1338 console.log('[AP] guardianship', type, 'for', gslug, 'from', claimedActor); 1339 return 202; 1340 } 1341 } 1332 if (rel) { const s = slugFromActorUrl(rel.ward); if (s) cand.add(s); } 1333 } 1334 let consumed = false; 1335 for (const slug of cand) { 1336 const gsite = db.prepare('SELECT * FROM sites WHERE slug = ?').get(slug); 1337 if (gsite && await Guardianship.handleGuardianshipInbox(gsite, act).catch(() => false)) consumed = true; 1338 } 1339 if (consumed) { console.log('[AP] guardianship', type, 'from', claimedActor); return 202; } 1342 1340 } 1343 1341 … … 3156 3154 buildReplyNote, AP_CONTEXT, getOrCreateKeys, deliver, enqueueDelivery, 3157 3155 }); 3156 // Which local site (if any) hosts this actor URI — used by the handshake to 3157 // apply the local side of a commit and to derive a ward's existing guardians. 3158 function localSlugOf(actorUri) { 3159 const base = (process.env.PUBLIC_BASE_URL || '').replace(/\/+$/, ''); 3160 if (!actorUri || !actorUri.startsWith(`${base}/ap/users/`)) return null; 3161 const slug = slugFromActorUrl(actorUri); 3162 if (!slug) return null; 3163 try { return db.prepare('SELECT slug FROM sites WHERE slug = ?').get(slug) ? slug : null; } 3164 catch { return null; } 3165 } 3158 3166 Guardianship.wireHandshake({ 3159 3167 selfId: selfActorId, 3168 localSlug: localSlugOf, 3160 3169 deliverTo: deliverToActor, 3161 3170 deriveHandle, 3162 // Guardian PWA push: an offer or an answer lands as a notification. 3171 fetchActor, 3172 // Guardian PWA / Berichten push. The kid answers an incoming offer in its 3173 // own Berichten; an existing guardian and a commit land in the PWA. 3163 3174 onEvent: (slug, ev) => { 3164 3175 const L = pushLang(slug); 3165 3176 const texts = { 3166 offer_received: ['push.n_guard_offer_t', 'push.n_guard_offer_b'], 3167 ward_accepted: ['push.n_guard_ward_t', 'push.n_guard_ward_b'], 3177 offer_received: ['push.n_guard_offer_t', 'push.n_guard_offer_b'], // I am the ward 3178 offer_for_ward: ['push.n_guard_cog_t', 'push.n_guard_cog_b'], // I co-guard this ward 3179 committed: ['push.n_guard_ward_t', 'push.n_guard_ward_b'], 3168 3180 }[ev.kind]; 3169 3181 if (!texts) return; 3170 3182 const who = deriveHandle(ev.candidate || ev.ward || ev.guardian || '') || '?'; 3171 // An offer is answered in the kid's own Berichten; a ward's accept lands3172 // in the guardian's PWA.3173 3183 const url = ev.kind === 'offer_received' ? `${pushPrefix(slug)}/messages` : '/guardian'; 3174 3184 pushEvent(slug, { type: 'guardian', title: i18nT(L, texts[0]), body: i18nT(L, texts[1], { who }), url });
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)