diff --git a/src/activitypub/contexts.js b/src/activitypub/contexts.js index 32be8b218d..12dcae1059 100644 --- a/src/activitypub/contexts.js +++ b/src/activitypub/contexts.js @@ -58,7 +58,7 @@ Contexts.getItems = async (uid, id, options) => { activitypub.helpers.log(`[activitypub/context] Retrieving context ${id}`); let { type, items, orderedItems, first, next } = await activitypub.get('uid', uid, id); if (!acceptableTypes.includes(type)) { - return []; + return false; } if (type.startsWith('Ordered') && orderedItems) { @@ -79,7 +79,7 @@ Contexts.getItems = async (uid, id, options) => { // Early breakout on empty collection if (!next && !chain.size) { - return []; + return new Set(); } if (next) { diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js index 14ad66d6e3..586bde26b5 100644 --- a/src/activitypub/notes.js +++ b/src/activitypub/notes.js @@ -43,13 +43,19 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { } let chain; - const context = await activitypub.contexts.get(uid, id); + let context = await activitypub.contexts.get(uid, id); if (context.tid) { unlock(id); 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) { + // Context resolves, use in later topic creation + context = context.context; + } + } else { + context = undefined; } if (!chain || !chain.length) { @@ -169,6 +175,11 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => { posts.attachments.update(mainPid, attachment), ]); unprocessed.shift(); + + if (context) { + activitypub.helpers.log(`[activitypub/notes.assert] Associating tid ${tid} with context ${context}`); + await topics.setTopicField(tid, 'context', context); + } } for (const post of unprocessed) {