feat(chat): 单向聊天的历史消息获取
This commit is contained in:
@@ -94,18 +94,31 @@ async def get_unread_messages_per_chat(
|
||||
return results
|
||||
|
||||
|
||||
async def get_chat(chat_guid, login_user: User, db_session: AsyncSession) -> Chat | None:
|
||||
async def get_chat(chat_guid, login_user: User, db_session: AsyncSession,
|
||||
is_query_messages: bool = False) -> Chat | None:
|
||||
subquery = (
|
||||
select(ChatParticipant.chat_id)
|
||||
.where(ChatParticipant.user_id == login_user.user_id)
|
||||
.where(
|
||||
and_(
|
||||
ChatParticipant.user_id == login_user.user_id,
|
||||
ChatParticipant.is_deleted == False
|
||||
)
|
||||
)
|
||||
).scalar_subquery()
|
||||
|
||||
conditions = [
|
||||
Chat.id.in_(subquery),
|
||||
Chat.guid == chat_guid
|
||||
]
|
||||
if is_query_messages is False:
|
||||
conditions.append(
|
||||
Chat.is_deleted == False
|
||||
)
|
||||
|
||||
query = (
|
||||
select(Chat)
|
||||
.where(and_(
|
||||
Chat.id.in_(subquery),
|
||||
Chat.guid == chat_guid,
|
||||
Chat.is_deleted == False
|
||||
*conditions
|
||||
))
|
||||
)
|
||||
result = await db_session.execute(query)
|
||||
|
||||
Reference in New Issue
Block a user