fix: regression that caused resolveInboxes to always return empty, added tests for resolveInboxes

This commit is contained in:
Julian Lam
2025-03-25 10:20:50 -04:00
parent 70dac3aede
commit 0d77e860bf
2 changed files with 74 additions and 6 deletions

View File

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

View File

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