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

@ -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 {