From a460a55064e1280f36a0021e0510c7c557251030 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 15 May 2025 15:38:57 -0400 Subject: [PATCH 1/2] fix: bring back auto-categorization if group and object are same-origin, handle Peertube putting channel names in `attributedTo` --- src/activitypub/mocks.js | 7 ++++++- src/activitypub/notes.js | 21 ++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js index 76cc8af01b..e5a8e8e363 100644 --- a/src/activitypub/mocks.js +++ b/src/activitypub/mocks.js @@ -42,7 +42,7 @@ const sanitizeConfig = { Mocks._normalize = async (object) => { // Normalized incoming AP objects into expected types for easier mocking - let { type, attributedTo, url, image, mediaType, content, source, attachment } = object; + let { type, attributedTo, url, image, mediaType, content, source, attachment, cc } = object; switch (true) { // non-string attributedTo handling case Array.isArray(attributedTo): { @@ -52,6 +52,10 @@ Mocks._normalize = async (object) => { } else if (typeof cur === 'object') { if (cur.type === 'Person' && cur.id) { valid.push(cur.id); + } else if (cur.type === 'Group' && cur.id) { + // Add any groups found to cc where it is expected + cc = Array.isArray(cc) ? cc : [cc]; + cc.push(cur.id); } } @@ -148,6 +152,7 @@ Mocks._normalize = async (object) => { return { ...object, + cc, attributedTo, content, sourceContent, diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index 31ca249d3d..616fc3a44f 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -115,18 +115,33 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { if (hasTid) { mainPid = await topics.getTopicField(tid, 'mainPid'); } else { - // Check recipients/audience for local category + // Check recipients/audience for category (local or remote) const set = activitypub.helpers.makeSet(_activitypub, ['to', 'cc', 'audience']); await activitypub.actors.assert(Array.from(set)); + + // Local const resolved = await Promise.all(Array.from(set).map(async id => await activitypub.helpers.resolveLocalId(id))); const recipientCids = resolved .filter(Boolean) .filter(({ type }) => type === 'category') .map(obj => obj.id); - if (recipientCids.length) { + // Remote + let remoteCid; + const assertedGroups = await categories.exists(Array.from(set)); + try { + const { hostname } = new URL(mainPid); + remoteCid = Array.from(set).filter((id, idx) => { + const { hostname: cidHostname } = new URL(id); + return assertedGroups[idx] && cidHostname === hostname; + }).shift(); + } catch (e) { + // noop + } + + if (remoteCid || recipientCids.length) { // Overrides passed-in value, respect addressing from main post over booster - options.cid = recipientCids.shift(); + options.cid = remoteCid || recipientCids.shift(); } // mainPid ok to leave as-is From 8f9f377121d38a1bb4aff121d35236b12bf75ebc Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 15 May 2025 16:57:05 -0400 Subject: [PATCH 2/2] fix: add attachments to getpostsummaries call in search, #13324 --- src/search.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/search.js b/src/search.js index 8e9d947dae..baf4d3c340 100644 --- a/src/search.js +++ b/src/search.js @@ -146,7 +146,9 @@ async function searchInContent(data) { metadata.pids = metadata.pids.slice(start, start + itemsPerPage); } - returnData.posts = await posts.getPostSummaryByPids(metadata.pids, data.uid, {}); + returnData.posts = await posts.getPostSummaryByPids(metadata.pids, data.uid, { + extraFields: ['attachments'], + }); await plugins.hooks.fire('filter:search.contentGetResult', { result: returnData, data: data }); delete metadata.pids; delete metadata.data;