chore: remove nostrchat debug logs

This commit is contained in:
padreug 2025-08-11 09:57:27 +02:00
parent 4f97ca7b6b
commit 7829635de8
2 changed files with 13 additions and 200 deletions

View file

@ -412,10 +412,7 @@ const {
markMessagesAsRead,
getUnreadCount,
totalUnreadCount,
getLatestMessageTimestamp,
clearAllUnreadCounts,
debugUnreadData,
getUnreadData
getLatestMessageTimestamp
} = nostrChat
// Computed
@ -426,19 +423,6 @@ const currentMessages = computed(() => {
// Sort messages by timestamp (oldest first) to ensure chronological order
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
})
@ -463,16 +447,6 @@ const sortedPeers = computed(() => {
return (a.username || '').localeCompare(b.username || '')
})
// Debug logging (only in development)
if (process.env.NODE_ENV === 'development' && sorted.length > 0) {
console.log('Sorted peers:', sorted.map(p => ({
username: p.username,
pubkey: p.pubkey.slice(0, 8) + '...',
latestTimestamp: getLatestMessageTimestamp(p.pubkey),
unreadCount: getUnreadCount(p.pubkey)
})))
}
return sorted
})
@ -522,7 +496,6 @@ const goBackToPeers = () => {
const refreshPeers = async () => {
console.log('Refreshing peers and chat data...')
isLoading.value = true
try {
await nostrChat.loadPeers()
@ -558,20 +531,6 @@ const sendMessage = async () => {
if (!selectedPeer.value || !messageInput.value.trim()) return
try {
// Add debugging information
console.log('🔍 ChatComponent: Attempting to send message...')
console.log('🔍 ChatComponent: Selected peer:', selectedPeer.value)
console.log('🔍 ChatComponent: Message content:', messageInput.value)
// Check authentication status
const keyStatus = nostrChat.getNostrKeyStatus()
console.log('🔍 ChatComponent: Nostr key status:', keyStatus)
// Check if user is logged in
console.log('🔍 ChatComponent: Is authenticated:', nostrChat.isLoggedIn.value)
console.log('🔍 ChatComponent: Current user:', nostrChat.currentUser.value)
console.log('🔍 ChatComponent: Has Nostr keys:', nostrChat.hasNostrKeys.value)
await sendNostrMessage(selectedPeer.value.pubkey, messageInput.value)
messageInput.value = ''
@ -585,17 +544,13 @@ const sendMessage = async () => {
}
const scrollToBottom = () => {
console.log('scrollToBottom called')
nextTick(() => {
if (scrollTarget.value) {
console.log('Found scrollTarget, scrolling to bottom')
// Use scrollIntoView on the target element
scrollTarget.value.scrollIntoView({
behavior: 'smooth',
block: 'end'
})
} else {
console.log('No scrollTarget found')
}
})
}
@ -623,60 +578,7 @@ const getPeerInitials = (peer: Peer) => {
return peer.pubkey.slice(0, 2).toUpperCase()
}
// Debug function to reset unread counts (can be called from browser console)
const debugResetUnreadCounts = () => {
console.log('🔧 Debug: Resetting all unread counts...')
clearAllUnreadCounts()
console.log('🔧 Debug: Unread counts reset. You may need to refresh the page to see the changes.')
}
// Debug function to show unread count details for a specific peer
const debugPeerUnreadCounts = (peerPubkey?: string) => {
if (peerPubkey) {
console.log(`🔧 Debug: Unread count details for peer ${peerPubkey}:`)
debugUnreadData(peerPubkey)
console.log(`Current unread count: ${getUnreadCount(peerPubkey)}`)
// Show timestamp details for debugging
const peerMessages = messages.value.get(peerPubkey) || []
const unreadData = getUnreadData(peerPubkey)
console.log(`Last read timestamp: ${unreadData.lastReadTimestamp} (${new Date(unreadData.lastReadTimestamp * 1000).toLocaleString()})`)
console.log(`Total messages: ${peerMessages.length}`)
// Show messages that would count as unread
const unreadMessages = peerMessages.filter(msg => !msg.sent && msg.created_at > unreadData.lastReadTimestamp)
console.log(`Messages that count as unread: ${unreadMessages.length}`)
unreadMessages.forEach(msg => {
console.log(` - ${msg.content.substring(0, 50)}... (${new Date(msg.created_at * 1000).toLocaleString()})`)
})
} else {
console.log('🔧 Debug: All unread counts:')
console.log('Total unread count:', totalUnreadCount.value)
// Simplified peer iteration to avoid TypeScript issues
const peerList = peers.value
if (peerList && peerList.length > 0) {
peerList.forEach((peer: any) => {
const count = getUnreadCount(peer.pubkey)
if (count > 0) {
const name = peer.username || peer.pubkey.slice(0, 8)
console.log(`${name}: ${count}`)
}
})
}
}
}
// Make debug functions available globally for browser console access
if (typeof window !== 'undefined') {
// Use type assertion to avoid TypeScript errors
const globalWindow = window as any
globalWindow.debugResetUnreadCounts = debugResetUnreadCounts
globalWindow.debugPeerUnreadCounts = debugPeerUnreadCounts
console.log('🔧 Debug functions available:')
console.log(' - debugResetUnreadCounts() - reset all unread counts')
console.log(' - debugPeerUnreadCounts(peerPubkey?) - show unread count details')
}
// Lifecycle
onMounted(async () => {
@ -685,31 +587,21 @@ onMounted(async () => {
// Set up message callback
onMessageAdded.value = (peerPubkey: string) => {
console.log('Message added callback triggered for peer:', peerPubkey)
if (selectedPeer.value && selectedPeer.value.pubkey === peerPubkey) {
console.log('Triggering scroll for current peer')
nextTick(() => {
scrollToBottom()
})
}
}
console.log('Chat component mounted - checking connection state...')
// If not connected, connect
if (!isConnected.value) {
console.log('Not connected, connecting to chat...')
await connect()
} else {
console.log('Already connected to chat')
}
// If no peers loaded, load them
if (peers.value.length === 0) {
console.log('No peers loaded, loading peers...')
await nostrChat.loadPeers()
} else {
console.log('Peers already loaded:', peers.value.length)
}
})
@ -720,21 +612,13 @@ onUnmounted(() => {
// Watch for connection state changes
watch(isConnected, async (connected, prevConnected) => {
console.log('Connection state changed:', { connected, prevConnected, peerCount: peers.value.length })
// Note: Peer subscriptions are handled by the preloader
})
// Watch for new messages and scroll to bottom
watch(currentMessages, (newMessages, oldMessages) => {
console.log('Messages changed:', {
newLength: newMessages.length,
oldLength: oldMessages?.length,
isNewMessage: !oldMessages || newMessages.length > oldMessages.length
})
// Scroll to bottom when new messages are added
if (newMessages.length > 0 && (!oldMessages || newMessages.length > oldMessages.length)) {
console.log('Triggering scroll to bottom')
nextTick(() => {
scrollToBottom()
})