[mastodon-client] Fix link pagination prev attribute when minId is set

This commit is contained in:
Laura Hausmann 2023-10-11 01:13:10 +02:00
parent 3204bd9d18
commit fef807a165
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
6 changed files with 15 additions and 15 deletions

View file

@ -58,7 +58,7 @@ export class ListHelpers {
.map(p => p.user) .map(p => p.user)
.filter(p => p) as 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; return users;
}); });
} }

View file

@ -177,7 +177,7 @@ export class NoteHelpers {
.map(p => p.user) .map(p => p.user)
.filter(p => p) as 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; return users;
}); });
} }
@ -249,7 +249,7 @@ export class NoteHelpers {
.map(p => p.user) .map(p => p.user)
.filter(p => p) as 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; return users;
}); });
} }

View file

@ -51,8 +51,8 @@ export class PaginationHelpers {
const ids = p.map(x => x.id); const ids = p.map(x => x.id);
ctx.pagination = p.length > 0 ? { ctx.pagination = p.length > 0 ? {
limit: limit, limit: limit,
maxId: ids.at(reverse ? 0 : -1), maxId: ids.at(-1),
minId: ids.at(reverse ? -1 : 0) minId: ids.at(0)
} : undefined; } : undefined;
return p; return p;
}); });

View file

@ -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))); return Promise.all(conversations.map(c => awaitAll(c)));
}); });
} }

View file

@ -267,7 +267,7 @@ export class UserHelpers {
} as MastodonEntity.MutedAccount } 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; return result;
}); });
} }
@ -292,7 +292,7 @@ export class UserHelpers {
.map(p => p.blockee) .map(p => p.blockee)
.filter(p => p) as 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; return users;
}); });
} }
@ -317,7 +317,7 @@ export class UserHelpers {
.map(p => p.follower) .map(p => p.follower)
.filter(p => p) as 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; return users;
}); });
} }
@ -401,7 +401,7 @@ export class UserHelpers {
return PaginationHelpers.execQuery(query, limit, minId !== undefined) return PaginationHelpers.execQuery(query, limit, minId !== undefined)
.then(res => { .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); return res.map(p => p.note as Note);
}); });
} }
@ -423,7 +423,7 @@ export class UserHelpers {
return PaginationHelpers.execQuery(query, limit, minId !== undefined) return PaginationHelpers.execQuery(query, limit, minId !== undefined)
.then(res => { .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); return res.map(p => p.note as Note);
}); });
} }
@ -466,7 +466,7 @@ export class UserHelpers {
return query.take(limit).getMany().then(p => { return query.take(limit).getMany().then(p => {
if (minId !== undefined) p = p.reverse(); 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[]; return p.map(p => type === "followers" ? p.follower : p.followee).filter(p => p) as User[];
}); });
} }

View file

@ -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; if (ids.length < 1) return undefined;
return { return {
limit: limit, limit: limit,
maxId: ids.at(reverse ? 0 : -1), maxId: ids.at(-1),
minId: ids.at(reverse ? -1 : 0) minId: ids.at(0)
} }
} }