Skip to content

Commit

Permalink
Fixed followers dispatcher and api endpoint
Browse files Browse the repository at this point in the history
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
  • Loading branch information
allouis committed Sep 10, 2024
1 parent 3d12852 commit ff75427
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
4 changes: 2 additions & 2 deletions features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
21 changes: 8 additions & 13 deletions src/dispatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextData>,
handle: string,
Expand All @@ -322,14 +311,20 @@ 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 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<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 = actors;
}
return {
items,
Expand Down

0 comments on commit ff75427

Please sign in to comment.