feat: Remember last selected DM conversation

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 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-01-04 13:29:04 +01:00
parent 16a76f5f71
commit 34ab437390
2 changed files with 18 additions and 1 deletions
+5
View File
@@ -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:**
+13 -1
View File
@@ -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');