feat: Enhance peer subscription and logging in Nostr chat

- Improve the subscription process for peers by adding detailed logging for subscription attempts and results.
- Update the ChatComponent to provide a summary of successful and failed subscriptions.
- Enhance the useNostrChat composable with additional logging for subscription filters and incoming message handling.
- Ensure better visibility into connection state changes and subscription readiness.
This commit is contained in:
padreug 2025-08-08 22:27:33 +02:00
parent d48cbbeec0
commit a0ae70670d
2 changed files with 68 additions and 18 deletions

View file

@ -341,6 +341,9 @@ 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
@ -362,28 +365,40 @@ 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 = [
{
kinds: [4],
authors: [peerPubkey],
'#p': [myPubkey]
},
{
kinds: [4],
authors: [myPubkey],
'#p': [peerPubkey]
}
]
console.log('Notification subscription filters:', JSON.stringify(filters, null, 2))
const sub = pool.value.subscribeMany(
relayConfigs.map(r => r.url),
[
{
kinds: [4],
authors: [peerPubkey],
'#p': [myPubkey]
},
{
kinds: [4],
authors: [myPubkey],
'#p': [peerPubkey]
}
],
filters,
{
onevent(event) {
console.log('Received notification event:', event.id, 'author:', event.pubkey, 'for peer:', peerPubkey)
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() {
@ -393,6 +408,7 @@ export function useNostrChat() {
)
console.log('Successfully created notification subscription for peer:', peerPubkey)
console.log('=== SUBSCRIBE TO PEER FOR NOTIFICATIONS END ===')
return sub
}
@ -446,11 +462,16 @@ export function useNostrChat() {
// Handle incoming message
const handleIncomingMessage = async (event: any, peerPubkey: string) => {
console.log('=== HANDLE INCOMING MESSAGE START ===')
console.log('Event ID:', event.id, 'Peer:', peerPubkey)
if (processedMessageIds.value.has(event.id)) {
console.log('Message already processed, skipping:', event.id)
return
}
processedMessageIds.value.add(event.id)
console.log('Added to processed messages:', event.id)
console.log('Handling incoming message:', {
eventId: event.id,