From 4fb6574cf78a859d7dac7124220d77d2c7fb4535 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 7 Feb 2024 14:29:47 -0500 Subject: [PATCH] fix: urls in posts and announces --- public/src/modules/helpers.common.js | 11 +++++++++-- src/activitypub/inbox.js | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.js index ab61734efab6..2c3d35e1a158 100644 --- a/public/src/modules/helpers.common.js +++ b/public/src/modules/helpers.common.js @@ -25,6 +25,7 @@ module.exports = function (utils, Benchpress, relative_path) { userAgentIcons, buildAvatar, increment, + generatePostUrl, generateRepliedTo, generateWrote, isoTimeToLocaleString, @@ -329,18 +330,24 @@ module.exports = function (utils, Benchpress, relative_path) { return String(value + parseInt(inc, 10)); } + function generatePostUrl(post, property = 'pid') { + return utils.isNumber(post[property]) ? `${relative_path}/post/${post[property]}` : post[property]; + } + function generateRepliedTo(post, timeagoCutoff) { const displayname = post.parent && post.parent.displayname ? post.parent.displayname : '[[global:guest]]'; const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs)); const langSuffix = isBeforeCutoff ? 'on' : 'ago'; - return `[[topic:replied-to-user-${langSuffix}, ${post.toPid}, ${relative_path}/post/${post.toPid}, ${displayname}, ${relative_path}/post/${post.pid}, ${post.timestampISO}]]`; + const url = generatePostUrl(post, 'toPid'); + return `[[topic:replied-to-user-${langSuffix}, ${post.toPid}, ${url}, ${displayname}, ${relative_path}/post/${post.pid}, ${post.timestampISO}]]`; } function generateWrote(post, timeagoCutoff) { const isBeforeCutoff = post.timestamp < (Date.now() - (timeagoCutoff * oneDayInMs)); const langSuffix = isBeforeCutoff ? 'on' : 'ago'; - return `[[topic:wrote-${langSuffix}, ${relative_path}/post/${post.pid}, ${post.timestampISO}]]`; + const url = generatePostUrl(post); + return `[[topic:wrote-${langSuffix}, ${url}, ${post.timestampISO}]]`; } function isoTimeToLocaleString(isoTime, locale = 'en-GB') { diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.js index 31ec27ce4655..0ea48737f119 100644 --- a/src/activitypub/inbox.js +++ b/src/activitypub/inbox.js @@ -8,6 +8,7 @@ const user = require('../user'); const posts = require('../posts'); const topics = require('../topics'); const categories = require('../categories'); +const utils = require('../utils'); const activitypub = require('.'); const helpers = require('./helpers'); @@ -115,7 +116,7 @@ inbox.announce = async (req) => { await topics.events.log(tid, { type: 'announce', uid: actor, - href: `/post/${pid}`, + href: utils.isNumber(pid) ? `/post/${pid}` : pid, pid, timestamp, });