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.
This commit is contained in:
padreug 2025-08-10 17:30:16 +02:00
parent 22b3c430fa
commit 4f2cf7885d

View file

@ -424,7 +424,22 @@ const currentMessages = computed(() => {
const peerMessages = messages.value.get(selectedPeer.value.pubkey) || [] const peerMessages = messages.value.get(selectedPeer.value.pubkey) || []
// Sort messages by timestamp (oldest first) to ensure chronological order // 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 // Sort peers by latest message timestamp (newest first) and unread status