feat(chat): 聊天列表新增未读消息总数
This commit is contained in:
@@ -40,6 +40,25 @@ async def get_user_active_direct_chats(
|
||||
|
||||
return None
|
||||
|
||||
async def get_total_unread_messages_count(db_session: AsyncSession, login_user: LoginUser) -> int:
|
||||
"""获取未读消息总数"""
|
||||
query = (
|
||||
select(func.count(Message.id))
|
||||
.join(
|
||||
ChatParticipant,
|
||||
and_(
|
||||
Message.chat_id == ChatParticipant.chat_id,
|
||||
ChatParticipant.user_id == login_user.user_id
|
||||
)
|
||||
)
|
||||
.filter(
|
||||
Message.id > ChatParticipant.last_read_message_id,
|
||||
Message.user_id != login_user.user_id,
|
||||
ChatParticipant.is_deleted == False
|
||||
)
|
||||
)
|
||||
result = await db_session.execute(query)
|
||||
return result.scalar()
|
||||
|
||||
async def get_chat_unread_messages_count(db_session: AsyncSession, login_user: LoginUser, chats):
|
||||
"""查询未读消息的预览"""
|
||||
|
||||
Reference in New Issue
Block a user