This commit is contained in:
2026-06-14 11:16:42 +08:00
parent ca39190ad7
commit c9fc87cd89
35 changed files with 1480 additions and 18 deletions
+4
View File
@@ -17,6 +17,9 @@ class EventType(str, Enum):
CHAT_TYPING_INDICATOR = "chat.typing"
CHAT_READ_RECEIPT = "chat.read"
CHAT_MESSAGE_DELETED = "chat.message_deleted"
CHAT_MESSAGE_RECALLED = "chat.message_recalled"
CHAT_REACTION_ADDED = "chat.reaction_added"
CHAT_REACTION_REMOVED = "chat.reaction_removed"
CONVERSATION_UPDATED = "conversation.updated"
CONVERSATION_MEMBER_ADDED = "conversation.member_added"
CONVERSATION_MEMBER_REMOVED = "conversation.member_removed"
@@ -24,6 +27,7 @@ class EventType(str, Enum):
FRIEND_ACCEPTED = "friend.accepted"
PRESENCE_ONLINE = "presence.online"
PRESENCE_OFFLINE = "presence.offline"
PRESENCE_MENTIONED = "presence.mentioned"
ECHO_SEND = "echo.send"
HEARTBEAT_SYNC = "heartbeat.sync"
FLASH_SPAWN = "flash.spawn"
+12
View File
@@ -22,6 +22,7 @@ async def handle_chat_send(ws: WebSocket, user_id: str, data: dict, db: AsyncSes
content=data["content"],
msg_type=data.get("type", "text"),
reply_to_id=data.get("reply_to_id"),
mentioned_user_ids=data.get("mentioned_user_ids"),
)
await db.commit()
@@ -60,6 +61,8 @@ async def handle_chat_send(ws: WebSocket, user_id: str, data: dict, db: AsyncSes
"reply_to_id": message.reply_to_id,
"reply_to_content": reply_to_content,
"reply_to_sender_name": reply_to_sender_name,
"mentions": data.get("mentioned_user_ids"),
"is_recalled": False,
"created_at": message.created_at.isoformat(),
}
@@ -69,6 +72,15 @@ async def handle_chat_send(ws: WebSocket, user_id: str, data: dict, db: AsyncSes
await manager.broadcast_to_conversation(
member_ids, EventType.CHAT_MESSAGE, msg_data
)
# 被@的人:单独推送提及通知(即使免打扰也提醒)
mentioned = data.get("mentioned_user_ids") or []
for mid in mentioned:
if mid in member_ids and mid != user_id:
await manager.send_to_user(mid, EventType.PRESENCE_MENTIONED, {
"conversation_id": message.conversation_id,
"from_user_id": user_id,
"from_username": sender.username if sender else "未知",
})
except Exception as e:
await manager.send_to_user(user_id, EventType.ERROR, {"message": str(e)})