@rmdes/indiekit-endpoint-activitypub 2.14.0 → 2.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -2
- package/assets/reader.css +6 -0
- package/lib/controllers/post-detail.js +71 -35
- package/lib/federation-setup.js +8 -17
- package/lib/inbox-handlers.js +82 -1
- package/lib/inbox-listeners.js +48 -1
- package/lib/outbox-failure.js +139 -0
- package/lib/storage/timeline.js +22 -2
- package/package.json +1 -1
- package/views/partials/ap-item-card.njk +3 -0
package/README.md
CHANGED
|
@@ -12,6 +12,28 @@ ActivityPub federation endpoint for [Indiekit](https://getindiekit.com), built o
|
|
|
12
12
|
- Reply delivery — replies are addressed to and delivered directly to the original post's author
|
|
13
13
|
- Shared inbox support with collection sync (FEP-8fcf)
|
|
14
14
|
- Configurable actor type (Person, Service, Organization, Group)
|
|
15
|
+
- Manual follow approval — review and accept/reject follow requests before they take effect
|
|
16
|
+
- Direct messages — private conversations stored separately from the public timeline
|
|
17
|
+
|
|
18
|
+
**Federation Resilience** *(v2.14.0+)*
|
|
19
|
+
- Async inbox queue — inbound activities are persisted to MongoDB before processing, ensuring no data loss on crashes
|
|
20
|
+
- Server blocking — block entire remote servers by domain, rejecting all inbound activities from blocked instances
|
|
21
|
+
- Key freshness tracking — tracks when remote actor keys were last verified, skipping redundant re-fetches
|
|
22
|
+
- Redis-cached actor lookups — caches actor resolution results to reduce network round-trips
|
|
23
|
+
- Delivery strike tracking on `ap_followers` — counts consecutive delivery failures per follower
|
|
24
|
+
- FEP-fe34 security — verifies `proof.created` timestamps to reject replayed activities
|
|
25
|
+
|
|
26
|
+
**Outbox Failure Handling** *(v2.15.0+, inspired by [Hollo](https://github.com/fedify-dev/hollo))*
|
|
27
|
+
- **410 Gone** — immediate full cleanup: removes the follower, their timeline items, and their notifications
|
|
28
|
+
- **404 Not Found** — strike system: 3 consecutive failures over 7+ days triggers the same full cleanup
|
|
29
|
+
- Strike auto-reset — when an actor sends us any activity, their delivery failure count resets to zero
|
|
30
|
+
- Prevents orphaned data from accumulating over time while tolerating temporary server outages
|
|
31
|
+
|
|
32
|
+
**Reply Intelligence** *(v2.15.0+, inspired by [Hollo](https://github.com/fedify-dev/hollo))*
|
|
33
|
+
- Recursive reply chain fetching — when a reply arrives, fetches parent posts up to 5 levels deep for thread context
|
|
34
|
+
- Ancestor posts stored with `isContext: true` flag for thread view without cluttering the main timeline
|
|
35
|
+
- Reply forwarding to followers — when someone replies to our posts, the reply is forwarded to our followers so they see the full conversation
|
|
36
|
+
- Write-time visibility classification — computes `public`/`unlisted`/`private`/`direct` from `to`/`cc` fields at ingest time
|
|
15
37
|
|
|
16
38
|
**Reader**
|
|
17
39
|
- Timeline view showing posts from followed accounts with tab filtering (notes, articles, replies, boosts, media)
|
|
@@ -36,6 +58,8 @@ ActivityPub federation endpoint for [Indiekit](https://getindiekit.com), built o
|
|
|
36
58
|
**Moderation**
|
|
37
59
|
- Mute actors or keywords
|
|
38
60
|
- Block actors (also removes from followers)
|
|
61
|
+
- Block entire servers by domain
|
|
62
|
+
- Report remote actors to their home instance (Flag activity)
|
|
39
63
|
- All moderation actions available from the reader UI
|
|
40
64
|
|
|
41
65
|
**Mastodon Migration**
|
|
@@ -186,6 +210,7 @@ When remote servers send activities to your inbox:
|
|
|
186
210
|
- **Accept(Follow)** → Marks our follow as accepted
|
|
187
211
|
- **Reject(Follow)** → Marks our follow as rejected
|
|
188
212
|
- **Block** → Removes actor from our followers
|
|
213
|
+
- **Flag** → Outbound report sent to remote actor's instance
|
|
189
214
|
|
|
190
215
|
### Content Negotiation
|
|
191
216
|
|
|
@@ -254,7 +279,7 @@ The plugin creates these collections automatically:
|
|
|
254
279
|
|
|
255
280
|
| Collection | Description |
|
|
256
281
|
|---|---|
|
|
257
|
-
| `ap_followers` | Accounts following your actor |
|
|
282
|
+
| `ap_followers` | Accounts following your actor (includes delivery failure strike tracking) |
|
|
258
283
|
| `ap_following` | Accounts you follow |
|
|
259
284
|
| `ap_activities` | Activity log with automatic TTL cleanup |
|
|
260
285
|
| `ap_keys` | RSA and Ed25519 key pairs for HTTP Signatures |
|
|
@@ -262,11 +287,19 @@ The plugin creates these collections automatically:
|
|
|
262
287
|
| `ap_profile` | Actor profile (single document) |
|
|
263
288
|
| `ap_featured` | Pinned/featured posts |
|
|
264
289
|
| `ap_featured_tags` | Featured hashtags |
|
|
265
|
-
| `ap_timeline` | Reader timeline items
|
|
290
|
+
| `ap_timeline` | Reader timeline items (includes `visibility` and `isContext` fields) |
|
|
266
291
|
| `ap_notifications` | Interaction notifications |
|
|
267
292
|
| `ap_muted` | Muted actors and keywords |
|
|
268
293
|
| `ap_blocked` | Blocked actors |
|
|
269
294
|
| `ap_interactions` | Per-post like/boost tracking |
|
|
295
|
+
| `ap_messages` | Direct messages / private conversations |
|
|
296
|
+
| `ap_followed_tags` | Hashtags you follow for timeline filtering |
|
|
297
|
+
| `ap_explore_tabs` | Saved Mastodon instances for the explore view |
|
|
298
|
+
| `ap_reports` | Outbound reports (Flag activities) sent to remote instances |
|
|
299
|
+
| `ap_pending_follows` | Follow requests awaiting manual approval |
|
|
300
|
+
| `ap_blocked_servers` | Blocked server domains (instance-level blocks) |
|
|
301
|
+
| `ap_key_freshness` | Tracks when remote actor keys were last verified |
|
|
302
|
+
| `ap_inbox_queue` | Persistent async inbox processing queue |
|
|
270
303
|
|
|
271
304
|
## Supported Post Types
|
|
272
305
|
|
|
@@ -346,6 +379,16 @@ This is not a bug — Fedify requires explicit opt-in for signed fetches. But it
|
|
|
346
379
|
- **No custom emoji rendering** — Custom emoji shortcodes display as text
|
|
347
380
|
- **In-process queue without Redis** — Activities may be lost on restart
|
|
348
381
|
|
|
382
|
+
## Acknowledgements
|
|
383
|
+
|
|
384
|
+
This plugin builds on the excellent [Fedify](https://fedify.dev) framework by [Hong Minhee](https://github.com/dahlia). Fedify provides the core ActivityPub federation layer — HTTP Signatures, content negotiation, message queues, and the vocabulary types that make all of this possible.
|
|
385
|
+
|
|
386
|
+
Several federation patterns in this plugin were inspired by studying other open-source ActivityPub implementations:
|
|
387
|
+
|
|
388
|
+
- **[Hollo](https://github.com/fedify-dev/hollo)** (by the Fedify author) — A single-user Fedify-based ActivityPub server that served as the primary reference implementation. The outbox permanent failure handling (410 cleanup and 404 strike system), recursive reply chain fetching, reply forwarding to followers, and write-time visibility classification in v2.15.0 are all adapted from Hollo's patterns for a MongoDB/single-user context.
|
|
389
|
+
|
|
390
|
+
- **[Wafrn](https://github.com/gabboman/wafrn)** — A federated social network whose ActivityPub implementation informed the operational resilience patterns added in v2.14.0. Server blocking, key freshness tracking, async inbox processing with persistent queues, and the general approach to federation hardening were inspired by studying Wafrn's production codebase.
|
|
391
|
+
|
|
349
392
|
## License
|
|
350
393
|
|
|
351
394
|
MIT
|
package/assets/reader.css
CHANGED
|
@@ -62,51 +62,87 @@ async function loadParentChain(ctx, documentLoader, timelineCol, parentUrl, maxD
|
|
|
62
62
|
return parents;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
// Load replies
|
|
66
|
-
async function
|
|
67
|
-
|
|
65
|
+
// Load local replies from ap_timeline (items where inReplyTo matches this post)
|
|
66
|
+
async function loadLocalReplies(timelineCol, postUrl, postUid, maxReplies = 20) {
|
|
67
|
+
if (!timelineCol) return [];
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (!repliesCollection) return replies;
|
|
69
|
+
const matchUrls = [postUrl, postUid].filter(Boolean);
|
|
70
|
+
if (matchUrls.length === 0) return [];
|
|
72
71
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
72
|
+
const localReplies = await timelineCol
|
|
73
|
+
.find({ inReplyTo: { $in: matchUrls } })
|
|
74
|
+
.sort({ published: 1 })
|
|
75
|
+
.limit(maxReplies)
|
|
76
|
+
.toArray();
|
|
79
77
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
return localReplies;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Load replies collection (best-effort) — merges local + remote
|
|
82
|
+
async function loadReplies(object, ctx, documentLoader, timelineCol, maxReplies = 20) {
|
|
83
|
+
const postUrl = object?.id?.href || object?.url?.href;
|
|
84
|
+
|
|
85
|
+
// Start with local replies already in our timeline (from organic inbox delivery
|
|
86
|
+
// or reply chain fetching). These are fast and free — no network requests.
|
|
87
|
+
const seenUrls = new Set();
|
|
88
|
+
const replies = await loadLocalReplies(timelineCol, postUrl, postUrl, maxReplies);
|
|
89
|
+
for (const r of replies) {
|
|
90
|
+
if (r.uid) seenUrls.add(r.uid);
|
|
91
|
+
if (r.url) seenUrls.add(r.url);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Supplement with remote replies collection (may contain items we don't have locally)
|
|
95
|
+
if (object && replies.length < maxReplies) {
|
|
96
|
+
try {
|
|
97
|
+
const repliesCollection = await object.getReplies({ documentLoader });
|
|
98
|
+
if (repliesCollection) {
|
|
99
|
+
let items = [];
|
|
100
|
+
try {
|
|
101
|
+
items = await repliesCollection.getItems({ documentLoader });
|
|
102
|
+
} catch {
|
|
103
|
+
// Remote fetch failed — continue with local replies only
|
|
97
104
|
}
|
|
98
105
|
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
for (const replyItem of items.slice(0, maxReplies - replies.length)) {
|
|
107
|
+
try {
|
|
108
|
+
const replyUrl = replyItem.id?.href || replyItem.url?.href;
|
|
109
|
+
if (!replyUrl || seenUrls.has(replyUrl)) continue;
|
|
110
|
+
seenUrls.add(replyUrl);
|
|
111
|
+
|
|
112
|
+
// Check timeline first
|
|
113
|
+
let reply = timelineCol
|
|
114
|
+
? await timelineCol.findOne({
|
|
115
|
+
$or: [{ uid: replyUrl }, { url: replyUrl }],
|
|
116
|
+
})
|
|
117
|
+
: null;
|
|
118
|
+
|
|
119
|
+
if (!reply) {
|
|
120
|
+
// Extract from the item we already have
|
|
121
|
+
if (replyItem instanceof Note || replyItem instanceof Article) {
|
|
122
|
+
reply = await extractObjectData(replyItem);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (reply) {
|
|
127
|
+
replies.push(reply);
|
|
128
|
+
}
|
|
129
|
+
} catch {
|
|
130
|
+
continue; // Skip failed replies
|
|
131
|
+
}
|
|
101
132
|
}
|
|
102
|
-
} catch {
|
|
103
|
-
continue; // Skip failed replies
|
|
104
133
|
}
|
|
134
|
+
} catch {
|
|
135
|
+
// getReplies() failed or not available
|
|
105
136
|
}
|
|
106
|
-
} catch {
|
|
107
|
-
// getReplies() failed or not available
|
|
108
137
|
}
|
|
109
138
|
|
|
139
|
+
// Sort all replies chronologically
|
|
140
|
+
replies.sort((a, b) => {
|
|
141
|
+
const dateA = a.published || "";
|
|
142
|
+
const dateB = b.published || "";
|
|
143
|
+
return dateA < dateB ? -1 : dateA > dateB ? 1 : 0;
|
|
144
|
+
});
|
|
145
|
+
|
|
110
146
|
return replies;
|
|
111
147
|
}
|
|
112
148
|
|
package/lib/federation-setup.js
CHANGED
|
@@ -41,6 +41,7 @@ import { MongoKvStore } from "./kv-store.js";
|
|
|
41
41
|
import { registerInboxListeners } from "./inbox-listeners.js";
|
|
42
42
|
import { jf2ToAS2Activity, resolvePostUrl } from "./jf2-to-as2.js";
|
|
43
43
|
import { cachedQuery } from "./redis-cache.js";
|
|
44
|
+
import { onOutboxPermanentFailure } from "./outbox-failure.js";
|
|
44
45
|
|
|
45
46
|
const COLLECTION_CACHE_TTL = 300; // 5 minutes
|
|
46
47
|
|
|
@@ -342,25 +343,15 @@ export function setupFederation(options) {
|
|
|
342
343
|
});
|
|
343
344
|
|
|
344
345
|
// Handle permanent delivery failures (Fedify 2.0).
|
|
345
|
-
// Fires when a remote inbox returns 404/410
|
|
346
|
-
//
|
|
346
|
+
// Fires when a remote inbox returns 404/410.
|
|
347
|
+
// 410: immediate full cleanup. 404: strike system (3 strikes over 7 days).
|
|
347
348
|
federation.setOutboxPermanentFailureHandler(async (_ctx, values) => {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
(actors.length ? ` (actors: ${actors.join(", ")})` : ""),
|
|
349
|
+
await onOutboxPermanentFailure(
|
|
350
|
+
values.statusCode,
|
|
351
|
+
values.actorIds,
|
|
352
|
+
values.inbox,
|
|
353
|
+
collections,
|
|
354
354
|
);
|
|
355
|
-
collections.ap_activities.insertOne({
|
|
356
|
-
direction: "outbound",
|
|
357
|
-
type: "DeliveryFailed",
|
|
358
|
-
actorUrl: publicationUrl,
|
|
359
|
-
objectUrl: inboxUrl,
|
|
360
|
-
summary: `Permanent delivery failure to ${inboxUrl}: ${error?.message || "unknown"}`,
|
|
361
|
-
affectedActors: actors,
|
|
362
|
-
receivedAt: new Date().toISOString(),
|
|
363
|
-
}).catch(() => {});
|
|
364
355
|
});
|
|
365
356
|
|
|
366
357
|
// Wrap with debug dashboard if enabled. The debugger proxies the
|
package/lib/inbox-handlers.js
CHANGED
|
@@ -152,6 +152,73 @@ function isDirectMessage(object, ourActorUrl, followersUrl) {
|
|
|
152
152
|
return true;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Compute post visibility from to/cc addressing fields.
|
|
157
|
+
* Matches Hollo's write-time visibility classification.
|
|
158
|
+
*
|
|
159
|
+
* @param {object} object - Fedify object (Note, Article, etc.)
|
|
160
|
+
* @returns {"public"|"unlisted"|"private"|"direct"}
|
|
161
|
+
*/
|
|
162
|
+
function computeVisibility(object) {
|
|
163
|
+
const to = new Set((object.toIds || []).map((u) => u.href));
|
|
164
|
+
const cc = new Set((object.ccIds || []).map((u) => u.href));
|
|
165
|
+
|
|
166
|
+
if (to.has(PUBLIC)) return "public";
|
|
167
|
+
if (cc.has(PUBLIC)) return "unlisted";
|
|
168
|
+
// Without knowing the remote actor's followers URL, we can't distinguish
|
|
169
|
+
// "private" (followers-only) from "direct". Both are non-public.
|
|
170
|
+
if (to.size > 0 || cc.size > 0) return "private";
|
|
171
|
+
return "direct";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Recursively fetch and store ancestor posts for a reply chain.
|
|
176
|
+
* Each ancestor is stored with isContext: true so it can be filtered
|
|
177
|
+
* from the main timeline while being available for thread views.
|
|
178
|
+
*
|
|
179
|
+
* @param {object} object - Fedify object (Note, Article, etc.)
|
|
180
|
+
* @param {object} collections - MongoDB collections
|
|
181
|
+
* @param {object} authLoader - Authenticated document loader
|
|
182
|
+
* @param {number} maxDepth - Maximum recursion depth
|
|
183
|
+
*/
|
|
184
|
+
async function fetchReplyChain(object, collections, authLoader, maxDepth) {
|
|
185
|
+
if (maxDepth <= 0) return;
|
|
186
|
+
const parentUrl = object.replyTargetId?.href;
|
|
187
|
+
if (!parentUrl) return;
|
|
188
|
+
|
|
189
|
+
// Skip if we already have this post
|
|
190
|
+
if (collections.ap_timeline) {
|
|
191
|
+
const existing = await collections.ap_timeline.findOne({ uid: parentUrl });
|
|
192
|
+
if (existing) return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Fetch the parent post
|
|
196
|
+
let parent;
|
|
197
|
+
try {
|
|
198
|
+
parent = await object.getReplyTarget({ documentLoader: authLoader });
|
|
199
|
+
} catch {
|
|
200
|
+
// Remote server unreachable — stop climbing
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (!parent || !parent.id) return;
|
|
204
|
+
|
|
205
|
+
// Store as context item
|
|
206
|
+
try {
|
|
207
|
+
const timelineItem = await extractObjectData(parent, {
|
|
208
|
+
documentLoader: authLoader,
|
|
209
|
+
});
|
|
210
|
+
timelineItem.isContext = true;
|
|
211
|
+
timelineItem.visibility = computeVisibility(parent);
|
|
212
|
+
await addTimelineItem(collections, timelineItem);
|
|
213
|
+
} catch {
|
|
214
|
+
// Extraction failed — stop climbing
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Recurse for the parent's parent
|
|
219
|
+
await fetchReplyChain(parent, collections, authLoader, maxDepth - 1);
|
|
220
|
+
}
|
|
221
|
+
|
|
155
222
|
// ---------------------------------------------------------------------------
|
|
156
223
|
// Individual handlers
|
|
157
224
|
// ---------------------------------------------------------------------------
|
|
@@ -515,7 +582,7 @@ export async function handleAnnounce(item, collections, ctx, handle) {
|
|
|
515
582
|
boostedAt: announce.published ? String(announce.published) : new Date().toISOString(),
|
|
516
583
|
documentLoader: authLoader,
|
|
517
584
|
});
|
|
518
|
-
|
|
585
|
+
timelineItem.visibility = computeVisibility(object);
|
|
519
586
|
await addTimelineItem(collections, timelineItem);
|
|
520
587
|
|
|
521
588
|
// Fire-and-forget quote enrichment for boosted posts
|
|
@@ -688,6 +755,18 @@ export async function handleCreate(item, collections, ctx, handle) {
|
|
|
688
755
|
}
|
|
689
756
|
}
|
|
690
757
|
|
|
758
|
+
// --- Recursive reply chain fetching ---
|
|
759
|
+
// Fetch and store ancestor posts so conversation threads have context.
|
|
760
|
+
// Each ancestor is stored with isContext: true to distinguish from organic timeline items.
|
|
761
|
+
if (inReplyTo) {
|
|
762
|
+
try {
|
|
763
|
+
await fetchReplyChain(object, collections, authLoader, 5);
|
|
764
|
+
} catch (error) {
|
|
765
|
+
// Non-critical — incomplete context is acceptable
|
|
766
|
+
console.warn("[inbox-handlers] Reply chain fetch failed:", error.message);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
691
770
|
// Check for mentions of our actor
|
|
692
771
|
if (object.tag) {
|
|
693
772
|
const tags = Array.isArray(object.tag) ? object.tag : [object.tag];
|
|
@@ -728,6 +807,7 @@ export async function handleCreate(item, collections, ctx, handle) {
|
|
|
728
807
|
actorFallback: actorObj,
|
|
729
808
|
documentLoader: authLoader,
|
|
730
809
|
});
|
|
810
|
+
timelineItem.visibility = computeVisibility(object);
|
|
731
811
|
await addTimelineItem(collections, timelineItem);
|
|
732
812
|
|
|
733
813
|
// Fire-and-forget OG unfurling for notes and articles (not boosts)
|
|
@@ -768,6 +848,7 @@ export async function handleCreate(item, collections, ctx, handle) {
|
|
|
768
848
|
actorFallback: actorObj,
|
|
769
849
|
documentLoader: authLoader,
|
|
770
850
|
});
|
|
851
|
+
timelineItem.visibility = computeVisibility(object);
|
|
771
852
|
await addTimelineItem(collections, timelineItem);
|
|
772
853
|
}
|
|
773
854
|
}
|
package/lib/inbox-listeners.js
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
|
|
28
28
|
import { isServerBlocked } from "./storage/server-blocks.js";
|
|
29
29
|
import { touchKeyFreshness } from "./key-refresh.js";
|
|
30
|
+
import { resetDeliveryStrikes } from "./outbox-failure.js";
|
|
30
31
|
import { enqueueActivity } from "./inbox-queue.js";
|
|
31
32
|
import { extractActorInfo } from "./timeline-store.js";
|
|
32
33
|
import { addNotification } from "./storage/notifications.js";
|
|
@@ -53,6 +54,7 @@ export function registerInboxListeners(inboxChain, options) {
|
|
|
53
54
|
const actorUrl = follow.actorId?.href || "";
|
|
54
55
|
if (await isServerBlocked(actorUrl, collections)) return;
|
|
55
56
|
await touchKeyFreshness(collections, actorUrl);
|
|
57
|
+
await resetDeliveryStrikes(collections, actorUrl);
|
|
56
58
|
|
|
57
59
|
const authLoader = await getAuthLoader(ctx);
|
|
58
60
|
const followerActor = await follow.getActor({ documentLoader: authLoader });
|
|
@@ -152,6 +154,7 @@ export function registerInboxListeners(inboxChain, options) {
|
|
|
152
154
|
const actorUrl = undo.actorId?.href || "";
|
|
153
155
|
if (await isServerBlocked(actorUrl, collections)) return;
|
|
154
156
|
await touchKeyFreshness(collections, actorUrl);
|
|
157
|
+
await resetDeliveryStrikes(collections, actorUrl);
|
|
155
158
|
|
|
156
159
|
await enqueueActivity(collections, {
|
|
157
160
|
activityType: "Undo",
|
|
@@ -165,6 +168,7 @@ export function registerInboxListeners(inboxChain, options) {
|
|
|
165
168
|
const actorUrl = accept.actorId?.href || "";
|
|
166
169
|
if (await isServerBlocked(actorUrl, collections)) return;
|
|
167
170
|
await touchKeyFreshness(collections, actorUrl);
|
|
171
|
+
await resetDeliveryStrikes(collections, actorUrl);
|
|
168
172
|
|
|
169
173
|
await enqueueActivity(collections, {
|
|
170
174
|
activityType: "Accept",
|
|
@@ -178,6 +182,7 @@ export function registerInboxListeners(inboxChain, options) {
|
|
|
178
182
|
const actorUrl = reject.actorId?.href || "";
|
|
179
183
|
if (await isServerBlocked(actorUrl, collections)) return;
|
|
180
184
|
await touchKeyFreshness(collections, actorUrl);
|
|
185
|
+
await resetDeliveryStrikes(collections, actorUrl);
|
|
181
186
|
|
|
182
187
|
await enqueueActivity(collections, {
|
|
183
188
|
activityType: "Reject",
|
|
@@ -191,6 +196,7 @@ export function registerInboxListeners(inboxChain, options) {
|
|
|
191
196
|
const actorUrl = like.actorId?.href || "";
|
|
192
197
|
if (await isServerBlocked(actorUrl, collections)) return;
|
|
193
198
|
await touchKeyFreshness(collections, actorUrl);
|
|
199
|
+
await resetDeliveryStrikes(collections, actorUrl);
|
|
194
200
|
|
|
195
201
|
await enqueueActivity(collections, {
|
|
196
202
|
activityType: "Like",
|
|
@@ -205,6 +211,7 @@ export function registerInboxListeners(inboxChain, options) {
|
|
|
205
211
|
const actorUrl = announce.actorId?.href || "";
|
|
206
212
|
if (await isServerBlocked(actorUrl, collections)) return;
|
|
207
213
|
await touchKeyFreshness(collections, actorUrl);
|
|
214
|
+
await resetDeliveryStrikes(collections, actorUrl);
|
|
208
215
|
|
|
209
216
|
await enqueueActivity(collections, {
|
|
210
217
|
activityType: "Announce",
|
|
@@ -219,11 +226,47 @@ export function registerInboxListeners(inboxChain, options) {
|
|
|
219
226
|
const actorUrl = create.actorId?.href || "";
|
|
220
227
|
if (await isServerBlocked(actorUrl, collections)) return;
|
|
221
228
|
await touchKeyFreshness(collections, actorUrl);
|
|
229
|
+
await resetDeliveryStrikes(collections, actorUrl);
|
|
230
|
+
|
|
231
|
+
// Forward public replies to our posts to our followers.
|
|
232
|
+
// Must happen here (not in async handler) because forwardActivity
|
|
233
|
+
// is only available on InboxContext, not base Context.
|
|
234
|
+
const objectUrl = create.objectId?.href || "";
|
|
235
|
+
try {
|
|
236
|
+
const obj = await create.getObject();
|
|
237
|
+
const inReplyTo = obj?.replyTargetId?.href || "";
|
|
238
|
+
if (
|
|
239
|
+
inReplyTo &&
|
|
240
|
+
collections._publicationUrl &&
|
|
241
|
+
inReplyTo.startsWith(collections._publicationUrl)
|
|
242
|
+
) {
|
|
243
|
+
// Check if the reply is public (to/cc includes PUBLIC collection)
|
|
244
|
+
const toUrls = (obj.toIds || []).map((u) => u.href);
|
|
245
|
+
const ccUrls = (obj.ccIds || []).map((u) => u.href);
|
|
246
|
+
const isPublic = [...toUrls, ...ccUrls].includes(
|
|
247
|
+
"https://www.w3.org/ns/activitystreams#Public",
|
|
248
|
+
);
|
|
249
|
+
if (isPublic) {
|
|
250
|
+
await ctx.forwardActivity(
|
|
251
|
+
{ identifier: handle },
|
|
252
|
+
"followers",
|
|
253
|
+
{
|
|
254
|
+
skipIfUnsigned: true,
|
|
255
|
+
preferSharedInbox: true,
|
|
256
|
+
excludeBaseUris: [new URL(ctx.origin)],
|
|
257
|
+
},
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
} catch (error) {
|
|
262
|
+
// Non-critical — forwarding failure shouldn't block processing
|
|
263
|
+
console.warn("[inbox-listeners] Reply forwarding failed:", error.message);
|
|
264
|
+
}
|
|
222
265
|
|
|
223
266
|
await enqueueActivity(collections, {
|
|
224
267
|
activityType: "Create",
|
|
225
268
|
actorUrl,
|
|
226
|
-
objectUrl
|
|
269
|
+
objectUrl,
|
|
227
270
|
rawJson: await create.toJsonLd(),
|
|
228
271
|
});
|
|
229
272
|
})
|
|
@@ -233,6 +276,7 @@ export function registerInboxListeners(inboxChain, options) {
|
|
|
233
276
|
const actorUrl = del.actorId?.href || "";
|
|
234
277
|
if (await isServerBlocked(actorUrl, collections)) return;
|
|
235
278
|
await touchKeyFreshness(collections, actorUrl);
|
|
279
|
+
await resetDeliveryStrikes(collections, actorUrl);
|
|
236
280
|
|
|
237
281
|
await enqueueActivity(collections, {
|
|
238
282
|
activityType: "Delete",
|
|
@@ -247,6 +291,7 @@ export function registerInboxListeners(inboxChain, options) {
|
|
|
247
291
|
const actorUrl = move.actorId?.href || "";
|
|
248
292
|
if (await isServerBlocked(actorUrl, collections)) return;
|
|
249
293
|
await touchKeyFreshness(collections, actorUrl);
|
|
294
|
+
await resetDeliveryStrikes(collections, actorUrl);
|
|
250
295
|
|
|
251
296
|
await enqueueActivity(collections, {
|
|
252
297
|
activityType: "Move",
|
|
@@ -260,6 +305,7 @@ export function registerInboxListeners(inboxChain, options) {
|
|
|
260
305
|
const actorUrl = update.actorId?.href || "";
|
|
261
306
|
if (await isServerBlocked(actorUrl, collections)) return;
|
|
262
307
|
await touchKeyFreshness(collections, actorUrl);
|
|
308
|
+
await resetDeliveryStrikes(collections, actorUrl);
|
|
263
309
|
|
|
264
310
|
await enqueueActivity(collections, {
|
|
265
311
|
activityType: "Update",
|
|
@@ -299,6 +345,7 @@ export function registerInboxListeners(inboxChain, options) {
|
|
|
299
345
|
const actorUrl = flag.actorId?.href || "";
|
|
300
346
|
if (await isServerBlocked(actorUrl, collections)) return;
|
|
301
347
|
await touchKeyFreshness(collections, actorUrl);
|
|
348
|
+
await resetDeliveryStrikes(collections, actorUrl);
|
|
302
349
|
|
|
303
350
|
await enqueueActivity(collections, {
|
|
304
351
|
activityType: "Flag",
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outbox permanent failure handling.
|
|
3
|
+
* Cleans up dead followers when delivery permanently fails.
|
|
4
|
+
*
|
|
5
|
+
* - 410 Gone: Immediate full cleanup (actor is permanently gone)
|
|
6
|
+
* - 404: Strike system — 3 failures over 7+ days triggers full cleanup
|
|
7
|
+
*
|
|
8
|
+
* @module outbox-failure
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { logActivity } from "./activity-log.js";
|
|
12
|
+
|
|
13
|
+
const STRIKE_THRESHOLD = 3;
|
|
14
|
+
const STRIKE_WINDOW_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Clean up all data associated with an actor.
|
|
18
|
+
* Removes follower record, their timeline items, and their notifications.
|
|
19
|
+
*
|
|
20
|
+
* @param {object} collections - MongoDB collections
|
|
21
|
+
* @param {string} actorUrl - Actor URL to clean up
|
|
22
|
+
* @param {string} reason - Reason for cleanup (for logging)
|
|
23
|
+
*/
|
|
24
|
+
async function cleanupActor(collections, actorUrl, reason) {
|
|
25
|
+
const { ap_followers, ap_timeline, ap_notifications } = collections;
|
|
26
|
+
|
|
27
|
+
// Remove from followers
|
|
28
|
+
const deleted = await ap_followers.deleteOne({ actorUrl });
|
|
29
|
+
|
|
30
|
+
// Remove their timeline items
|
|
31
|
+
if (ap_timeline) {
|
|
32
|
+
await ap_timeline.deleteMany({ "author.url": actorUrl });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Remove their notifications
|
|
36
|
+
if (ap_notifications) {
|
|
37
|
+
await ap_notifications.deleteMany({ actorUrl });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (deleted.deletedCount > 0) {
|
|
41
|
+
console.info(`[outbox-failure] Cleaned up actor ${actorUrl}: ${reason}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Handle permanent outbox delivery failure.
|
|
47
|
+
* Called by Fedify's setOutboxPermanentFailureHandler.
|
|
48
|
+
*
|
|
49
|
+
* @param {number} statusCode - HTTP status code (404, 410, etc.)
|
|
50
|
+
* @param {readonly URL[]} actorIds - Array of actor ID URLs
|
|
51
|
+
* @param {URL} inbox - The inbox URL that failed
|
|
52
|
+
* @param {object} collections - MongoDB collections
|
|
53
|
+
*/
|
|
54
|
+
export async function onOutboxPermanentFailure(statusCode, actorIds, inbox, collections) {
|
|
55
|
+
const inboxUrl = inbox?.href || String(inbox);
|
|
56
|
+
|
|
57
|
+
for (const actorId of actorIds) {
|
|
58
|
+
const actorUrl = actorId?.href || String(actorId);
|
|
59
|
+
|
|
60
|
+
if (statusCode === 410) {
|
|
61
|
+
// 410 Gone — immediate full cleanup
|
|
62
|
+
await cleanupActor(collections, actorUrl, `410 Gone from ${inboxUrl}`);
|
|
63
|
+
|
|
64
|
+
await logActivity(collections.ap_activities, {
|
|
65
|
+
direction: "outbound",
|
|
66
|
+
type: "DeliveryFailed:410",
|
|
67
|
+
actorUrl,
|
|
68
|
+
objectUrl: inboxUrl,
|
|
69
|
+
summary: `Permanent delivery failure (410 Gone) to ${inboxUrl} — actor cleaned up`,
|
|
70
|
+
}, {});
|
|
71
|
+
} else {
|
|
72
|
+
// 404 or other — strike system
|
|
73
|
+
const now = new Date();
|
|
74
|
+
const result = await collections.ap_followers.findOneAndUpdate(
|
|
75
|
+
{ actorUrl },
|
|
76
|
+
{
|
|
77
|
+
$inc: { deliveryFailures: 1 },
|
|
78
|
+
$setOnInsert: { firstFailureAt: now.toISOString() },
|
|
79
|
+
$set: { lastFailureAt: now.toISOString() },
|
|
80
|
+
},
|
|
81
|
+
{ returnDocument: "after" },
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (!result) {
|
|
85
|
+
// Not a follower — nothing to track or clean up
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const failures = result.deliveryFailures || 1;
|
|
90
|
+
const firstFailure = result.firstFailureAt
|
|
91
|
+
? new Date(result.firstFailureAt)
|
|
92
|
+
: now;
|
|
93
|
+
const windowElapsed = now.getTime() - firstFailure.getTime() >= STRIKE_WINDOW_MS;
|
|
94
|
+
|
|
95
|
+
if (failures >= STRIKE_THRESHOLD && windowElapsed) {
|
|
96
|
+
// Confirmed dead — full cleanup
|
|
97
|
+
await cleanupActor(
|
|
98
|
+
collections,
|
|
99
|
+
actorUrl,
|
|
100
|
+
`${failures} failures over ${Math.round((now.getTime() - firstFailure.getTime()) / 86400000)}d (HTTP ${statusCode})`,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
await logActivity(collections.ap_activities, {
|
|
104
|
+
direction: "outbound",
|
|
105
|
+
type: `DeliveryFailed:${statusCode}:cleanup`,
|
|
106
|
+
actorUrl,
|
|
107
|
+
objectUrl: inboxUrl,
|
|
108
|
+
summary: `${failures} delivery failures over 7+ days — actor cleaned up`,
|
|
109
|
+
}, {});
|
|
110
|
+
} else {
|
|
111
|
+
// Strike recorded, not yet confirmed dead
|
|
112
|
+
await logActivity(collections.ap_activities, {
|
|
113
|
+
direction: "outbound",
|
|
114
|
+
type: `DeliveryFailed:${statusCode}:strike`,
|
|
115
|
+
actorUrl,
|
|
116
|
+
objectUrl: inboxUrl,
|
|
117
|
+
summary: `Delivery strike ${failures}/${STRIKE_THRESHOLD} for ${actorUrl} (HTTP ${statusCode})`,
|
|
118
|
+
}, {});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Reset delivery failure strikes for an actor.
|
|
126
|
+
* Called when we receive an inbound activity from an actor,
|
|
127
|
+
* proving they are alive despite previous delivery failures.
|
|
128
|
+
*
|
|
129
|
+
* @param {object} collections - MongoDB collections
|
|
130
|
+
* @param {string} actorUrl - Actor URL
|
|
131
|
+
*/
|
|
132
|
+
export async function resetDeliveryStrikes(collections, actorUrl) {
|
|
133
|
+
if (!actorUrl) return;
|
|
134
|
+
// Only update if the fields exist — avoid unnecessary writes
|
|
135
|
+
await collections.ap_followers.updateOne(
|
|
136
|
+
{ actorUrl, deliveryFailures: { $exists: true } },
|
|
137
|
+
{ $unset: { deliveryFailures: "", firstFailureAt: "", lastFailureAt: "" } },
|
|
138
|
+
);
|
|
139
|
+
}
|
package/lib/storage/timeline.js
CHANGED
|
@@ -73,6 +73,18 @@ export async function getTimelineItems(collections, options = {}) {
|
|
|
73
73
|
|
|
74
74
|
const query = {};
|
|
75
75
|
|
|
76
|
+
// Exclude context-only items (ancestors fetched for thread reconstruction)
|
|
77
|
+
// unless explicitly requested via options.includeContext
|
|
78
|
+
if (!options.includeContext) {
|
|
79
|
+
query.isContext = { $ne: true };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Exclude private/direct posts from the main timeline feed —
|
|
83
|
+
// these belong in messages/notifications, not the public reader
|
|
84
|
+
if (!options.includePrivate) {
|
|
85
|
+
query.visibility = { $nin: ["private", "direct"] };
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
// Type filter
|
|
77
89
|
if (options.type) {
|
|
78
90
|
query.type = options.type;
|
|
@@ -252,7 +264,11 @@ export async function countNewItems(collections, after, options = {}) {
|
|
|
252
264
|
const { ap_timeline } = collections;
|
|
253
265
|
if (!after || Number.isNaN(new Date(after).getTime())) return 0;
|
|
254
266
|
|
|
255
|
-
const query = {
|
|
267
|
+
const query = {
|
|
268
|
+
published: { $gt: after },
|
|
269
|
+
isContext: { $ne: true },
|
|
270
|
+
visibility: { $nin: ["private", "direct"] },
|
|
271
|
+
};
|
|
256
272
|
if (options.type) query.type = options.type;
|
|
257
273
|
if (options.excludeReplies) {
|
|
258
274
|
query.$or = [
|
|
@@ -289,5 +305,9 @@ export async function markItemsRead(collections, uids) {
|
|
|
289
305
|
*/
|
|
290
306
|
export async function countUnreadItems(collections) {
|
|
291
307
|
const { ap_timeline } = collections;
|
|
292
|
-
return await ap_timeline.countDocuments({
|
|
308
|
+
return await ap_timeline.countDocuments({
|
|
309
|
+
read: { $ne: true },
|
|
310
|
+
isContext: { $ne: true },
|
|
311
|
+
visibility: { $nin: ["private", "direct"] },
|
|
312
|
+
});
|
|
293
313
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmdes/indiekit-endpoint-activitypub",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.1",
|
|
4
4
|
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"indiekit",
|
|
@@ -65,6 +65,9 @@
|
|
|
65
65
|
</time>
|
|
66
66
|
{% if item.updated %}<span class="ap-card__edited" title="{{ item.updated | date('PPp') }}">✏️</span>{% endif %}
|
|
67
67
|
</a>
|
|
68
|
+
{% if item.visibility and item.visibility != "public" %}
|
|
69
|
+
<span class="ap-card__visibility ap-card__visibility--{{ item.visibility }}" title="{% if item.visibility == 'unlisted' %}{{ __('activitypub.reader.compose.visibilityUnlisted') }}{% elif item.visibility == 'private' %}{{ __('activitypub.reader.compose.visibilityFollowers') }}{% elif item.visibility == 'direct' %}DM{% endif %}">{% if item.visibility == "unlisted" %}🔓{% elif item.visibility == "private" %}🔒{% elif item.visibility == "direct" %}✉️{% endif %}</span>
|
|
70
|
+
{% endif %}
|
|
68
71
|
{% endif %}
|
|
69
72
|
</header>
|
|
70
73
|
|