From 904b43d4fc1387f22ffd0633ad35831019c8f509 Mon Sep 17 00:00:00 2001 From: spencrmartin Date: Fri, 21 Nov 2025 14:22:16 -0500 Subject: [PATCH] Show loading state only for existing chats with messages Check message_count from backend session to determine if chat has existing messages. Only show loading indicator if messages need to be loaded. New chats (message_count = 0) show empty state immediately with popular topics. This prevents showing a loading spinner for brand new Matrix chats that have no message history to load. --- ui/desktop/src/contexts/TabContext.tsx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/ui/desktop/src/contexts/TabContext.tsx b/ui/desktop/src/contexts/TabContext.tsx index e5740be728..12da37b3bf 100644 --- a/ui/desktop/src/contexts/TabContext.tsx +++ b/ui/desktop/src/contexts/TabContext.tsx @@ -928,6 +928,7 @@ export const TabProvider: React.FC = ({ children }) => { // Get or create the backend session for this Matrix room (async) let backendSessionId = sessionMappingService.getGooseSessionId(roomId); + let hasExistingMessages = false; if (!backendSessionId) { console.log('📱 No existing mapping found, creating new Matrix session mapping'); @@ -943,21 +944,39 @@ export const TabProvider: React.FC = ({ children }) => { ); backendSessionId = mapping.gooseSessionId; console.log('✅ Created new backend session for Matrix room:', backendSessionId); + hasExistingMessages = false; // New session, no messages } catch (error) { console.error('❌ Failed to create backend session for Matrix room:', error); // Keep the temporary session ID - this won't have backend persistence backendSessionId = tempTab.sessionId; + hasExistingMessages = false; } } else { console.log('📱 Found existing backend session for Matrix room:', backendSessionId); + + // Check if this session has existing messages + try { + const sessionResponse = await getSession({ + path: { session_id: backendSessionId } + }); + hasExistingMessages = (sessionResponse.data?.message_count ?? 0) > 0; + console.log('📱 Session has existing messages:', hasExistingMessages, 'count:', sessionResponse.data?.message_count); + } catch (error) { + console.warn('⚠️ Failed to check message count:', error); + hasExistingMessages = true; // Assume it has messages to show loading state + } } - // Update the tab with the real backend session ID and remove loading state + // Update the tab with the real backend session ID + // Keep loading state if there are existing messages (they need to load) + // Remove loading state if it's a new chat (show empty state immediately) console.log('📱 Updating tab with backend session:', { tabId: tempTab.id, backendSessionId, roomId, - senderId + senderId, + hasExistingMessages, + willShowLoading: hasExistingMessages }); setTabStates(prev => prev.map(ts => @@ -966,7 +985,7 @@ export const TabProvider: React.FC = ({ children }) => { ...ts, tab: { ...ts.tab, sessionId: backendSessionId }, chat: { ...ts.chat, sessionId: backendSessionId }, - loadingChat: false // Remove loading state + loadingChat: hasExistingMessages // Keep loading if there are messages to load } : ts ));