mirror of https://gitlab.com/litecord/litecord.git
messages: fix ordering of "around" result
This commit is contained in:
parent
3ed0ff8176
commit
a2f892192d
|
|
@ -54,6 +54,7 @@ async def message_search(
|
||||||
before: Optional[int],
|
before: Optional[int],
|
||||||
after: Optional[int],
|
after: Optional[int],
|
||||||
limit: int,
|
limit: int,
|
||||||
|
order: str = "DESC",
|
||||||
) -> List[int]:
|
) -> List[int]:
|
||||||
where_clause = ""
|
where_clause = ""
|
||||||
if before:
|
if before:
|
||||||
|
|
@ -69,7 +70,7 @@ async def message_search(
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM messages
|
FROM messages
|
||||||
WHERE channel_id = $1 {where_clause}
|
WHERE channel_id = $1 {where_clause}
|
||||||
ORDER BY id DESC
|
ORDER BY id {order}
|
||||||
LIMIT {limit}
|
LIMIT {limit}
|
||||||
""",
|
""",
|
||||||
channel_id,
|
channel_id,
|
||||||
|
|
@ -87,10 +88,10 @@ async def around_message_search(
|
||||||
# merge it all together: before + [around_id] + after
|
# merge it all together: before + [around_id] + after
|
||||||
halved_limit = limit // 2
|
halved_limit = limit // 2
|
||||||
before_messages = await message_search(
|
before_messages = await message_search(
|
||||||
channel_id, before=around_id, after=None, limit=halved_limit
|
channel_id, before=around_id, after=None, limit=halved_limit, order="ASC"
|
||||||
)
|
)
|
||||||
after_messages = await message_search(
|
after_messages = await message_search(
|
||||||
channel_id, before=None, after=around_id, limit=halved_limit
|
channel_id, before=None, after=around_id, limit=halved_limit, order="ASC"
|
||||||
)
|
)
|
||||||
return before_messages + [around_id] + after_messages
|
return before_messages + [around_id] + after_messages
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue