mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-27 02:40:39 +01: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);
|
||||
ids = ids.filter((_, idx) => exists[idx]);
|
||||
|
||||
const isCategory = await db.exists(ids.map(id => `categoryRemote:${id}`));
|
||||
await batch.processArray(ids, async (currentIds) => {
|
||||
const method = isCategory ? categories.getCategoriesFields : user.getUsersFields;
|
||||
const usersData = await method(currentIds, ['inbox', 'sharedInbox']);
|
||||
usersData.forEach((u) => {
|
||||
if (u && (u.sharedInbox || u.inbox)) {
|
||||
inboxes.add(u.sharedInbox || u.inbox);
|
||||
const isCategory = await db.exists(currentIds.map(id => `categoryRemote:${id}`));
|
||||
const [cids, uids] = currentIds.reduce(([cids, uids], id, idx) => {
|
||||
const array = isCategory[idx] ? cids : uids;
|
||||
array.push(id);
|
||||
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('User Actor endpoint', () => {
|
||||
let uid;
|
||||
|
||||
Reference in New Issue
Block a user