Changeset 8878814 in Klonkt for src/services/ActivityPubService.js
- Timestamp:
- 07/16/2026 12:20:51 PM (8 weeks ago)
- Branches:
- main
- Children:
- 2d6a9c3
- Parents:
- 72f936a
- git-author:
- Robin <roboburr@…> (07/12/2026 11:43:58 PM)
- git-committer:
- Robin <roboburr@…> (07/16/2026 12:20:51 PM)
- File:
-
- 1 edited
-
src/services/ActivityPubService.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/services/ActivityPubService.js
r72f936a r8878814 524 524 export function followerCount(slug) { return fStmts().cnt.get(slug).n; } 525 525 526 // Followers with delivery health, for the management list. Never-delivered accounts 527 // first, then oldest successful delivery first — i.e. the cleanup candidates on top. 528 export function listFollowers(slug) { 529 return db.prepare( 530 `SELECT id, actor_uri, inbox, shared_inbox, created_at, last_delivery_at, last_error_at 531 FROM ap_followers WHERE slug = ? 532 ORDER BY (last_delivery_at IS NULL) DESC, last_delivery_at ASC, created_at ASC` 533 ).all(slug); 534 } 535 // Manually drop a follower after a check (a still-live account would have to re-follow). 536 export function removeFollower(slug, id) { 537 const info = db.prepare('DELETE FROM ap_followers WHERE slug = ? AND id = ?').run(slug, id); 538 return info.changes > 0; 539 } 540 526 541 // ── inbound interactions store (replies / likes / boosts) + our outbound replies ── 527 542 let _insI, _delLA, _delReply, _listI, _getI, _insO, _listO, _getO; … … 724 739 try { deliveryStmts().ins.run(slug, inbox, JSON.stringify(activity)); } catch { /* ignore */ } 725 740 } 741 // Record delivery health per follower so the followers list can flag dead accounts. 742 // Keyed by inbox: a shared-inbox POST reaches every follower behind it, so all of them 743 // are marked. A non-follower inbox (inline @mention) simply matches 0 rows. 744 let _fDelivOk, _fDelivErr; 745 function markFollowerDelivery(slug, inbox, ok) { 746 if (!slug || !inbox) return; 747 try { 748 if (!_fDelivOk) { 749 _fDelivOk = db.prepare('UPDATE ap_followers SET last_delivery_at = CURRENT_TIMESTAMP WHERE slug = ? AND (inbox = ? OR shared_inbox = ?)'); 750 _fDelivErr = db.prepare('UPDATE ap_followers SET last_error_at = CURRENT_TIMESTAMP WHERE slug = ? AND (inbox = ? OR shared_inbox = ?)'); 751 } 752 (ok ? _fDelivOk : _fDelivErr).run(slug, inbox, inbox); 753 } catch { /* health tracking is non-fatal */ } 754 } 726 755 // Deliver now; queue for retry if it fails. 727 756 export async function deliverWithRetry(slug, inbox, activity, keyId, privPem) { 728 757 if (!inbox) return; 729 try { const st = await deliver(inbox, activity, keyId, privPem); if (st >= 200 && st < 300) return;} catch { /* queue below */ }758 try { const st = await deliver(inbox, activity, keyId, privPem); if (st >= 200 && st < 300) { markFollowerDelivery(slug, inbox, true); return; } } catch { /* queue below */ } 730 759 enqueueDelivery(slug, inbox, activity); 731 760 } … … 746 775 ok = st >= 200 && st < 300; 747 776 } catch { ok = false; } 748 if (ok) { deliveryStmts().del.run(row.id); continue; }777 if (ok) { markFollowerDelivery(row.slug, row.inbox, true); deliveryStmts().del.run(row.id); continue; } 749 778 const attempts = row.attempts + 1; 750 if (attempts >= DELIVERY_MAX_ATTEMPTS) { deliveryStmts().del.run(row.id); console.warn('[AP] delivery gave up after', attempts, 'tries →', row.inbox); continue; }779 if (attempts >= DELIVERY_MAX_ATTEMPTS) { markFollowerDelivery(row.slug, row.inbox, false); deliveryStmts().del.run(row.id); console.warn('[AP] delivery gave up after', attempts, 'tries →', row.inbox); continue; } 751 780 // Index the backoff on the CURRENT attempt count (row.attempts) so the first 752 781 // retry uses the 1-min tier instead of skipping it. … … 2434 2463 deliverWithRetry, enqueueDelivery, processDeliveryQueue, startDeliveryWorker, 2435 2464 getReplyUris, markNotificationsSeen, countUnseenNotifications, hasPlayableAudio, 2436 linkifyBody, 2465 linkifyBody, listFollowers, removeFollower, 2437 2466 };
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)