Skip to content

Node.js based forum software built for the modern web

feat: save remote post url into hash for use

Julian Lam525b7c2ceefc
diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js
index f24c995f53..f9bcad3f2b 100644
--- a/src/activitypub/mocks.js
+++ b/src/activitypub/mocks.js
@@ -85,6 +85,7 @@ Mocks.post = async (objects) => {
let {
id: pid,
+ url,
attributedTo: uid,
inReplyTo: toPid,
published, updated, name, content, sourceContent,
@@ -112,7 +113,7 @@ Mocks.post = async (objects) => {
edited,
editor: edited ? uid : undefined,
- _activitypub: { to, cc, attachment, tag },
+ _activitypub: { to, cc, attachment, tag, url },
};
return payload;
diff --git a/src/posts/create.js b/src/posts/create.js
index b67fb56573..d38aec356e 100644
--- a/src/posts/create.js
+++ b/src/posts/create.js
@@ -44,6 +44,9 @@ module.exports = function (Posts) {
if (data.handle && !parseInt(uid, 10)) {
postData.handle = data.handle;
}
+ if (_activitypub.url) {
+ postData.url = _activitypub.url;
+ }
({ post: postData } = await plugins.hooks.fire('filter:post.create', { post: postData, data: data }));
await db.setObject(`post:${postData.pid}`, postData);
diff --git a/src/posts/summary.js b/src/posts/summary.js
index 6865372cef..fc39428c83 100644
--- a/src/posts/summary.js
+++ b/src/posts/summary.js
@@ -3,6 +3,7 @@
const validator = require('validator');
const _ = require('lodash');
+const nconf = require('nconf');
const topics = require('../topics');
const user = require('../user');
@@ -20,7 +21,7 @@ module.exports = function (Posts) {
options.parse = options.hasOwnProperty('parse') ? options.parse : true;
options.extraFields = options.hasOwnProperty('extraFields') ? options.extraFields : [];
- const fields = ['pid', 'tid', 'toPid', 'content', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields);
+ const fields = ['pid', 'tid', 'toPid', 'url', 'content', 'uid', 'timestamp', 'deleted', 'upvotes', 'downvotes', 'replies', 'handle'].concat(options.extraFields);
let posts = await Posts.getPostsFields(pids, fields);
posts = posts.filter(Boolean);
@@ -56,6 +57,11 @@ module.exports = function (Posts) {
post.isMainPost = post.topic && post.pid === post.topic.mainPid;
post.deleted = post.deleted === 1;
post.timestampISO = utils.toISOString(post.timestamp);
+
+ // url only applies to remote posts; assume permalink otherwise
+ if (utils.isNumber(post.pid)) {
+ post.url = `${nconf.get('url')}/post/${post.pid}`;
+ }
});
posts = posts.filter(post => tidToTopic[post.tid]);
diff --git a/src/socket.io/posts/tools.js b/src/socket.io/posts/tools.js
index f156ff82f2..a2dc02e27a 100644
--- a/src/socket.io/posts/tools.js
+++ b/src/socket.io/posts/tools.js
@@ -19,7 +19,7 @@ module.exports = function (SocketPosts) {
}
const cid = await posts.getCidByPid(data.pid);
const results = await utils.promiseParallel({
- posts: posts.getPostFields(data.pid, ['deleted', 'bookmarks', 'uid', 'ip', 'flagId']),
+ posts: posts.getPostFields(data.pid, ['deleted', 'bookmarks', 'uid', 'ip', 'flagId', 'url']),
isAdmin: user.isAdministrator(socket.uid),
isGlobalMod: user.isGlobalModerator(socket.uid),
isModerator: user.isModerator(socket.uid, cid),