From f67942caecbefab7f062379f653615f33b074b2f Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 15 Sep 2025 13:53:27 -0400 Subject: [PATCH] fix: local pids not always converted to absolute URLs on topic actor controller --- src/controllers/activitypub/actors.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/controllers/activitypub/actors.js b/src/controllers/activitypub/actors.js index 0f7a348990..850585e379 100644 --- a/src/controllers/activitypub/actors.js +++ b/src/controllers/activitypub/actors.js @@ -136,6 +136,7 @@ Actors.topic = async function (req, res, next) { let collection; let pids; try { + // pids are used in generation of digest only. ([collection, pids] = await Promise.all([ activitypub.helpers.generateCollection({ set: `tid:${req.params.tid}:posts`, @@ -151,7 +152,6 @@ Actors.topic = async function (req, res, next) { } pids.push(mainPid); pids = pids.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid)); - collection.totalItems += 1; // account for mainPid // Generate digest for ETag const digest = activitypub.helpers.generateDigest(new Set(pids)); @@ -168,15 +168,18 @@ Actors.topic = async function (req, res, next) { } res.set('ETag', digest); - // Convert pids to urls + // Add OP to collection on first (or only) page if (page || collection.totalItems < perPage) { collection.orderedItems = collection.orderedItems || []; - if (!page || page === 1) { // add OP to collection + if (!page || page === 1) { collection.orderedItems.unshift(mainPid); + collection.totalItems += 1; } - collection.orderedItems = collection.orderedItems.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid)); } + // Convert pids to urls + collection.orderedItems = collection.orderedItems.map(pid => (utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid)); + const object = { '@context': 'https://www.w3.org/ns/activitystreams', id: `${nconf.get('url')}/topic/${req.params.tid}${collection.orderedItems && page ? `?page=${page}` : ''}`,