Changeset 780a7c6 in Klonkt for src/routes
- Timestamp:
- 07/24/2026 07:44:15 PM (7 weeks ago)
- Branches:
- main
- Children:
- b5924eb
- Parents:
- c26cc18
- Location:
- src/routes
- Files:
-
- 2 edited
-
guardian.js (modified) (3 diffs)
-
posts.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/guardian.js
rc26cc18 r780a7c6 32 32 function uiStrings(L) { 33 33 const keys = ['sent', 'sent_retry', 'sending', 'not_found', 'failed', 'network', 34 'pending', 'active', 'retract', 'release', 'open', 'push_unavailable']; 34 'pending', 'active', 'retract', 'release', 'open', 'push_unavailable', 35 'accept', 'reject', 'complete', 'awaiting_others', 'coguard']; 35 36 return Object.fromEntries(keys.map((k) => [k, i18nT(L, `guardian.${k}`)])); 36 37 } 37 38 38 39 function dashboardState(site, L) { 39 const wards = Guardianship.listWards(site.slug); 40 const base = (process.env.PUBLIC_BASE_URL || '').replace(/\/+$/, ''); 41 const me = AP.actorId(base, site.slug); 40 42 const help = db.prepare( 41 43 `SELECT object_uri, note_url, actor_uri, actor_name, actor_handle, actor_icon, content, published, created_at … … 44 46 return { 45 47 site: site.slug, 46 wards: wards.filter((w) => w.status === 'accepted'), 47 pendingOffers: wards.filter((w) => w.status === 'offered'), 48 me, 49 wards: Guardianship.listWards(site.slug), // committed wards 50 offers: Guardianship.offersCollection(`${me}/queues/offers`, site.slug, me).orderedItems, 48 51 help, 49 52 strings: uiStrings(L), … … 94 97 }); 95 98 96 // ── Manage: retract a pending offer / release a ward ───────────────────── 99 // ── Answer an offer (co-guardian accept/reject, or the candidate's final 100 // "complete"). All three are a C2S Accept/Reject on the offer id; the 101 // handshake module decides when it commits (§3.1). 102 router.post('/offer', requireAuth, express.json({ limit: '4kb' }), async (req, res) => { 103 const site = siteForUser(req); 104 if (!site) return res.status(404).json({ error: 'no_site' }); 105 const offerId = String(req.body?.offer || '').trim(); 106 const answer = req.body?.answer === 'reject' ? 'Reject' : 'Accept'; 107 if (!offerId) return res.status(400).json({ error: 'empty_offer' }); 108 const r = await AP.ingestOutboxActivity(site, req.session.user, { type: answer, object: offerId }); 109 if (!r || r.status >= 400) return res.status(r?.status || 500).json({ error: r?.error || 'answer_failed' }); 110 res.json({ ok: true, committed: !!r.committed, readyToCommit: !!r.readyToCommit }); 111 }); 112 113 // ── Manage: release a committed ward (local Undo; federation is Fase 4). ── 97 114 router.post('/wards/remove', requireAuth, express.json({ limit: '4kb' }), (req, res) => { 98 115 const site = siteForUser(req); -
src/routes/posts.js
rc26cc18 r780a7c6 931 931 return renderPage(req, res, 'partials/messages-append', { items, seen: seenAt, hasMore, nextOffset: offset + FEED_PAGE, moreBase }); 932 932 } 933 // FEP-633c: pending guardianship offers TO this account (ward side) show 934 // as a special message with an accept button (Robins besluit: the kid 935 // answers in their own Klonkt; safety is handled out-of-band by the 936 // guardians themselves). 937 const guardianOffers = site 938 ? Guardianship.listOffers(site.slug).filter((o) => o.role === 'ward') 939 : []; 933 // FEP-633c: pending guardianship offers TO this account (I am the ward) 934 // show as a special message with an accept button (Robins besluit: the kid 935 // answers in its own Klonkt; safety is out-of-band by the guardians). 936 const gBase = (process.env.PUBLIC_BASE_URL || '').replace(/\/+$/, ''); 937 const gMe = site ? ActivityPubService.actorId(gBase, site.slug) : null; 938 const guardianOffers = (site 939 ? Guardianship.offersCollection(`${gMe}/queues/offers`, site.slug, gMe).orderedItems 940 : []).filter((o) => o['shaer:ward'] === gMe && o['shaer:needsMyAccept']); 940 941 renderPage(req, res, 'pages/messages', { 941 942 pageTitleKey: 'msg.title', bodyClass: 'on-special', items, seenAt, … … 951 952 const back = `${res.locals.siteUrlBase || ''}/messages`; 952 953 const answer = req.body.answer === 'accept' ? 'Accept' : (req.body.answer === 'reject' ? 'Reject' : null); 953 const guardian = String(req.body.guardian || '').trim(); 954 if (!site || !answer || !guardian) return res.redirect(back + '?error=guardianship'); 955 const row = Guardianship.getRelation(site.slug, 'ward', guardian); 956 if (!row || row.status !== 'offered') return res.redirect(back + '?error=guardianship'); 954 const offer = String(req.body.offer || '').trim(); 955 if (!site || !answer || !offer) return res.redirect(back + '?error=guardianship'); 957 956 try { 958 const base = (process.env.PUBLIC_BASE_URL || '').replace(/\/+$/, ''); 959 const me = ActivityPubService.actorId(base, site.slug); 960 const r = await Guardianship.handleGuardianshipOutbox(site, { 961 type: answer, 962 object: row.offer_id || { type: 'Relationship', subject: me, relationship: 'shaer:Guardian', object: guardian }, 963 }); 957 // Same C2S Accept/Reject the apps use; the handshake module records the 958 // ward's accept and (once the candidate returns the handle) commits. 959 const r = await ActivityPubService.ingestOutboxActivity(site, req.session.user, { type: answer, object: offer }); 964 960 if (r && r.status < 400) return res.redirect(back + '?success=' + (answer === 'Accept' ? 'guardian_accepted' : 'guardian_rejected')); 965 961 } catch { /* fall through */ }
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)