mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 16:06:08 +02:00
fix: handle remote objects reporting a local context, #14188
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user