Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated following and followers collection to only return URLs #262

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,8 @@ Then(
// Check that the activity was sent to all followers
const activity = this.activities[activityName];

for (const follower of followers) {
for (const followerUrl of followers) {
const follower = await (await fetchActivityPub(followerUrl)).json();
const inbox = new URL(follower.inbox);

const found = await waitForRequest(
Expand Down Expand Up @@ -1253,7 +1254,7 @@ Then('{string} is in our Followers', async function (actorName) {
const actor = this.actors[actorName];

const found = (followers.orderedItems || []).find(
(item) => item.id === actor.id,
(item) => item === actor.id,
);

assert(found);
Expand All @@ -1280,7 +1281,7 @@ Then('{string} is in our Followers once only', async function (actorName) {
const followers = await firstPageResponse.json();
const actor = this.actors[actorName];
const found = (followers.orderedItems || []).filter(
(item) => item.id === actor.id,
(item) => item === actor.id,
);

assert.equal(found.length, 1);
Expand Down
15 changes: 13 additions & 2 deletions src/dispatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,14 @@ export async function followersDispatcher(
return {
items: (
await Promise.all(items.map((item) => APObject.fromJsonLd(item)))
).filter((item): item is Actor => isActor(item)),
)
.filter((item): item is Actor => isActor(item))
.map((item) => {
return {
id: item.id,
inboxId: item.inboxId,
};
}),
nextCursor,
};
}
Expand Down Expand Up @@ -592,7 +599,11 @@ export async function followingDispatcher(
});
}
}),
).then((results) => results.filter((r): r is Actor => isActor(r)));
).then((results) =>
results
.filter((r): r is Actor => isActor(r) && r.id !== null)
.map((r) => new URL(r.id!)),
);

return {
items,
Expand Down
18 changes: 6 additions & 12 deletions src/dispatchers.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,11 @@ describe('dispatchers', () => {

// Check correct items are returned in the correct order
expect(result.items.length).toEqual(2);
expect(result.items[0] instanceof Person).toBeTruthy();
expect(result.items[1] instanceof Person).toBeTruthy();
// @ts-ignore: We know that this is the correct type because of the above assertions
expect(result.items[0].id.toString()).toEqual(
'https://example.com/person/123',
expect(result.items[0]).toEqual(
new URL('https://example.com/person/123'),
);
// @ts-ignore: We know that this is the correct type because of the above assertions
expect(result.items[1].id.toString()).toEqual(
'https://example.com/person/456',
expect(result.items[1]).toEqual(
new URL('https://example.com/person/456'),
);
});

Expand All @@ -123,10 +119,8 @@ describe('dispatchers', () => {

// Check correct items are returned
expect(result.items.length).toEqual(1);
expect(result.items[0] instanceof Person).toBeTruthy();
// @ts-ignore: We know that this is the correct type because of the above assertions
expect(result.items[0].id.toString()).toEqual(
'https://example.com/person/456',
expect(result.items[0]).toEqual(
new URL('https://example.com/person/456'),
);
});
});
Expand Down
Loading