feat: mentions badge in chat list and muted-mention delivery
All checks were successful
CI / test (push) Successful in 21s

This commit is contained in:
2026-03-08 12:23:39 +03:00
parent fc7a9cc3a6
commit 0594b890c3
9 changed files with 92 additions and 75 deletions

View File

@@ -237,6 +237,42 @@ async def get_unread_count_for_chat(db: AsyncSession, *, chat_id: int, user_id:
return int(result.scalar_one() or 0)
async def get_unread_mentions_count_for_chat(
db: AsyncSession,
*,
chat_id: int,
user_id: int,
username: str | None,
) -> int:
normalized_username = (username or "").strip().lower()
if not normalized_username:
return 0
last_read_subquery = (
select(MessageReceipt.last_read_message_id)
.where(MessageReceipt.chat_id == chat_id, MessageReceipt.user_id == user_id)
.limit(1)
.scalar_subquery()
)
mention_like = f"%@{normalized_username}%"
stmt = (
select(func.count(Message.id))
.outerjoin(
MessageHidden,
(MessageHidden.message_id == Message.id) & (MessageHidden.user_id == user_id),
)
.where(
Message.chat_id == chat_id,
Message.sender_id != user_id,
MessageHidden.id.is_(None),
Message.id > func.coalesce(last_read_subquery, 0),
Message.text.is_not(None),
func.lower(Message.text).like(mention_like),
)
)
result = await db.execute(stmt)
return int(result.scalar_one() or 0)
async def get_last_visible_message_for_user(
db: AsyncSession,
*,