Changeset bddbfe0 in Klonkt for src/services/ActivityPubService.js
- Timestamp:
- 06/27/2026 12:04:36 PM (2 months ago)
- Branches:
- main
- Children:
- dd7daef
- Parents:
- 7cea873
- File:
-
- 1 edited
-
src/services/ActivityPubService.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/services/ActivityPubService.js
r7cea873 rbddbfe0 1076 1076 1077 1077 // List a site's own outbound fediverse replies (for the manage/delete view). 1078 // The plain editable text of a stored reply (unwrap links → their text, <br> → newline) 1079 // so the manage view can prefill an edit box; the mention is re-added on save. 1080 function outboxEditableText(content) { 1081 return String(content || '') 1082 .replace(/<br\s*\/?>/gi, '\n') 1083 .replace(/<a\b[^>]*>([\s\S]*?)<\/a>/gi, '$1') 1084 .replace(/<[^>]+>/g, '') 1085 .replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&') 1086 .trim(); 1087 } 1078 1088 export function listOutbox(siteSlug) { 1079 1089 return db.prepare('SELECT id, content, to_handle, in_reply_to, created_at FROM ap_outbox WHERE site_slug = ? ORDER BY created_at DESC') 1080 .all(siteSlug).map((r) => ({ ...r, content: stripLeadingMentions(r.content) }));1090 .all(siteSlug).map((r) => { const c = stripLeadingMentions(r.content); return { ...r, content: c, editable: outboxEditableText(c) }; }); 1081 1091 } 1082 1092 … … 1098 1108 db.prepare('DELETE FROM ap_outbox WHERE id = ?').run(outboxId); 1099 1109 return true; 1110 } 1111 1112 // Edit one of our outbound replies: rewrite the stored content (mention re-added + #tags 1113 // re-linked) and send an Update(Note) so recipients refresh their cached copy. 1114 export async function deliverOutboxUpdate(site, outboxId, newText) { 1115 const row = iStmts().getO.get(outboxId); 1116 if (!row || row.site_slug !== site.slug) return false; 1117 const text = String(newText || '').trim(); 1118 if (!text) return false; 1119 const base = (process.env.PUBLIC_BASE_URL || '').replace(/\/+$/, ''); 1120 if (!base) return false; 1121 const me = actorId(base, site.slug); 1122 const mention = row.to_actor 1123 ? `<a href="${escHtml(row.to_actor)}" class="u-url mention">${escHtml(row.to_handle || deriveHandle(row.to_actor))}</a> ` : ''; 1124 const body = escHtml(text).replace(/\r?\n/g, '<br>'); 1125 const content = `<p>${mention}${linkHashtags(base, body)}</p>`; 1126 db.prepare('UPDATE ap_outbox SET content = ? WHERE id = ?').run(content, outboxId); 1127 const note = buildReplyNote(base, site, iStmts().getO.get(outboxId)); 1128 note.updated = new Date().toISOString(); 1129 const update = { 1130 '@context': 'https://www.w3.org/ns/activitystreams', 1131 id: `${note.id}#update-${Date.now()}-${rid()}`, type: 'Update', actor: me, 1132 published: note.published, updated: note.updated, to: note.to, cc: note.cc, object: note, 1133 }; 1134 const keys = getOrCreateKeys(site.slug); 1135 const inboxes = new Set(); 1136 if (row.to_actor) { const a = await fetchActor(row.to_actor).catch(() => null); if (a) inboxes.add((a.endpoints && a.endpoints.sharedInbox) || a.inbox); } 1137 for (const f of fStmts().list.all(site.slug)) inboxes.add(f.shared_inbox || f.inbox); 1138 inboxes.delete(`${me}/inbox`); inboxes.delete(`${base}/ap/inbox`); 1139 let delivered = 0; 1140 for (const inbox of [...inboxes].filter(Boolean)) { 1141 try { const st = await deliver(inbox, update, `${me}#main-key`, keys.private_pem); if (st >= 200 && st < 300) delivered++; } catch { /* best-effort */ } 1142 } 1143 console.log('[AP] outreply edit', site.slug, 'delivered', delivered); 1144 return { ok: true, content, delivered }; 1100 1145 } 1101 1146 … … 1453 1498 followerCount, deliver, fetchActor, verifyRequest, handleInbox, deliverCreate, deliverDelete, deliverUpdate, deliverActorUpdate, resyncFeaturedPins, 1454 1499 getInteractions, getInteractionById, setInteractionBoosted, setInteractionLiked, setMyReaction, getMyReactions, buildReplyNote, getOutboxNote, deliverReply, resolveRemoteNote, 1455 listOutbox, deliverOutboxDelete, 1500 listOutbox, deliverOutboxDelete, deliverOutboxUpdate, 1456 1501 webfingerResolve, followActor, resolveRemoteActor, unfollowActor, listFollowing, setAutoBoost, getTimeline, sendInteraction, 1457 1502 autoBoostCount, boostedCount, markBoosted, unmarkBoosted, markLiked, unmarkLiked, getTimelineReaction, upsertBoostedNote, getCirkelPosts, getCirkelMembers, selfHealTimeline,
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)