Changeset 78b6d8a in Klonkt for src/services/ActivityPubService.js
- Timestamp:
- 06/26/2026 12:16:33 PM (2 months ago)
- Branches:
- main
- Children:
- 4c47eff
- Parents:
- 3384e95
- File:
-
- 1 edited
-
src/services/ActivityPubService.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/services/ActivityPubService.js
r3384e95 r78b6d8a 1073 1073 } 1074 1074 // Mark a timeline post as boosted so it shows in the Cirkel (mixed by date). 1075 let _markBoost, _ boostedCount;1075 let _markBoost, _unmarkBoost, _boostedCount; 1076 1076 export function markBoosted(slug, noteId) { 1077 1077 try { if (!_markBoost) _markBoost = db.prepare('UPDATE ap_timeline SET boosted = 1 WHERE slug = ? AND id = ?'); _markBoost.run(slug, noteId); } catch { /* ignore */ } 1078 } 1079 export function unmarkBoosted(slug, noteId) { 1080 try { if (!_unmarkBoost) _unmarkBoost = db.prepare('UPDATE ap_timeline SET boosted = 0 WHERE slug = ? AND id = ?'); _unmarkBoost.run(slug, noteId); } catch { /* ignore */ } 1078 1081 } 1079 1082 export function boostedCount(slug) { … … 1226 1229 const base = (process.env.PUBLIC_BASE_URL || '').replace(/\/+$/, ''); 1227 1230 if (!base || !site || !site.slug || !targetNoteId) return { error: 'config' }; 1228 const type = kind === 'boost' ? 'Announce' : 'Like';1229 1231 const me = actorId(base, site.slug); 1230 1232 const keys = getOrCreateKeys(site.slug); 1231 const act = { 1232 '@context': 'https://www.w3.org/ns/activitystreams', 1233 id: `${me}#${type.toLowerCase()}-${Date.now()}-${rid()}`, 1234 type, actor: me, object: targetNoteId, 1235 }; 1236 if (type === 'Announce') { act.to = [PUBLIC]; act.cc = [`${me}/followers`]; } 1233 // 'unboost' = Undo(Announce): retracts a boost so followers' servers remove the 1234 // reblog (matched on actor+object — no record of the original Announce needed). 1235 const fanout = (kind === 'boost' || kind === 'unboost'); // also goes to our followers 1236 let act; 1237 if (kind === 'unboost') { 1238 act = { 1239 '@context': 'https://www.w3.org/ns/activitystreams', 1240 id: `${me}#undo-${Date.now()}-${rid()}`, type: 'Undo', actor: me, 1241 to: [PUBLIC], cc: [`${me}/followers`], 1242 object: { id: `${me}#announce-${Date.now()}-${rid()}`, type: 'Announce', actor: me, object: targetNoteId }, 1243 }; 1244 } else { 1245 const type = kind === 'boost' ? 'Announce' : 'Like'; 1246 act = { 1247 '@context': 'https://www.w3.org/ns/activitystreams', 1248 id: `${me}#${type.toLowerCase()}-${Date.now()}-${rid()}`, 1249 type, actor: me, object: targetNoteId, 1250 }; 1251 if (type === 'Announce') { act.to = [PUBLIC]; act.cc = [`${me}/followers`]; } 1252 } 1237 1253 const inboxes = new Set(); 1238 1254 if (authorUri) { const a = await fetchActor(authorUri).catch(() => null); if (a) inboxes.add((a.endpoints && a.endpoints.sharedInbox) || a.inbox); } 1239 // A boost is public → also deliver to our own followers so it shows for them. 1240 if (type === 'Announce') { for (const f of fStmts().list.all(site.slug)) inboxes.add(f.shared_inbox || f.inbox); } 1255 if (fanout) { for (const f of fStmts().list.all(site.slug)) inboxes.add(f.shared_inbox || f.inbox); } 1241 1256 let delivered = 0; 1242 1257 for (const inbox of [...inboxes].filter(Boolean)) { try { const st = await deliver(inbox, act, `${me}#main-key`, keys.private_pem); if (st >= 200 && st < 300) delivered++; } catch { /* best-effort */ } } 1243 console.log('[AP]', type, site.slug, '→', targetNoteId, 'delivered', delivered);1258 console.log('[AP]', kind, site.slug, '→', targetNoteId, 'delivered', delivered); 1244 1259 return { ok: true, delivered }; 1245 1260 } … … 1356 1371 listOutbox, deliverOutboxDelete, 1357 1372 webfingerResolve, followActor, resolveRemoteActor, unfollowActor, listFollowing, setAutoBoost, getTimeline, sendInteraction, 1358 autoBoostCount, boostedCount, markBoosted, getCirkelPosts, getCirkelMembers, autoMigrateCircles, selfHealTimeline, boostLatestN,1373 autoBoostCount, boostedCount, markBoosted, unmarkBoosted, getCirkelPosts, getCirkelMembers, autoMigrateCircles, selfHealTimeline, boostLatestN, 1359 1374 getNotifications, listBlocks, isBlockedAny, blockTarget, unblock, 1360 1375 deliverWithRetry, enqueueDelivery, processDeliveryQueue, startDeliveryWorker,
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)