feat: save remote post url into hash for use

This commit is contained in:
Julian Lam
2024-04-11 13:25:37 -04:00
parent f5ea470df4
commit 525b7c2cee
4 changed files with 13 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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