fix: auto-created Microsub channel invisible in reader UI

The AP plugin auto-created the Fediverse channel with userId: null,
but the Microsub reader UI filters channels by userId: "default".
The channel existed in MongoDB but was invisible to users.

getApChannelId() now:
- Auto-creates with userId: "default" if no channel exists
- Fixes existing channels missing userId (from earlier versions)
- Uses proper field pattern matching Microsub plugin conventions
This commit is contained in:
Ricardo
2026-02-20 10:00:01 +01:00
parent bd87769ad0
commit 505daa68c5
2 changed files with 42 additions and 4 deletions

View File

@@ -332,16 +332,54 @@ async function logActivity(collections, storeRaw, record) {
let _apChannelId = null;
/**
* Look up the ActivityPub channel's ObjectId (cached after first call).
* Look up (or auto-create) the ActivityPub channel's ObjectId.
* Cached after first successful call.
*
* The channel is created with `userId: "default"` so it appears in the
* Microsub reader UI alongside user-created channels.
*
* @param {object} collections - MongoDB collections
* @returns {Promise<import("mongodb").ObjectId|null>}
*/
async function getApChannelId(collections) {
if (_apChannelId) return _apChannelId;
const channel = await collections.microsub_channels?.findOne({
if (!collections.microsub_channels) return null;
let channel = await collections.microsub_channels.findOne({
uid: "activitypub",
});
_apChannelId = channel?._id || null;
if (!channel) {
// Auto-create the channel with the same fields the Microsub plugin uses
const maxOrderDoc = await collections.microsub_channels
.find({ userId: "default" })
.sort({ order: -1 })
.limit(1)
.toArray();
const order = maxOrderDoc.length > 0 ? maxOrderDoc[0].order + 1 : 0;
const doc = {
uid: "activitypub",
name: "Fediverse",
userId: "default",
order,
settings: { excludeTypes: [], excludeRegex: null },
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};
await collections.microsub_channels.insertOne(doc);
channel = doc;
console.info("[ActivityPub] Auto-created Microsub channel 'Fediverse'");
} else if (!channel.userId) {
// Fix existing channel missing userId (created by earlier version)
await collections.microsub_channels.updateOne(
{ _id: channel._id },
{ $set: { userId: "default" } },
);
console.info("[ActivityPub] Fixed Microsub channel: set userId to 'default'");
}
_apChannelId = channel._id;
return _apChannelId;
}

View File

@@ -1,6 +1,6 @@
{
"name": "@rmdes/indiekit-endpoint-activitypub",
"version": "1.0.16",
"version": "1.0.17",
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
"keywords": [
"indiekit",