diff --git a/README.md b/README.md index 4d8c483..c653780 100644 --- a/README.md +++ b/README.md @@ -355,6 +355,11 @@ Access the Direct Messages feature: 4. Press Enter or click Send 5. Click "Back" button to return to the main chat view +**Persistence:** +- The app remembers your last selected conversation +- When you return to the DM page, it automatically opens the last conversation you were viewing +- This works similarly to how the main page remembers your selected channel + **Note:** Only client contacts (CLI) are shown in the dropdown. Repeaters (REP), rooms (ROOM), and sensors (SENS) are automatically filtered out. **Message status indicators:** diff --git a/app/static/js/dm.js b/app/static/js/dm.js index 5b055a2..0ab2e90 100644 --- a/app/static/js/dm.js +++ b/app/static/js/dm.js @@ -39,11 +39,17 @@ document.addEventListener('DOMContentLoaded', async function() { // Load connection status await loadStatus(); - // Check for initial conversation from URL parameter + // Check for initial conversation from URL parameter, or restore last active conversation if (window.MC_CONFIG && window.MC_CONFIG.initialConversation) { const convId = window.MC_CONFIG.initialConversation; // Find the conversation in the list or use the ID directly selectConversation(convId); + } else { + // Restore last selected conversation from localStorage + const savedConversation = localStorage.getItem('mc_active_dm_conversation'); + if (savedConversation) { + selectConversation(savedConversation); + } } // Setup auto-refresh @@ -244,6 +250,9 @@ function populateConversationSelector() { async function selectConversation(conversationId) { currentConversationId = conversationId; + // Save to localStorage for next visit + localStorage.setItem('mc_active_dm_conversation', conversationId); + // Find the conversation to get recipient name const conv = dmConversations.find(c => c.conversation_id === conversationId); if (conv) { @@ -287,6 +296,9 @@ function clearConversation() { currentConversationId = null; currentRecipient = null; + // Clear from localStorage + localStorage.removeItem('mc_active_dm_conversation'); + // Disable input const input = document.getElementById('dmMessageInput'); const sendBtn = document.getElementById('dmSendBtn');