feat: associate new topics created from asserted notes with their originating context, if that context is resolvable

re: #12647
This commit is contained in:
Julian Lam
2024-10-24 14:35:34 -04:00
parent 15516862ce
commit 6f237c57cd
2 changed files with 14 additions and 3 deletions

View File

@@ -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) {