mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-20 09:20:37 +02:00
fix: regression that caused resolveInboxes to always return empty, added tests for resolveInboxes
This commit is contained in:
@@ -120,13 +120,23 @@ ActivityPub.resolveInboxes = async (ids) => {
|
|||||||
const exists = await db.isSortedSetMembers('usersRemote:lastCrawled', ids);
|
const exists = await db.isSortedSetMembers('usersRemote:lastCrawled', ids);
|
||||||
ids = ids.filter((_, idx) => exists[idx]);
|
ids = ids.filter((_, idx) => exists[idx]);
|
||||||
|
|
||||||
const isCategory = await db.exists(ids.map(id => `categoryRemote:${id}`));
|
|
||||||
await batch.processArray(ids, async (currentIds) => {
|
await batch.processArray(ids, async (currentIds) => {
|
||||||
const method = isCategory ? categories.getCategoriesFields : user.getUsersFields;
|
const isCategory = await db.exists(currentIds.map(id => `categoryRemote:${id}`));
|
||||||
const usersData = await method(currentIds, ['inbox', 'sharedInbox']);
|
const [cids, uids] = currentIds.reduce(([cids, uids], id, idx) => {
|
||||||
usersData.forEach((u) => {
|
const array = isCategory[idx] ? cids : uids;
|
||||||
if (u && (u.sharedInbox || u.inbox)) {
|
array.push(id);
|
||||||
inboxes.add(u.sharedInbox || u.inbox);
|
return [cids, uids];
|
||||||
|
}, [[], []]);
|
||||||
|
const categoryData = await categories.getCategoriesFields(cids, ['inbox', 'sharedInbox']);
|
||||||
|
const userData = await user.getUsersFields(uids, ['inbox', 'sharedInbox']);
|
||||||
|
|
||||||
|
currentIds.forEach((id) => {
|
||||||
|
if (cids.includes(id)) {
|
||||||
|
const data = categoryData[cids.indexOf(id)];
|
||||||
|
inboxes.add(data.sharedInbox || data.inbox);
|
||||||
|
} else if (uids.includes(id)) {
|
||||||
|
const data = userData[uids.indexOf(id)];
|
||||||
|
inboxes.add(data.sharedInbox || data.inbox);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@@ -353,6 +353,64 @@ describe('as:Group', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Inbox resolution', () => {
|
||||||
|
describe('remote users', () => {
|
||||||
|
it('should return an inbox if present', async () => {
|
||||||
|
const { id, actor } = helpers.mocks.person();
|
||||||
|
await activitypub.actors.assert(id);
|
||||||
|
|
||||||
|
const inboxes = await activitypub.resolveInboxes([id]);
|
||||||
|
|
||||||
|
assert(inboxes && Array.isArray(inboxes));
|
||||||
|
assert.strictEqual(inboxes.length, 1);
|
||||||
|
assert.strictEqual(inboxes[0], actor.inbox);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a shared inbox if present', async () => {
|
||||||
|
const { id, actor } = helpers.mocks.person({
|
||||||
|
endpoints: {
|
||||||
|
sharedInbox: 'https://example.org/inbox',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await activitypub.actors.assert(id);
|
||||||
|
|
||||||
|
const inboxes = await activitypub.resolveInboxes([id]);
|
||||||
|
|
||||||
|
assert(inboxes && Array.isArray(inboxes));
|
||||||
|
assert.strictEqual(inboxes.length, 1);
|
||||||
|
assert.strictEqual(inboxes[0], 'https://example.org/inbox');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('remote categories', () => {
|
||||||
|
it('should return an inbox if present', async () => {
|
||||||
|
const { id, actor } = helpers.mocks.group();
|
||||||
|
await activitypub.actors.assertGroup(id);
|
||||||
|
|
||||||
|
const inboxes = await activitypub.resolveInboxes([id]);
|
||||||
|
|
||||||
|
assert(inboxes && Array.isArray(inboxes));
|
||||||
|
assert.strictEqual(inboxes.length, 1);
|
||||||
|
assert.strictEqual(inboxes[0], actor.inbox);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a shared inbox if present', async () => {
|
||||||
|
const { id, actor } = helpers.mocks.group({
|
||||||
|
endpoints: {
|
||||||
|
sharedInbox: 'https://example.org/inbox',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await activitypub.actors.assertGroup(id);
|
||||||
|
|
||||||
|
const inboxes = await activitypub.resolveInboxes([id]);
|
||||||
|
|
||||||
|
assert(inboxes && Array.isArray(inboxes));
|
||||||
|
assert.strictEqual(inboxes.length, 1);
|
||||||
|
assert.strictEqual(inboxes[0], 'https://example.org/inbox');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Controllers', () => {
|
describe('Controllers', () => {
|
||||||
describe('User Actor endpoint', () => {
|
describe('User Actor endpoint', () => {
|
||||||
let uid;
|
let uid;
|
||||||
|
|||||||
Reference in New Issue
Block a user