mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-25 11:27:31 -07:00
[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:
parent
53bb79706e
commit
73895e856c
2 changed files with 3 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { ObjectLiteral, SelectQueryBuilder } from "typeorm";
|
import { ObjectLiteral, SelectQueryBuilder } from "typeorm";
|
||||||
import { MastoContext } from "@/server/api/mastodon/index.js";
|
import { MastoContext } from "@/server/api/mastodon/index.js";
|
||||||
|
import { generatePaginationData } from "@/server/api/mastodon/middleware/pagination.js";
|
||||||
|
|
||||||
export class PaginationHelpers {
|
export class PaginationHelpers {
|
||||||
public static makePaginationQuery<T extends ObjectLiteral>(
|
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[]> {
|
public static async execQueryLinkPagination<T extends ObjectLiteral>(query: SelectQueryBuilder<T>, limit: number, reverse: boolean, ctx: MastoContext): Promise<T[]> {
|
||||||
return this.execQuery(query, limit, reverse)
|
return this.execQuery(query, limit, reverse)
|
||||||
.then(p => {
|
.then(p => {
|
||||||
const ids = p.map(x => x.id);
|
ctx.pagination = generatePaginationData(p.map(x => x.id), limit);
|
||||||
ctx.pagination = p.length > 0 ? {
|
|
||||||
limit: limit,
|
|
||||||
maxId: ids.at(-1),
|
|
||||||
minId: ids.at(0)
|
|
||||||
} : undefined;
|
|
||||||
return p;
|
return p;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ export function generatePaginationData(ids: string[], limit: number): Pagination
|
||||||
|
|
||||||
return {
|
return {
|
||||||
limit: limit,
|
limit: limit,
|
||||||
maxId: ids.at(-1),
|
maxId: ids.length < limit ? undefined : ids.at(-1),
|
||||||
minId: ids.at(0)
|
minId: ids.at(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue