From 73895e856c000bc5afe3c6bf87ca194faa8b91f6 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 11 Oct 2023 18:22:53 +0200 Subject: [PATCH] [mastodon-client] Don't return 'next' link pagination header when there are not more results This fixes clients like toot! showing ghost users --- .../backend/src/server/api/mastodon/helpers/pagination.ts | 8 ++------ .../src/server/api/mastodon/middleware/pagination.ts | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/helpers/pagination.ts b/packages/backend/src/server/api/mastodon/helpers/pagination.ts index 836a8f083..f9116455d 100644 --- a/packages/backend/src/server/api/mastodon/helpers/pagination.ts +++ b/packages/backend/src/server/api/mastodon/helpers/pagination.ts @@ -1,5 +1,6 @@ import { ObjectLiteral, SelectQueryBuilder } from "typeorm"; import { MastoContext } from "@/server/api/mastodon/index.js"; +import { generatePaginationData } from "@/server/api/mastodon/middleware/pagination.js"; export class PaginationHelpers { public static makePaginationQuery( @@ -48,12 +49,7 @@ export class PaginationHelpers { public static async execQueryLinkPagination(query: SelectQueryBuilder, limit: number, reverse: boolean, ctx: MastoContext): Promise { return this.execQuery(query, limit, reverse) .then(p => { - const ids = p.map(x => x.id); - ctx.pagination = p.length > 0 ? { - limit: limit, - maxId: ids.at(-1), - minId: ids.at(0) - } : undefined; + ctx.pagination = generatePaginationData(p.map(x => x.id), limit); return p; }); } diff --git a/packages/backend/src/server/api/mastodon/middleware/pagination.ts b/packages/backend/src/server/api/mastodon/middleware/pagination.ts index 110ad5b5e..908ac6e3a 100644 --- a/packages/backend/src/server/api/mastodon/middleware/pagination.ts +++ b/packages/backend/src/server/api/mastodon/middleware/pagination.ts @@ -31,7 +31,7 @@ export function generatePaginationData(ids: string[], limit: number): Pagination return { limit: limit, - maxId: ids.at(-1), + maxId: ids.length < limit ? undefined : ids.at(-1), minId: ids.at(0) } }