From 1a5530c4bdd210805f83cc034d3decadafaf6a62 Mon Sep 17 00:00:00 2001 From: spencrmartin Date: Fri, 21 Nov 2025 09:52:46 -0500 Subject: [PATCH] DEBUG: Add extensive logging to diagnose Matrix message leakage - Added detailed logging to useSessionSharing Matrix listener setup check - Added critical debug logging to ChatInput before calling useSessionSharing - Enhanced Matrix room detection logging with timestamps - This will help identify why regular chats are still receiving Matrix messages The issue appears to be that regular chat sessions might be getting initialRoomId values when they shouldn't, causing Matrix listeners to be set up for non-Matrix chats. --- ui/desktop/src/components/ChatInput.tsx | 9 +++++++++ ui/desktop/src/hooks/useSessionSharing.ts | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ui/desktop/src/components/ChatInput.tsx b/ui/desktop/src/components/ChatInput.tsx index 6372dc70d7..840cec571d 100644 --- a/ui/desktop/src/components/ChatInput.tsx +++ b/ui/desktop/src/components/ChatInput.tsx @@ -421,6 +421,15 @@ export default function ChatInput({ } }); + // CRITICAL DEBUG: Log what we're actually passing to useSessionSharing + console.log('🚨 ChatInput: About to call useSessionSharing with:', { + sessionId: sessionId, + initialRoomId: actualMatrixRoomId, + isMatrixRoom: isMatrixRoom, + shouldSetupMatrixListeners: !!actualMatrixRoomId, + timestamp: new Date().toISOString() + }); + // Get Matrix context for current user information const { currentUser } = useMatrix(); diff --git a/ui/desktop/src/hooks/useSessionSharing.ts b/ui/desktop/src/hooks/useSessionSharing.ts index 8ef4733ed7..507aec978f 100644 --- a/ui/desktop/src/hooks/useSessionSharing.ts +++ b/ui/desktop/src/hooks/useSessionSharing.ts @@ -138,7 +138,20 @@ export const useSessionSharing = ({ // CRITICAL FIX: Only set up Matrix listeners if this session actually has a Matrix room // This prevents Matrix messages from leaking into regular chats - if (!stateRef.current.roomId && !initialRoomId) { + // Check both current state and initialRoomId parameter + const currentRoomId = stateRef.current.roomId; + const hasMatrixRoom = !!(currentRoomId || initialRoomId); + + console.log('🔍 useSessionSharing: Matrix listener setup check:', { + sessionId, + currentRoomId, + initialRoomId, + hasMatrixRoom, + stateIsShared: stateRef.current.isShared, + willSetupListeners: hasMatrixRoom + }); + + if (!hasMatrixRoom) { console.log('🚫 useSessionSharing: No Matrix room ID - skipping Matrix listener setup for regular chat session:', sessionId); return; }