[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)
.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;
});
}

View File

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

View File

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

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

View File

@ -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[];
});
}

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