feat: extend activitypubApi.create.note to accept a post object to reduce unnecessary calls to retrieve post summary

This commit is contained in:
Julian Lam
2024-09-05 10:42:44 -04:00
parent 16c8a6523a
commit b63440cb14
2 changed files with 7 additions and 5 deletions

View File

@@ -144,10 +144,12 @@ async function buildRecipients(object, { pid, uid }) {
}; };
} }
activitypubApi.create.note = enabledCheck(async (caller, { pid }) => { activitypubApi.create.note = enabledCheck(async (caller, { pid, post }) => {
const post = (await posts.getPostSummaryByPids([pid], caller.uid, { stripTags: false })).pop();
if (!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); const allowed = await privileges.posts.can('topics:read', pid, activitypub._constants.uid);

View File

@@ -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 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 response
const result = { const result = {
posts: [postData], posts: [postData],
@@ -123,7 +123,7 @@ topicsAPI.reply = async function (caller, data) {
} }
socketHelpers.notifyNew(caller.uid, 'newPost', result); socketHelpers.notifyNew(caller.uid, 'newPost', result);
activitypubApi.create.note(caller, { pid: postData.pid }); activitypubApi.create.note(caller, { post: postObj[0] });
return postObj[0]; return postObj[0];
}; };