Node.js based forum software built for the modern web
feat: extend activitypubApi.create.note to accept a post object to reduce unnecessary calls to retrieve post summary
Julian Lamb63440cb14af
diff --git a/src/api/activitypub.js b/src/api/activitypub.jsindex 396aa2c1b9..2f23c483fd 100644--- a/src/api/activitypub.js+++ b/src/api/activitypub.js@@ -144,10 +144,12 @@ async function buildRecipients(object, { pid, uid }) {};}-activitypubApi.create.note = enabledCheck(async (caller, { pid }) => {- const post = (await posts.getPostSummaryByPids([pid], caller.uid, { stripTags: false })).pop();+activitypubApi.create.note = enabledCheck(async (caller, { pid, post }) => {if (!post) {- return;+ post = (await posts.getPostSummaryByPids([pid], caller.uid, { stripTags: false })).pop();+ if (!post) {+ return;+ }}const allowed = await privileges.posts.can('topics:read', pid, activitypub._constants.uid);diff --git a/src/api/topics.js b/src/api/topics.jsindex 964d919188..cc761e9542 100644--- a/src/api/topics.js+++ b/src/api/topics.js@@ -107,7 +107,7 @@ topicsAPI.reply = async function (caller, data) {}const postData = await topics.reply(payload); // postData seems to be a subset of postObj, refactor?- const postObj = await posts.getPostSummaryByPids([postData.pid], caller.uid, {});+ const postObj = await posts.getPostSummaryByPids([postData.pid], caller.uid, {}); // standardized API responseconst result = {posts: [postData],@@ -123,7 +123,7 @@ topicsAPI.reply = async function (caller, data) {}socketHelpers.notifyNew(caller.uid, 'newPost', result);- activitypubApi.create.note(caller, { pid: postData.pid });+ activitypubApi.create.note(caller, { post: postObj[0] });return postObj[0];};