Node.js based forum software built for the modern web
fix: default to showing alternate as link to the post object
Julian Lam86107535db68
diff --git a/src/controllers/topics.js b/src/controllers/topics.jsindex 1cd83520bd..2ba24d8155 100644--- a/src/controllers/topics.js+++ b/src/controllers/topics.js@@ -137,7 +137,9 @@ topicsController.get = async function getTopic(req, res, next) {if (meta.config.activitypubEnabled) {// Include link header for richer parsing- res.set('Link', `<${nconf.get('url')}/topic/${tid}>; rel="alternate"; type="application/activity+json"`);+ const pid = await topics.getPidByIndex(tid, postIndex);+ const href = utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid;+ res.set('Link', `<${href}>; rel="alternate"; type="application/activity+json"`);}res.render('topic', topicData);@@ -293,9 +295,7 @@ async function addTags(topicData, req, res, currentPage) {}if (meta.config.activitypubEnabled) {- const pid = topicData.postIndex !== 1 ?- (await db.getSortedSetRange(`tid:${topicData.tid}:posts`, topicData.postIndex - 2, topicData.postIndex - 2)).pop() :- topicData.mainPid;+ const pid = await topics.getPidByIndex(topicData.tid, topicData.postIndex);res.locals.linkTags.push({rel: 'alternate',diff --git a/src/topics/index.js b/src/topics/index.jsindex ae3b345768..77573a2154 100644--- a/src/topics/index.js+++ b/src/topics/index.js@@ -313,4 +313,11 @@ Topics.search = async function (tid, term) {return Array.isArray(result) ? result : result.ids;};+Topics.getPidByIndex = async function (tid, index) {+ index -= 2; // zset only stores replies, index is not zero-indexed, so offset by 2.+ return index > 0 ?+ (await db.getSortedSetRange(`tid:${tid}:posts`, index - 2, index - 2)).pop() :+ await Topics.getTopicField(tid, 'mainPid');+};+require('../promisify')(Topics);