From 4f2cf7885dc64e9911d11bd57219870ae914596a Mon Sep 17 00:00:00 2001 From: padreug Date: Sun, 10 Aug 2025 17:30:16 +0200 Subject: [PATCH] feat: Add debug logging for message sorting in Nostr chat - Enhance the computed property in ChatComponent to include detailed debug logging for message sorting by timestamp. This addition aids in development by providing insights into the message order and content, improving troubleshooting capabilities. --- src/components/nostr/ChatComponent.vue | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/nostr/ChatComponent.vue b/src/components/nostr/ChatComponent.vue index e48cdd1..47f14c7 100644 --- a/src/components/nostr/ChatComponent.vue +++ b/src/components/nostr/ChatComponent.vue @@ -424,7 +424,22 @@ const currentMessages = computed(() => { const peerMessages = messages.value.get(selectedPeer.value.pubkey) || [] // Sort messages by timestamp (oldest first) to ensure chronological order - return [...peerMessages].sort((a, b) => a.created_at - b.created_at) + const sortedMessages = [...peerMessages].sort((a, b) => a.created_at - b.created_at) + + // Debug logging for message sorting (only in development) + if (process.env.NODE_ENV === 'development' && sortedMessages.length > 0) { + console.log(`🔧 Message sorting for peer ${selectedPeer.value.username}:`) + console.log(` Total messages: ${sortedMessages.length}`) + console.log(` First message: ${new Date(sortedMessages[0].created_at * 1000).toLocaleString()}`) + console.log(` Last message: ${new Date(sortedMessages[sortedMessages.length - 1].created_at * 1000).toLocaleString()}`) + + // Show first few messages with timestamps + sortedMessages.slice(0, 3).forEach((msg, i) => { + console.log(` ${i + 1}. ${msg.content.substring(0, 30)}... (${new Date(msg.created_at * 1000).toLocaleString()})`) + }) + } + + return sortedMessages }) // Sort peers by latest message timestamp (newest first) and unread status