From 34ab437390da27111875f7fea97113851451969b Mon Sep 17 00:00:00 2001 From: MarekWo Date: Sun, 4 Jan 2026 13:29:04 +0100 Subject: [PATCH] feat: Remember last selected DM conversation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add localStorage persistence for Direct Messages page to remember and restore the last selected conversation when user returns to the page. Changes: - Save selected conversation to localStorage when user selects a conversation - Restore last conversation on page load (if no URL parameter provided) - Clear localStorage when user returns to empty state - Updated README.md with persistence documentation - Priority: URL parameter > localStorage > empty state This improves UX by maintaining conversation context across page navigation, similar to how the main page remembers the selected channel. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- README.md | 5 +++++ app/static/js/dm.js | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) 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');