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) } }