chore: remove nostrchat debug logs
This commit is contained in:
parent
4f97ca7b6b
commit
7829635de8
2 changed files with 13 additions and 200 deletions
|
|
@ -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()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -92,30 +92,19 @@ export function useNostrChat() {
|
|||
const currentUser = computed(() => {
|
||||
const user = auth.currentUser.value
|
||||
if (!user) {
|
||||
console.log('🔍 useNostrChat: No user available from auth system')
|
||||
return null
|
||||
}
|
||||
|
||||
console.log('🔍 useNostrChat: Full user data from LNBits:', user)
|
||||
console.log('🔍 useNostrChat: User pubkey:', user.pubkey)
|
||||
console.log('🔍 useNostrChat: User prvkey:', user.prvkey)
|
||||
console.log('🔍 useNostrChat: User prvkey type:', typeof user.prvkey)
|
||||
console.log('🔍 useNostrChat: User prvkey length:', user.prvkey?.length)
|
||||
|
||||
// Check if the user has a pubkey field
|
||||
if (!user.pubkey) {
|
||||
console.log('🔍 useNostrChat: User has no pubkey field')
|
||||
return null
|
||||
}
|
||||
|
||||
// Check if the user has a prvkey field
|
||||
if (!user.prvkey) {
|
||||
console.log('🔍 useNostrChat: User has no prvkey field')
|
||||
return null
|
||||
}
|
||||
|
||||
console.log('🔍 useNostrChat: User has both pubkey and prvkey, returning user object')
|
||||
|
||||
// Use the actual user data - assume prvkey and pubkey contain real Nostr keys
|
||||
return {
|
||||
pubkey: user.pubkey,
|
||||
|
|
@ -219,7 +208,6 @@ export function useNostrChat() {
|
|||
|
||||
// Also clear any processed message IDs from the global set that might be from this peer
|
||||
// This helps prevent duplicate message issues
|
||||
console.log(`Marked messages as read for peer: ${peerPubkey}`)
|
||||
}
|
||||
|
||||
// Load unread counts from localStorage
|
||||
|
|
@ -229,7 +217,7 @@ export function useNostrChat() {
|
|||
key.startsWith(`${UNREAD_MESSAGES_KEY}-`)
|
||||
)
|
||||
|
||||
console.log('Loading unread counts from localStorage. Found keys:', keys)
|
||||
|
||||
|
||||
for (const key of keys) {
|
||||
const peerPubkey = key.replace(`${UNREAD_MESSAGES_KEY}-`, '')
|
||||
|
|
@ -248,17 +236,11 @@ export function useNostrChat() {
|
|||
|
||||
// Update the stored count to match reality
|
||||
if (actualUnreadCount !== unreadData.unreadCount) {
|
||||
console.log(`Correcting unread count for peer ${peerPubkey}: stored=${unreadData.unreadCount}, actual=${actualUnreadCount}`)
|
||||
unreadData.unreadCount = actualUnreadCount
|
||||
saveUnreadData(peerPubkey, unreadData)
|
||||
}
|
||||
|
||||
console.log(`Peer ${peerPubkey}:`, {
|
||||
lastReadTimestamp: unreadData.lastReadTimestamp,
|
||||
unreadCount: unreadData.unreadCount,
|
||||
processedMessageIdsCount: unreadData.processedMessageIds.size,
|
||||
messageCount: peerMessages.length
|
||||
})
|
||||
|
||||
|
||||
if (actualUnreadCount > 0) {
|
||||
unreadCounts.value.set(peerPubkey, actualUnreadCount)
|
||||
|
|
@ -319,8 +301,8 @@ export function useNostrChat() {
|
|||
|
||||
// Debug unread data for a peer
|
||||
const debugUnreadData = (peerPubkey: string): void => {
|
||||
const unreadData = getUnreadData(peerPubkey)
|
||||
console.log(`Unread data for ${peerPubkey}:`, unreadData)
|
||||
// Function kept for potential future debugging
|
||||
getUnreadData(peerPubkey)
|
||||
}
|
||||
|
||||
// Get relay configuration
|
||||
|
|
@ -340,7 +322,7 @@ export function useNostrChat() {
|
|||
await relayHub.connect()
|
||||
}
|
||||
|
||||
console.log('Connected to relays via RelayHub')
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to connect to relays:', error)
|
||||
throw error
|
||||
|
|
@ -351,7 +333,7 @@ export function useNostrChat() {
|
|||
const disconnect = () => {
|
||||
// Note: We don't disconnect the relay hub here as other components might be using it
|
||||
// The relay hub will be managed at the app level
|
||||
console.log('Chat disconnected from relays (relay hub remains active)')
|
||||
|
||||
}
|
||||
|
||||
// Load current user from LNBits
|
||||
|
|
@ -429,7 +411,7 @@ export function useNostrChat() {
|
|||
authors: [peerPubkey] // Messages from this specific peer
|
||||
}
|
||||
|
||||
console.log('Subscribing to peer with filter:', filter)
|
||||
|
||||
|
||||
// Use the relay hub to subscribe
|
||||
const unsubscribe = relayHub.subscribe({
|
||||
|
|
@ -440,7 +422,7 @@ export function useNostrChat() {
|
|||
}
|
||||
})
|
||||
|
||||
console.log('Successfully subscribed to peer:', peerPubkey)
|
||||
|
||||
|
||||
return unsubscribe
|
||||
} catch (error) {
|
||||
|
|
@ -451,9 +433,6 @@ export function useNostrChat() {
|
|||
|
||||
// Subscribe to a peer for notifications only (without loading full message history)
|
||||
const subscribeToPeerForNotifications = async (peerPubkey: string) => {
|
||||
console.log('=== SUBSCRIBE TO PEER FOR NOTIFICATIONS START ===')
|
||||
console.log('Peer pubkey:', peerPubkey)
|
||||
|
||||
if (!currentUser.value) {
|
||||
console.warn('No user logged in - cannot subscribe to peer notifications')
|
||||
return null
|
||||
|
|
@ -470,12 +449,9 @@ export function useNostrChat() {
|
|||
}
|
||||
|
||||
const myPubkey = currentUser.value.pubkey
|
||||
console.log('My pubkey:', myPubkey)
|
||||
|
||||
// Subscribe to new messages only (no historical messages)
|
||||
const relayConfigs = getRelays()
|
||||
console.log('Subscribing to notifications for peer:', peerPubkey, 'with my pubkey:', myPubkey)
|
||||
console.log('Using relays:', relayConfigs.map(r => r.url))
|
||||
|
||||
const filters = [
|
||||
{
|
||||
|
|
@ -490,29 +466,18 @@ export function useNostrChat() {
|
|||
}
|
||||
]
|
||||
|
||||
console.log('Notification subscription filters:', JSON.stringify(filters, null, 2))
|
||||
|
||||
const unsubscribe = relayHub.subscribe({
|
||||
id: `notifications-${peerPubkey}-${Date.now()}`,
|
||||
filters,
|
||||
relays: relayConfigs.map(r => r.url),
|
||||
onEvent: (event: any) => {
|
||||
console.log('Received notification event:', {
|
||||
id: event.id,
|
||||
author: event.pubkey,
|
||||
forPeer: peerPubkey,
|
||||
tags: event.tags,
|
||||
contentLength: event.content?.length || 0
|
||||
})
|
||||
handleIncomingMessage(event, peerPubkey)
|
||||
},
|
||||
onEose: () => {
|
||||
console.log('Notification subscription closed for peer:', peerPubkey)
|
||||
// Notification subscription closed
|
||||
}
|
||||
})
|
||||
|
||||
console.log('Successfully created notification subscription for peer:', peerPubkey)
|
||||
console.log('=== SUBSCRIBE TO PEER FOR NOTIFICATIONS END ===')
|
||||
return unsubscribe
|
||||
}
|
||||
|
||||
|
|
@ -527,7 +492,6 @@ export function useNostrChat() {
|
|||
|
||||
// Check if we've already processed this message to prevent duplicates
|
||||
if (processedMessageIds.value.has(event.id)) {
|
||||
console.log('Message already processed, skipping:', event.id)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -536,14 +500,7 @@ export function useNostrChat() {
|
|||
// This is the public key of the other party in the conversation
|
||||
const isSentByMe = event.pubkey === currentUser.value.pubkey
|
||||
|
||||
console.log('Decrypting message:', {
|
||||
eventId: event.id,
|
||||
isSentByMe,
|
||||
eventPubkey: event.pubkey,
|
||||
myPubkey: currentUser.value.pubkey,
|
||||
peerPubkey,
|
||||
contentLength: event.content.length
|
||||
})
|
||||
|
||||
|
||||
const decryptedContent = await nip04.decrypt(
|
||||
currentUser.value.prvkey,
|
||||
|
|
@ -551,11 +508,7 @@ export function useNostrChat() {
|
|||
event.content
|
||||
)
|
||||
|
||||
console.log('Message decrypted successfully:', {
|
||||
eventId: event.id,
|
||||
contentLength: decryptedContent.length,
|
||||
isSentByMe
|
||||
})
|
||||
|
||||
|
||||
// Create chat message
|
||||
const message: ChatMessage = {
|
||||
|
|
@ -589,10 +542,6 @@ export function useNostrChat() {
|
|||
// Save to localStorage
|
||||
unreadData.unreadCount = newCount
|
||||
saveUnreadData(peerPubkey, unreadData)
|
||||
|
||||
console.log(`Message marked as unread for peer ${peerPubkey}. Count: ${newCount}`)
|
||||
} else {
|
||||
console.log(`Message not marked as unread (created before last read): ${event.created_at} <= ${unreadData.lastReadTimestamp}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -606,8 +555,6 @@ export function useNostrChat() {
|
|||
if (onMessageAdded.value) {
|
||||
onMessageAdded.value(peerPubkey)
|
||||
}
|
||||
|
||||
console.log('Message processed and added to chat:', message)
|
||||
} catch (error) {
|
||||
console.error('Failed to decrypt message:', error)
|
||||
}
|
||||
|
|
@ -615,24 +562,12 @@ export function useNostrChat() {
|
|||
|
||||
// Send message to a peer
|
||||
const sendMessage = async (peerPubkey: string, content: string) => {
|
||||
console.log('🔍 sendMessage: Starting message send...')
|
||||
console.log('🔍 sendMessage: peerPubkey:', peerPubkey)
|
||||
console.log('🔍 sendMessage: content length:', content.length)
|
||||
|
||||
if (!currentUser.value) {
|
||||
console.log('🔍 sendMessage: currentUser.value is null/undefined')
|
||||
throw new Error('No user logged in - please authenticate first')
|
||||
}
|
||||
|
||||
console.log('🔍 sendMessage: currentUser.value:', currentUser.value)
|
||||
console.log('🔍 sendMessage: currentUser.value.pubkey:', currentUser.value.pubkey)
|
||||
console.log('🔍 sendMessage: currentUser.value.prvkey:', currentUser.value.prvkey)
|
||||
console.log('🔍 sendMessage: currentUser.value.prvkey type:', typeof currentUser.value.prvkey)
|
||||
console.log('🔍 sendMessage: currentUser.value.prvkey length:', currentUser.value.prvkey?.length)
|
||||
|
||||
// Check if we have the required Nostr keypair
|
||||
if (!currentUser.value.prvkey) {
|
||||
console.log('🔍 sendMessage: prvkey is falsy, throwing error')
|
||||
throw new Error('Nostr private key not available. Please ensure your LNBits account has Nostr keys configured.')
|
||||
}
|
||||
|
||||
|
|
@ -783,7 +718,7 @@ export function useNostrChat() {
|
|||
|
||||
// Store peers in the singleton state
|
||||
peers.value = loadedPeers
|
||||
console.log(`Loaded ${loadedPeers.length} peers`)
|
||||
|
||||
|
||||
return loadedPeers
|
||||
|
||||
|
|
@ -796,13 +731,11 @@ export function useNostrChat() {
|
|||
// Subscribe to all peers for notifications (without loading full message history)
|
||||
const subscribeToAllPeersForNotifications = async (peers: any[]) => {
|
||||
if (!peers.length) {
|
||||
console.log('No peers to subscribe to')
|
||||
return
|
||||
}
|
||||
|
||||
// Wait for connection to be established
|
||||
if (!relayHub.isConnected.value) {
|
||||
console.log('Waiting for connection to be established before subscribing to peers')
|
||||
// Wait a bit for connection to establish
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
|
||||
|
|
@ -812,8 +745,6 @@ export function useNostrChat() {
|
|||
}
|
||||
}
|
||||
|
||||
console.log(`Subscribing to ${peers.length} peers for notifications`)
|
||||
|
||||
// Subscribe to each peer for notifications
|
||||
for (const peer of peers) {
|
||||
try {
|
||||
|
|
@ -822,8 +753,6 @@ export function useNostrChat() {
|
|||
console.error(`Failed to subscribe to peer ${peer.username} (${peer.pubkey}):`, error)
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Successfully subscribed to ${peers.length} peers for notifications`)
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue