feat(backend): chat list marks a deleted last message, history pages mark messages with a note
This commit is contained in:
1 parent
90b37ec708
commit
97f9082f5e
3 files changed
+148
-1
No files matched your search
@@ -80,7 +80,8 @@ _CHAT_ROWS = """
|
||||
WITH ids AS ({ids})
|
||||
SELECT ids.chat_id,
|
||||
COALESCE(cs.message_count, 0) AS message_count,
|
||||
cs.last_date, cs.last_text, cs.last_sender_id,
|
||||
cs.last_date, cs.last_text, cs.last_sender_id, cs.last_message_id,
|
||||
COALESCE(cs.last_deleted, false) AS last_deleted,
|
||||
COALESCE(named.title,
|
||||
NULLIF(trim(concat_ws(' ', p.first_name, p.last_name)), ''),
|
||||
p.username) AS title,
|
||||
@@ -149,6 +150,8 @@ def _chat_item(row: asyncpg.Record) -> ChatListItem:
|
||||
last_date=row["last_date"],
|
||||
last_text=row["last_text"],
|
||||
last_sender_id=row["last_sender_id"],
|
||||
last_message_id=row["last_message_id"],
|
||||
last_deleted=row["last_deleted"],
|
||||
)
|
||||
|
||||
|
||||
@@ -259,6 +262,7 @@ async def get_chat_history( # noqa: PLR0913
|
||||
views.append(_build_album(members, media_by_key))
|
||||
index = end
|
||||
await _apply_read_status(pool, account_id, chat_id, views)
|
||||
await _apply_notes(pool, account_id, chat_id, views)
|
||||
return views
|
||||
|
||||
|
||||
@@ -278,6 +282,7 @@ async def get_message(
|
||||
raw = load_raw(row["raw"])
|
||||
view = build_message_view(row, raw, _single_media(row, raw, media_by_key))
|
||||
await _apply_read_status(pool, account_id, chat_id, [view])
|
||||
await _apply_notes(pool, account_id, chat_id, [view])
|
||||
return view
|
||||
|
||||
|
||||
@@ -301,6 +306,23 @@ async def _apply_read_status(
|
||||
)
|
||||
|
||||
|
||||
async def _apply_notes(
|
||||
pool: asyncpg.Pool, account_id: int, chat_id: int, views: list[MessageView]
|
||||
) -> None:
|
||||
if not views:
|
||||
return
|
||||
rows = await pool.fetch(
|
||||
"SELECT DISTINCT message_id FROM annotations "
|
||||
"WHERE account_id = $1 AND chat_id = $2 AND message_id = ANY($3::bigint[])",
|
||||
account_id,
|
||||
chat_id,
|
||||
[view.message_id for view in views],
|
||||
)
|
||||
noted = {row["message_id"] for row in rows}
|
||||
for view in views:
|
||||
view.has_note = view.message_id in noted
|
||||
|
||||
|
||||
def _build_album(
|
||||
members: list[tuple[asyncpg.Record, dict]],
|
||||
media_by_key: dict[tuple[int, int], asyncpg.Record],
|
||||
|
||||
Reference in new issue
Block a user