mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
feat: associate new topics created from asserted notes with their originating context, if that context is resolvable
re: #12647
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user