mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-22 02:12:40 +01:00
Fix sort order when using ?around
This commit is contained in:
parent
d3ece937e6
commit
481cf38373
@ -130,19 +130,25 @@ router.get(
|
||||
query.take = Math.floor(limit / 2);
|
||||
if (query.take != 0) {
|
||||
const [right, left] = await Promise.all([
|
||||
Message.find({ ...query, where: { id: LessThan(around) } }),
|
||||
Message.find({
|
||||
...query,
|
||||
where: { id: MoreThanOrEqual(around) },
|
||||
where: { channel_id, id: LessThan(around) },
|
||||
}),
|
||||
Message.find({
|
||||
...query,
|
||||
where: { channel_id, id: MoreThanOrEqual(around) },
|
||||
order: { timestamp: "ASC" },
|
||||
}),
|
||||
]);
|
||||
left.push(...right);
|
||||
messages = left;
|
||||
messages = left.sort(
|
||||
(a, b) => a.timestamp.getTime() - b.timestamp.getTime(),
|
||||
);
|
||||
} else {
|
||||
query.take = 1;
|
||||
const message = await Message.findOne({
|
||||
...query,
|
||||
where: { id: around },
|
||||
where: { channel_id, id: around },
|
||||
});
|
||||
messages = message ? [message] : [];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user