Node.js based forum software built for the modern web
fix: handle remote objects reporting a local context, #14188
Julian Lamffab31bd6291
diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.jsindex 5dff8c0b00..b36f18166b 100644--- a/src/activitypub/helpers.js+++ b/src/activitypub/helpers.js@@ -197,6 +197,9 @@ Helpers.resolveLocalId = async (input) => {case 'post':return { type: 'post', id: value, ...activityData };+ case 'topic':+ return { type: 'topic', id: value, ...activityData };+case 'cid':case 'category':return { type: 'category', id: value, ...activityData };diff --git a/src/activitypub/notes.js b/src/activitypub/notes.jsindex 3ca30b7aa5..582832bcc1 100644--- a/src/activitypub/notes.js+++ b/src/activitypub/notes.js@@ -82,18 +82,33 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {const { tid } = context;return { tid, count: 0 };} else if (context.context) {- chain = Array.from(await activitypub.contexts.getItems(uid, context.context, { input }));- if (chain && chain.length) {- // Deduplicate by id (just in case, also a buggy NodeBB impl. sent dupes)- const ids = new Set();- chain = chain.filter((item) => {- const seen = ids.has(item.pid);- ids.add(item.pid);- return !seen;- });-- // Context resolves, use in later topic creation- context = context.context;+ const { type, id: tid } = await activitypub.helpers.resolveLocalId(context.context);+ if (!type === 'topic') {+ chain = Array.from(await activitypub.contexts.getItems(uid, context.context, { input }));+ if (chain && chain.length) {+ // Deduplicate by id (just in case, also a buggy NodeBB impl. sent dupes)+ const ids = new Set();+ chain = chain.filter((item) => {+ const seen = ids.has(item.pid);+ ids.add(item.pid);+ return !seen;+ });++ // Context resolves, use in later topic creation+ context = context.context;+ }+ } else {+ // Local context, get local posts+ const mainPid = await topics.getTopicField(tid, 'mainPid');+ const pids = await db.getSortedSetMembers(`tid:${tid}:posts`);+ pids.unshift(mainPid);+ chain = await posts.getPostsData(pids);++ // Add received object to chain if not present already+ if (!pids.includes(input.id)) {+ const mocked = await activitypub.mocks.post(input);+ chain.push(mocked);+ }}} else {context = undefined;