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

[WIP] Fix followers collection output #24

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ Then('{string} is in our Followers', async function (actorName) {
const followers = await response.json();
const actor = this.actors[actorName];

const found = followers.orderedItems.find(item => item === actor.id);
const found = followers.orderedItems.find(item => item.id === actor.id);

assert(found);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"wiremock-captain": "3.3.1"
},
"dependencies": {
"@fedify/fedify": "0.13.0-dev.318",
"@fedify/fedify": "0.14.0-dev.334",
"@hono/node-server": "1.11.1",
"@js-temporal/polyfill": "0.4.4",
"@sentry/node": "8.13.0",
Expand Down
23 changes: 11 additions & 12 deletions src/dispatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,12 @@ async function lookupActor(ctx: RequestContext<ContextData>, url: string) {
return null;
}

function convertJsonLdToRecipient(result: any): Recipient {
return {
...result,
id: new URL(result.id),
inboxId: new URL(result.inbox),
endpoints: result.endpoints?.sharedInbox != null
? { sharedInbox: new URL(result.endpoints.sharedInbox) }
: null,
};
async function convertJsonLdToRecipient(result: any): Promise<Actor | null> {
const thing = await APObject.fromJsonLd(result);
if (isActor(thing)) {
return thing;
}
return null;
}

export async function followersDispatcher(
Expand All @@ -265,17 +262,19 @@ export async function followersDispatcher(
let items: Recipient[] = [];
const fullResults = await ctx.data.db.get<any[]>(['followers', 'expanded']);
if (fullResults) {
items = fullResults.map(convertJsonLdToRecipient)
items = (await Promise.all(fullResults.map(convertJsonLdToRecipient)))
.filter(item => item !== null) as Actor[]
} else {
const results = (await ctx.data.db.get<string[]>(['followers'])) || [];
const actors = items = (await Promise.all(results.map((result) => lookupActor(ctx, result))))
.filter((item): item is Actor => isActor(item))
const toStore = await Promise.all(actors.map(actor => actor.toJsonLd() as any));
await ctx.data.db.set(['followers', 'expanded'], toStore);
items = toStore.map(convertJsonLdToRecipient);
items = (await Promise.all(toStore.map(convertJsonLdToRecipient)))
.filter(item => item !== null) as Actor[];
}
return {
items,
items: items,
};
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@
resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.1.tgz#b9da6a878a371829a0502c9b6c1c143ef6663f4d"
integrity sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==

"@fedify/fedify@0.13.0-dev.318":
version "0.13.0-dev.318"
resolved "https://registry.yarnpkg.com/@fedify/fedify/-/fedify-0.13.0-dev.318.tgz#96146859d01888cb163908049bdb4d928ade0938"
integrity sha512-xzT3iz5IA9/9Wj30X+o0t0INDeLzn/7dq75nw5u966myzT0Ejq5L//fKNmVB04rFE6vx0+DWmZtpdxOL26YoNw==
"@fedify/fedify@0.14.0-dev.334":
version "0.14.0-dev.334"
resolved "https://registry.yarnpkg.com/@fedify/fedify/-/fedify-0.14.0-dev.334.tgz#326c3696501b83b1b052a7a539b7548e9edf598e"
integrity sha512-1YEjUiQv2/reKuZLPCjsojOCYkUhs5A7zX1ZXqO726QHVVRZtxinz6RW2wHWYAiMVsY6Ko1KGva/FzwBssGR6A==
dependencies:
"@deno/shim-crypto" "~0.3.1"
"@deno/shim-deno" "~0.18.0"
Expand Down
Loading