fix(chat): 修复多个聊天错误 消息格式错误导致断连、新消息会通知到发件人、加强消息发送的成员验证

This commit is contained in:
xingc
2025-05-14 21:19:46 +08:00
parent 854f5bcbea
commit 99f15cff84
4 changed files with 33 additions and 12 deletions

View File

@@ -14,6 +14,7 @@ from core.db.models import ReadStatus, User, Chat, Message
from .managers import SocketManager
from . import schema
from .services import get_chat
logger = logging.getLogger(__name__)
socket_manager = SocketManager()
@@ -28,7 +29,8 @@ async def send_new_message(
incoming_message: schema.WSMessage,
):
chat_guid: str = str(incoming_message.chat_guid)
chat: Chat | None = await CRUD(db_session, Chat).get(filters={'guid': chat_guid})
# chat: Chat | None = await CRUD(db_session, Chat).get(filters={'guid': chat_guid, 'is_deleted': False}
chat: Chat | None = await get_chat(chat_guid, current_user, db_session)
# 判断是否为新聊天
if not chats or chat_guid not in chats:
@@ -56,8 +58,6 @@ async def send_new_message(
await db_session.flush()
await db_session.commit()
# await db_session.refresh(message, attribute_names=["user", "chat"])
# await db_session.refresh(chat, attribute_names=["users"])
except Exception as exc_info:
await db_session.rollback()