feat: mentions badge in chat list and muted-mention delivery
All checks were successful
CI / test (push) Successful in 21s
All checks were successful
CI / test (push) Successful in 21s
This commit is contained in:
@@ -30,7 +30,13 @@ from app.realtime.presence import get_users_online_map
|
||||
from app.users.repository import get_user_by_id, has_block_relation_between_users
|
||||
|
||||
|
||||
async def serialize_chat_for_user(db: AsyncSession, *, user_id: int, chat: Chat) -> ChatRead:
|
||||
async def serialize_chat_for_user(
|
||||
db: AsyncSession,
|
||||
*,
|
||||
user_id: int,
|
||||
chat: Chat,
|
||||
current_username: str | None = None,
|
||||
) -> ChatRead:
|
||||
display_title = chat.title
|
||||
my_role = None
|
||||
membership = await repository.get_chat_member(db, chat_id=chat.id, user_id=user_id)
|
||||
@@ -66,7 +72,16 @@ async def serialize_chat_for_user(db: AsyncSession, *, user_id: int, chat: Chat)
|
||||
if chat.type == ChatType.CHANNEL:
|
||||
subscribers_count = members_count
|
||||
|
||||
if not current_username:
|
||||
current_user = await get_user_by_id(db, user_id)
|
||||
current_username = current_user.username if current_user else None
|
||||
unread_count = await repository.get_unread_count_for_chat(db, chat_id=chat.id, user_id=user_id)
|
||||
unread_mentions_count = await repository.get_unread_mentions_count_for_chat(
|
||||
db,
|
||||
chat_id=chat.id,
|
||||
user_id=user_id,
|
||||
username=current_username,
|
||||
)
|
||||
last_message = await repository.get_last_visible_message_for_user(db, chat_id=chat.id, user_id=user_id)
|
||||
user_setting = await repository.get_chat_user_setting(db, chat_id=chat.id, user_id=user_id)
|
||||
archived = bool(user_setting and user_setting.archived)
|
||||
@@ -86,6 +101,7 @@ async def serialize_chat_for_user(db: AsyncSession, *, user_id: int, chat: Chat)
|
||||
"archived": archived,
|
||||
"pinned": pinned,
|
||||
"unread_count": unread_count,
|
||||
"unread_mentions_count": unread_mentions_count,
|
||||
"pinned_message_id": chat.pinned_message_id,
|
||||
"members_count": members_count,
|
||||
"online_count": online_count,
|
||||
@@ -105,7 +121,12 @@ async def serialize_chat_for_user(db: AsyncSession, *, user_id: int, chat: Chat)
|
||||
|
||||
|
||||
async def serialize_chats_for_user(db: AsyncSession, *, user_id: int, chats: list[Chat]) -> list[ChatRead]:
|
||||
return [await serialize_chat_for_user(db, user_id=user_id, chat=chat) for chat in chats]
|
||||
current_user = await get_user_by_id(db, user_id)
|
||||
current_username = current_user.username if current_user else None
|
||||
return [
|
||||
await serialize_chat_for_user(db, user_id=user_id, chat=chat, current_username=current_username)
|
||||
for chat in chats
|
||||
]
|
||||
|
||||
|
||||
async def create_chat_for_user(db: AsyncSession, *, creator_id: int, payload: ChatCreateRequest) -> Chat:
|
||||
|
||||
Reference in New Issue
Block a user