From ff754270fa17c7a4868deb936349b9fac2c4df5a Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Tue, 10 Sep 2024 16:59:06 +0700 Subject: [PATCH] Fixed followers dispatcher and api endpoint There was a bug in fedify with serialising Actors which mean we had to return incompleter followers data, which broke our frontend, this has now been fixed so we can update the followers dispatcher to return full Actor objects again --- features/step_definitions/stepdefs.js | 4 ++-- src/dispatchers.ts | 21 ++++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/features/step_definitions/stepdefs.js b/features/step_definitions/stepdefs.js index d39b0b2da..7e00e8d6e 100644 --- a/features/step_definitions/stepdefs.js +++ b/features/step_definitions/stepdefs.js @@ -343,7 +343,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 = this.followers.orderedItems.find(item => item.id === actor.id); assert(found); }); @@ -356,7 +356,7 @@ Then('{string} is in our Followers once only', async function (actorName) { }); const followers = await response.json(); const actor = this.actors[actorName]; - const found = followers.orderedItems.filter(item => item === actor.id); + const found = this.followers.orderedItems.filter(item => item.id === actor.id); assert.equal(found.length, 1); }); diff --git a/src/dispatchers.ts b/src/dispatchers.ts index fb89128bb..a1e6afda6 100644 --- a/src/dispatchers.ts +++ b/src/dispatchers.ts @@ -303,17 +303,6 @@ export async function inboxErrorHandler( console.error(error); } -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, - }; -} - export async function followersDispatcher( ctx: Context, handle: string, @@ -322,14 +311,20 @@ export async function followersDispatcher( let items: Recipient[] = []; const fullResults = await ctx.data.db.get(['followers', 'expanded']); if (fullResults) { - items = fullResults.map(convertJsonLdToRecipient) + items = await fullResults.reduce(async (list, item) => { + const obj = await APObject.fromJsonLd(item); + if (isActor(obj)) { + return (await list).concat(obj); + } + return list; + }, Promise.resolve([])); } else { const results = (await ctx.data.db.get(['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 = actors; } return { items,