diff --git a/ai_chat.db b/ai_chat.db index e6c3e50..93f1bb3 100644 Binary files a/ai_chat.db and b/ai_chat.db differ diff --git a/main.py b/main.py index 8ed6166..519b23a 100644 --- a/main.py +++ b/main.py @@ -422,7 +422,7 @@ async def update_config(data: dict, db: Session = Depends(get_db)): # ==================== Matrix消息处理回调 ==================== -async def handle_matrix_message(action: str, conversation_id: str = None, user_message: str = None, room_id: str = None, message_id: int = None): +async def handle_matrix_message(action: str, conversation_id: str = None, user_message: str = None, room_id: str = None, message_id: int = None, sender: str = None): """处理从Matrix收到的消息""" if action == "new_conversation": @@ -433,6 +433,30 @@ async def handle_matrix_message(action: str, conversation_id: str = None, user_m }) return + if action == "user_message": + # 用户消息 - 同步到网页端 + db = SessionLocal() + try: + conv_service = ConversationService(db) + conversation = conv_service.get_conversation(conversation_id) + if conversation: + # 发送用户消息通知到网页端 + await manager.send_to_user(MAIN_USER_ID, { + "type": "user_message", + "conversation_id": conversation_id, + "message": { + "id": message_id, + "role": "user", + "content": user_message, + "source": "matrix", + "sender": sender, + "created_at": datetime.now().isoformat() + } + }) + finally: + db.close() + return + if action == "chat": db = SessionLocal() try: diff --git a/matrix_store/@tester:matrix.tphai.com_MIPPYHRVAS.blacklisted_devices b/matrix_store/@tester:matrix.tphai.com_MIPPYHRVAS.blacklisted_devices new file mode 100644 index 0000000..e69de29 diff --git a/matrix_store/@tester:matrix.tphai.com_MIPPYHRVAS.ignored_devices b/matrix_store/@tester:matrix.tphai.com_MIPPYHRVAS.ignored_devices new file mode 100644 index 0000000..e69de29 diff --git a/matrix_store/@tester:matrix.tphai.com_MIPPYHRVAS.trusted_devices b/matrix_store/@tester:matrix.tphai.com_MIPPYHRVAS.trusted_devices new file mode 100644 index 0000000..3f32624 --- /dev/null +++ b/matrix_store/@tester:matrix.tphai.com_MIPPYHRVAS.trusted_devices @@ -0,0 +1,4 @@ +@huangzhuang_bro:matrix.tphai.com BQHGFLQEPR matrix-ed25519 IrEHmvqotfHKLyx1JRJp4RthUVyBT8qQX72qBifRRyQ +@tester:matrix.tphai.com AJFVRTHLJY matrix-ed25519 4mRjLhM8xbwjkwQP2T/iB3UZJoaADgP6cCVUiB8AtSk +@tester:matrix.tphai.com GVSFGGYNJL matrix-ed25519 8qV2own4G3m2nki+izFDBOrAxtbGl8RoneM3qUPkThU +@tester:matrix.tphai.com IMEQIQPXTR matrix-ed25519 6Yd4lmhP6jdkkNvh1rIw6TRK331ZUyiAt5G5hPeYqSE diff --git a/services/__pycache__/matrix_service.cpython-310.pyc b/services/__pycache__/matrix_service.cpython-310.pyc index e4f2e78..6fe022c 100644 Binary files a/services/__pycache__/matrix_service.cpython-310.pyc and b/services/__pycache__/matrix_service.cpython-310.pyc differ diff --git a/services/matrix_service.py b/services/matrix_service.py index 8e32b48..45e0121 100644 --- a/services/matrix_service.py +++ b/services/matrix_service.py @@ -224,6 +224,17 @@ class MatrixBot: } ) + # 立即通知网页端有新用户消息(通过回调) + if self.on_message_callback: + await self.on_message_callback( + action="user_message", + conversation_id=conversation.conversation_id, + user_message=message_text, + room_id=room.room_id, + message_id=user_msg.id, + sender=sender + ) + # 发送"正在输入"状态 try: await self.client.room_typing(room.room_id, typing_state=True)