Changeset f278df9 in Klonkt for src/services/ActivityPubService.js
- Timestamp:
- 06/26/2026 07:47:20 AM (2 months ago)
- Branches:
- main
- Children:
- ce0bedf
- Parents:
- 283f618
- File:
-
- 1 edited
-
src/services/ActivityPubService.js (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/services/ActivityPubService.js
r283f618 rf278df9 642 642 // Home timeline (client): a top-level post from an account we follow. 643 643 if (actorUri && !isLocalActor && !o.inReplyTo && o.id) { 644 let subs = []; try { subs = db.prepare('SELECT slug FROM ap_following WHERE actor_uri = ?').all(actorUri); } catch { /* table may not exist yet */ }644 let subs = []; try { subs = db.prepare('SELECT slug, auto_boost FROM ap_following WHERE actor_uri = ?').all(actorUri); } catch { /* table may not exist yet */ } 645 645 if (subs.length) { 646 646 const ai = actorInfo(await resolveActor(actorUri), actorUri); 647 647 const html = HtmlSanitizerService.sanitize(o.content || ''); 648 648 const media = JSON.stringify((Array.isArray(o.attachment) ? o.attachment : []).map((a) => ({ url: safeUrl(a && a.url), type: (a && a.mediaType) || '' })).filter((m) => m.url)); 649 for (const s of subs) tlStmts().ins.run(o.id, s.slug, actorUri, ai.name, ai.handle, ai.icon, ai.url, html, o.url || null, o.published || null, media); 649 for (const s of subs) { 650 tlStmts().ins.run(o.id, s.slug, actorUri, ai.name, ai.handle, ai.icon, ai.url, html, o.url || null, o.published || null, media); 651 // "Feature an artist": auto-boost (re-Announce) their new posts to our own followers. 652 if (s.auto_boost) sendInteraction({ slug: s.slug }, 'boost', o.id, actorUri).catch(() => { /* best-effort */ }); 653 } 650 654 console.log('[AP] timeline +', actorUri, 'x' + subs.length); 651 655 } … … 997 1001 } 998 1002 999 let _insFw, _delFw, _listFw, _accFw, _oneFw ;1003 let _insFw, _delFw, _listFw, _accFw, _oneFw, _setAB; 1000 1004 function fwStmts() { 1001 1005 if (!_insFw) { 1002 _insFw = db.prepare('INSERT OR REPLACE INTO ap_following (slug, actor_uri, handle, name, icon, url, inbox, follow_id, status, created_at) VALUES (?,?,?,?,?,?,?,?,?,CURRENT_TIMESTAMP)');1006 _insFw = db.prepare('INSERT OR REPLACE INTO ap_following (slug, actor_uri, handle, name, icon, url, inbox, follow_id, status, auto_boost, created_at) VALUES (?,?,?,?,?,?,?,?,?,?,CURRENT_TIMESTAMP)'); 1003 1007 _delFw = db.prepare('DELETE FROM ap_following WHERE slug = ? AND actor_uri = ?'); 1004 1008 _listFw = db.prepare('SELECT * FROM ap_following WHERE slug = ? ORDER BY created_at DESC'); 1005 1009 _accFw = db.prepare("UPDATE ap_following SET status = 'accepted' WHERE follow_id = ?"); 1006 1010 _oneFw = db.prepare('SELECT * FROM ap_following WHERE slug = ? AND actor_uri = ?'); 1007 } 1008 return { ins: _insFw, del: _delFw, list: _listFw, acc: _accFw, one: _oneFw }; 1011 _setAB = db.prepare('UPDATE ap_following SET auto_boost = ? WHERE slug = ? AND actor_uri = ?'); 1012 } 1013 return { ins: _insFw, del: _delFw, list: _listFw, acc: _accFw, one: _oneFw, setAB: _setAB }; 1009 1014 } 1010 1015 export function listFollowing(slug) { return fwStmts().list.all(slug); } 1016 1017 // Toggle auto-boost ("feature") on an account we already follow. 1018 export function setAutoBoost(slug, actorUri, on) { 1019 try { fwStmts().setAB.run(on ? 1 : 0, slug, actorUri); } catch { /* ignore */ } 1020 return { ok: true }; 1021 } 1011 1022 1012 1023 let _insTl, _listTl, _delTl; … … 1022 1033 1023 1034 // Follow a fediverse account by @handle (WebFinger → actor → signed Follow). 1024 export async function followActor(site, handle ) {1035 export async function followActor(site, handle, autoBoost = false) { 1025 1036 const base = (process.env.PUBLIC_BASE_URL || '').replace(/\/+$/, ''); 1026 1037 if (!base || !site || !site.slug) return { error: 'config' }; … … 1036 1047 const keys = getOrCreateKeys(site.slug); 1037 1048 const followId = `${me}#follow-${Date.now()}-${rid()}`; 1038 fwStmts().ins.run(site.slug, actor.id, ai.handle, ai.name, ai.icon, ai.url, actor.inbox, followId, 'pending' );1049 fwStmts().ins.run(site.slug, actor.id, ai.handle, ai.name, ai.icon, ai.url, actor.inbox, followId, 'pending', autoBoost ? 1 : 0); 1039 1050 const follow = { '@context': 'https://www.w3.org/ns/activitystreams', id: followId, type: 'Follow', actor: me, object: actor.id }; 1040 1051 try { await deliver(actor.inbox, follow, `${me}#main-key`, keys.private_pem); } … … 1178 1189 getInteractions, getInteractionById, buildReplyNote, getOutboxNote, deliverReply, resolveRemoteNote, 1179 1190 listOutbox, deliverOutboxDelete, 1180 webfingerResolve, followActor, resolveRemoteActor, unfollowActor, listFollowing, getTimeline, sendInteraction,1191 webfingerResolve, followActor, resolveRemoteActor, unfollowActor, listFollowing, setAutoBoost, getTimeline, sendInteraction, 1181 1192 getNotifications, listBlocks, isBlockedAny, blockTarget, unblock, 1182 1193 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)