fix(chat): 修复多个聊天错误 消息格式错误导致断连、新消息会通知到发件人、加强消息发送的成员验证
This commit is contained in:
@@ -11,12 +11,10 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import aliased, selectinload
|
||||
|
||||
from core.base.exceptions import WebsocketTooManyRequests
|
||||
from core.db.models import User, Chat, ReadStatus, Message
|
||||
from core.db.models import User, Chat, ReadStatus, Message, chat_participant
|
||||
from core.routers.auth.schema import LoginUser
|
||||
from core.utils.helper import format_date
|
||||
|
||||
from .schema import ChatUnreadOut
|
||||
|
||||
|
||||
async def websocket_callback(ws, pexpire):
|
||||
raise WebsocketTooManyRequests("Too many requests")
|
||||
@@ -91,3 +89,22 @@ async def get_unread_messages_per_chat(
|
||||
))
|
||||
|
||||
return results
|
||||
|
||||
|
||||
async def get_chat(chat_guid, login_user: User, db_session: AsyncSession) -> Chat | None:
|
||||
subquery = (
|
||||
select(chat_participant.c.chat_id)
|
||||
.where(chat_participant.c.user_id == login_user.user_id)
|
||||
).scalar_subquery()
|
||||
|
||||
query = (
|
||||
select(Chat)
|
||||
.where(and_(
|
||||
Chat.id.in_(subquery),
|
||||
Chat.guid == chat_guid,
|
||||
Chat.is_deleted == False
|
||||
))
|
||||
)
|
||||
result = await db_session.execute(query)
|
||||
await db_session.commit()
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
Reference in New Issue
Block a user