fix: handle remote objects reporting a local context, #14188

This commit is contained in:
Julian Lam
2026-04-20 12:48:47 -04:00
parent a537e38493
commit ffab31bd62
2 changed files with 29 additions and 11 deletions

View File

@@ -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 };

View File

@@ -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;
});
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;
// 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;