Fix out-of-order antenna note pagination

This commit is contained in:
Laura Hausmann 2023-08-08 00:11:15 +02:00
parent 79471cf450
commit 16702c4d6a
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605

View File

@ -126,17 +126,25 @@ export default define(meta, paramDef, async (ps, user) => {
readNote(user.id, notes);
}
const packedNotes = (await Notes.packMany(notes, user)).sort(
(a, b) =>
paginationMap.findIndex((p) => p[0] == a.id) -
paginationMap.findIndex((p) => p[0] == b.id),
);
if (notes.length < ps.limit) {
pagination = "-1";
} else {
// I'm so sorry, FIXME: rewrite pagination system
pagination = paginationMap.find(
(p) => p[0] == notes[notes.length - (notes.length > 1 ? 2 : 1)].id,
(p) =>
p[0] ==
packedNotes[packedNotes.length - (packedNotes.length > 1 ? 2 : 1)].id,
)[1];
}
return {
pagination: pagination,
notes: await Notes.packMany(notes, user),
notes: packedNotes,
};
});