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; }