fix: default to showing alternate as link to the post object

This commit is contained in:
Julian Lam
2024-04-08 16:08:41 -04:00
parent de83d6b01c
commit 86107535db
2 changed files with 11 additions and 4 deletions

View File

@@ -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',

View File

@@ -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);