feat: add sort param to messages endpoint, default desc (newest first)
This commit is contained in:
parent
36637c0d70
commit
b133ac7a8a
|
|
@ -17,8 +17,13 @@ async def list_messages(
|
|||
from_addr: Optional[str] = Query(default=None, alias="from"),
|
||||
limit: int = Query(default=50, le=200),
|
||||
offset: int = Query(default=0),
|
||||
sort: str = Query(default="desc", regex="^(asc|desc)$"),
|
||||
) -> list[Message]:
|
||||
"""List messages in a folder."""
|
||||
"""List messages in a folder.
|
||||
|
||||
Args:
|
||||
sort: Sort order by date. "desc" (default) = newest first, "asc" = oldest first
|
||||
"""
|
||||
config = get_config()
|
||||
|
||||
if account_id not in config.accounts:
|
||||
|
|
@ -36,6 +41,10 @@ async def list_messages(
|
|||
from_addr=from_addr,
|
||||
)
|
||||
|
||||
# Sort by UID (higher UID = newer message)
|
||||
if sort == "desc":
|
||||
uids = list(reversed(uids))
|
||||
|
||||
# Apply pagination
|
||||
total = len(uids)
|
||||
uids = uids[offset:offset + limit]
|
||||
|
|
|
|||
Loading…
Reference in New Issue