diff --git a/app/static/js/dm.js b/app/static/js/dm.js index e500049..51ad209 100644 --- a/app/static/js/dm.js +++ b/app/static/js/dm.js @@ -12,6 +12,15 @@ let dmLastSeenTimestamps = {}; let autoRefreshInterval = null; let lastMessageTimestamp = 0; // Track latest message timestamp for smart refresh +/** + * Get display-friendly name (truncate full pubkeys to short prefix) + */ +function displayName(name) { + if (!name) return 'Unknown'; + if (/^[0-9a-f]{64}$/i.test(name)) return name.substring(0, 8) + '...'; + return name; +} + // Initialize on page load document.addEventListener('DOMContentLoaded', async function() { console.log('DM page initialized'); @@ -223,12 +232,7 @@ function populateConversationSelector() { const lastSeen = dmLastSeenTimestamps[conv.conversation_id] || 0; const isUnread = conv.last_message_timestamp > lastSeen; - // If display_name is a full pubkey, show short prefix - let displayName = conv.display_name; - if (/^[0-9a-f]{64}$/i.test(displayName)) { - displayName = displayName.substring(0, 8) + '...'; - } - let label = displayName; + let label = displayName(conv.display_name); if (isUnread) { label = `* ${label}`; } @@ -292,12 +296,7 @@ async function selectConversation(conversationId) { // Find the conversation to get recipient name const conv = dmConversations.find(c => c.conversation_id === conversationId); if (conv && conv.display_name) { - // If display_name is a full pubkey (64 hex chars), show short prefix - if (/^[0-9a-f]{64}$/i.test(conv.display_name)) { - currentRecipient = conv.display_name.substring(0, 8) + '...'; - } else { - currentRecipient = conv.display_name; - } + currentRecipient = conv.display_name; } else { // Extract name from conversation_id if (conversationId.startsWith('name_')) { @@ -320,7 +319,7 @@ async function selectConversation(conversationId) { const sendBtn = document.getElementById('dmSendBtn'); if (input) { input.disabled = false; - input.placeholder = `Message ${currentRecipient}...`; + input.placeholder = `Message ${displayName(currentRecipient)}...`; } if (sendBtn) { sendBtn.disabled = false; @@ -390,7 +389,7 @@ async function loadMessages() { currentRecipient = data.display_name; const input = document.getElementById('dmMessageInput'); if (input) { - input.placeholder = `Message ${currentRecipient}...`; + input.placeholder = `Message ${displayName(currentRecipient)}...`; } }