[mastodon-client] Don't return 'next' link pagination header when there are not more results

This fixes clients like toot! showing ghost users
This commit is contained in:
Laura Hausmann 2023-10-11 18:22:53 +02:00
parent 53bb79706e
commit 73895e856c
Signed by: zotan
GPG key ID: D044E84C5BE01605
2 changed files with 3 additions and 7 deletions

View file

@ -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<T extends ObjectLiteral>(
@ -48,12 +49,7 @@ export class PaginationHelpers {
public static async execQueryLinkPagination<T extends ObjectLiteral>(query: SelectQueryBuilder<T>, limit: number, reverse: boolean, ctx: MastoContext): Promise<T[]> {
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;
});
}

View file

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