feat: add annotations, user profiles, watchers, stories, search and more
This commit is contained in:
@@ -118,25 +118,39 @@ async def list_chats(
|
||||
return items
|
||||
|
||||
|
||||
async def get_chat_history(
|
||||
async def get_chat_history( # noqa: PLR0913
|
||||
pool: asyncpg.Pool,
|
||||
account_id: int,
|
||||
chat_id: int,
|
||||
page: Page,
|
||||
*,
|
||||
include_deleted: bool = True,
|
||||
before_id: int | None = None,
|
||||
after_id: int | None = None,
|
||||
) -> list[MessageView]:
|
||||
where = "account_id = $1 AND chat_id = $2"
|
||||
if not include_deleted:
|
||||
where += " AND deleted_at IS NULL"
|
||||
rows = await pool.fetch(
|
||||
params: list[object] = [account_id, chat_id]
|
||||
if after_id is not None:
|
||||
params.append(after_id)
|
||||
where += f" AND message_id > ${len(params)}"
|
||||
order = "date ASC, message_id ASC"
|
||||
elif before_id is not None:
|
||||
params.append(before_id)
|
||||
where += f" AND message_id < ${len(params)}"
|
||||
order = "date DESC, message_id DESC"
|
||||
else:
|
||||
order = "date DESC, message_id DESC"
|
||||
params.append(page.capped_limit)
|
||||
query = (
|
||||
f"SELECT {_MESSAGE_COLS} FROM messages WHERE {where} " # noqa: S608
|
||||
"ORDER BY date DESC, message_id DESC LIMIT $3 OFFSET $4",
|
||||
account_id,
|
||||
chat_id,
|
||||
page.capped_limit,
|
||||
page.offset,
|
||||
f"ORDER BY {order} LIMIT ${len(params)}"
|
||||
)
|
||||
if before_id is None and after_id is None:
|
||||
params.append(page.offset)
|
||||
query += f" OFFSET ${len(params)}"
|
||||
rows = await pool.fetch(query, *params)
|
||||
media_by_key = await _media_map(pool, account_id, rows)
|
||||
parsed = [(row, load_raw(row["raw"])) for row in rows]
|
||||
views: list[MessageView] = []
|
||||
|
||||
Reference in New Issue
Block a user