@rmdes/indiekit-endpoint-activitypub 1.0.15 → 1.0.17

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.
@@ -120,30 +120,15 @@ export function registerInboxListeners(inboxChain, options) {
120
120
  }
121
121
  })
122
122
  .on(Accept, async (ctx, accept) => {
123
- // Handle Accept(Follow) — remote server accepted our Follow request
123
+ // Handle Accept(Follow) — remote server accepted our Follow request.
124
+ // We don't inspect the inner object type because Fedify often resolves
125
+ // it to a Person (the Follow's target) rather than the Follow itself.
126
+ // Instead, we match directly against ap_following — if we have a
127
+ // pending follow for this actor, any Accept from them confirms it.
124
128
  const actorObj = await accept.getActor();
125
129
  const actorUrl = actorObj?.id?.href || "";
126
130
  if (!actorUrl) return;
127
131
 
128
- // Check if the inner object is a Follow. Some servers send the full
129
- // Follow object, others send only a reference URL that Fedify can't
130
- // resolve (since the original Follow was our outgoing activity).
131
- let isFollow = false;
132
- try {
133
- const inner = await accept.getObject();
134
- isFollow = inner instanceof Follow;
135
- // If inner resolved to a non-Follow activity, skip
136
- if (inner && !isFollow) {
137
- console.info(
138
- `[ActivityPub] Accept from ${actorUrl}: inner is ${inner.constructor?.name}, not Follow — skipping`,
139
- );
140
- return;
141
- }
142
- } catch {
143
- // getObject() failed — proceed anyway if we have a pending follow
144
- }
145
-
146
- // Match against our following list for refollow or microsub-reader follows
147
132
  const result = await collections.ap_following.findOneAndUpdate(
148
133
  {
149
134
  actorUrl,
@@ -347,16 +332,54 @@ async function logActivity(collections, storeRaw, record) {
347
332
  let _apChannelId = null;
348
333
 
349
334
  /**
350
- * Look up the ActivityPub channel's ObjectId (cached after first call).
335
+ * Look up (or auto-create) the ActivityPub channel's ObjectId.
336
+ * Cached after first successful call.
337
+ *
338
+ * The channel is created with `userId: "default"` so it appears in the
339
+ * Microsub reader UI alongside user-created channels.
340
+ *
351
341
  * @param {object} collections - MongoDB collections
352
342
  * @returns {Promise<import("mongodb").ObjectId|null>}
353
343
  */
354
344
  async function getApChannelId(collections) {
355
345
  if (_apChannelId) return _apChannelId;
356
- const channel = await collections.microsub_channels?.findOne({
346
+ if (!collections.microsub_channels) return null;
347
+
348
+ let channel = await collections.microsub_channels.findOne({
357
349
  uid: "activitypub",
358
350
  });
359
- _apChannelId = channel?._id || null;
351
+
352
+ if (!channel) {
353
+ // Auto-create the channel with the same fields the Microsub plugin uses
354
+ const maxOrderDoc = await collections.microsub_channels
355
+ .find({ userId: "default" })
356
+ .sort({ order: -1 })
357
+ .limit(1)
358
+ .toArray();
359
+ const order = maxOrderDoc.length > 0 ? maxOrderDoc[0].order + 1 : 0;
360
+
361
+ const doc = {
362
+ uid: "activitypub",
363
+ name: "Fediverse",
364
+ userId: "default",
365
+ order,
366
+ settings: { excludeTypes: [], excludeRegex: null },
367
+ createdAt: new Date().toISOString(),
368
+ updatedAt: new Date().toISOString(),
369
+ };
370
+ await collections.microsub_channels.insertOne(doc);
371
+ channel = doc;
372
+ console.info("[ActivityPub] Auto-created Microsub channel 'Fediverse'");
373
+ } else if (!channel.userId) {
374
+ // Fix existing channel missing userId (created by earlier version)
375
+ await collections.microsub_channels.updateOne(
376
+ { _id: channel._id },
377
+ { $set: { userId: "default" } },
378
+ );
379
+ console.info("[ActivityPub] Fixed Microsub channel: set userId to 'default'");
380
+ }
381
+
382
+ _apChannelId = channel._id;
360
383
  return _apChannelId;
361
384
  }
362
385
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-activitypub",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
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",