diff --git a/packages/backend/src/server/api/mastodon/helpers/list.ts b/packages/backend/src/server/api/mastodon/helpers/list.ts index 8485e2a3b..69d3db0fd 100644 --- a/packages/backend/src/server/api/mastodon/helpers/list.ts +++ b/packages/backend/src/server/api/mastodon/helpers/list.ts @@ -58,7 +58,7 @@ export class ListHelpers { .map(p => p.user) .filter(p => p) as User[]; - ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined); + ctx.pagination = generatePaginationData(p.map(p => p.id), limit); return users; }); } diff --git a/packages/backend/src/server/api/mastodon/helpers/note.ts b/packages/backend/src/server/api/mastodon/helpers/note.ts index 42bc7b6da..0ad4399ec 100644 --- a/packages/backend/src/server/api/mastodon/helpers/note.ts +++ b/packages/backend/src/server/api/mastodon/helpers/note.ts @@ -177,7 +177,7 @@ export class NoteHelpers { .map(p => p.user) .filter(p => p) as User[]; - ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined); + ctx.pagination = generatePaginationData(p.map(p => p.id), limit); return users; }); } @@ -249,7 +249,7 @@ export class NoteHelpers { .map(p => p.user) .filter(p => p) as User[]; - ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined); + ctx.pagination = generatePaginationData(p.map(p => p.id), limit); return users; }); } diff --git a/packages/backend/src/server/api/mastodon/helpers/pagination.ts b/packages/backend/src/server/api/mastodon/helpers/pagination.ts index 3323566df..836a8f083 100644 --- a/packages/backend/src/server/api/mastodon/helpers/pagination.ts +++ b/packages/backend/src/server/api/mastodon/helpers/pagination.ts @@ -51,8 +51,8 @@ export class PaginationHelpers { const ids = p.map(x => x.id); ctx.pagination = p.length > 0 ? { limit: limit, - maxId: ids.at(reverse ? 0 : -1), - minId: ids.at(reverse ? -1 : 0) + maxId: ids.at(-1), + minId: ids.at(0) } : undefined; return p; }); diff --git a/packages/backend/src/server/api/mastodon/helpers/timeline.ts b/packages/backend/src/server/api/mastodon/helpers/timeline.ts index a406ca798..cc1f05a66 100644 --- a/packages/backend/src/server/api/mastodon/helpers/timeline.ts +++ b/packages/backend/src/server/api/mastodon/helpers/timeline.ts @@ -216,7 +216,7 @@ export class TimelineHelpers { } }); - ctx.pagination = generatePaginationData(p.map(p => p.threadId ?? p.id), limit, minId !== undefined); + ctx.pagination = generatePaginationData(p.map(p => p.threadId ?? p.id), limit); return Promise.all(conversations.map(c => awaitAll(c))); }); } diff --git a/packages/backend/src/server/api/mastodon/helpers/user.ts b/packages/backend/src/server/api/mastodon/helpers/user.ts index 80c175f21..3c843bfc4 100644 --- a/packages/backend/src/server/api/mastodon/helpers/user.ts +++ b/packages/backend/src/server/api/mastodon/helpers/user.ts @@ -267,7 +267,7 @@ export class UserHelpers { } as MastodonEntity.MutedAccount })); - ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined); + ctx.pagination = generatePaginationData(p.map(p => p.id), limit); return result; }); } @@ -292,7 +292,7 @@ export class UserHelpers { .map(p => p.blockee) .filter(p => p) as User[]; - ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined); + ctx.pagination = generatePaginationData(p.map(p => p.id), limit); return users; }); } @@ -317,7 +317,7 @@ export class UserHelpers { .map(p => p.follower) .filter(p => p) as User[]; - ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined); + ctx.pagination = generatePaginationData(p.map(p => p.id), limit); return users; }); } @@ -401,7 +401,7 @@ export class UserHelpers { return PaginationHelpers.execQuery(query, limit, minId !== undefined) .then(res => { - ctx.pagination = generatePaginationData(res.map(p => p.id), limit, minId !== undefined); + ctx.pagination = generatePaginationData(res.map(p => p.id), limit); return res.map(p => p.note as Note); }); } @@ -423,7 +423,7 @@ export class UserHelpers { return PaginationHelpers.execQuery(query, limit, minId !== undefined) .then(res => { - ctx.pagination = generatePaginationData(res.map(p => p.id), limit, minId !== undefined); + ctx.pagination = generatePaginationData(res.map(p => p.id), limit); return res.map(p => p.note as Note); }); } @@ -466,7 +466,7 @@ export class UserHelpers { return query.take(limit).getMany().then(p => { if (minId !== undefined) p = p.reverse(); - ctx.pagination = generatePaginationData(p.map(p => p.id), limit, minId !== undefined); + ctx.pagination = generatePaginationData(p.map(p => p.id), limit); return p.map(p => type === "followers" ? p.follower : p.followee).filter(p => p) as User[]; }); } diff --git a/packages/backend/src/server/api/mastodon/middleware/pagination.ts b/packages/backend/src/server/api/mastodon/middleware/pagination.ts index edbff4c8a..110ad5b5e 100644 --- a/packages/backend/src/server/api/mastodon/middleware/pagination.ts +++ b/packages/backend/src/server/api/mastodon/middleware/pagination.ts @@ -26,12 +26,12 @@ export async function PaginationMiddleware(ctx: MastoContext, next: () => Promis } } -export function generatePaginationData(ids: string[], limit: number, reverse: boolean): PaginationData | undefined { +export function generatePaginationData(ids: string[], limit: number): PaginationData | undefined { if (ids.length < 1) return undefined; return { limit: limit, - maxId: ids.at(reverse ? 0 : -1), - minId: ids.at(reverse ? -1 : 0) + maxId: ids.at(-1), + minId: ids.at(0) } }