fix: restore Debug page decrypt display via onDecryptComplete callback

Added onDecryptComplete callback to controller:
- Controller emits decrypt results (eventId, publicCount, privateCount)
- Debug subscribes to see decryption progress
- setDecryptedEvents updated with decrypt results for UI display

Debug page now shows decrypted content counts for encrypted bookmark lists (like kind:30001 Amethyst-style NIP-04 bookmarks).
This commit is contained in:
Gigi
2025-10-17 23:14:10 +02:00
parent 7a75982715
commit 29ef21a1fa
2 changed files with 30 additions and 3 deletions

View File

@@ -253,7 +253,7 @@ const Debug: React.FC<DebugProps> = ({
const { bookmarkController } = await import('../services/bookmarkController')
// Subscribe to raw events for Debug UI display
const unsubscribe = bookmarkController.onRawEvent((evt) => {
const unsubscribeRaw = bookmarkController.onRawEvent((evt) => {
// Add event immediately with live deduplication
setBookmarkEvents(prev => {
const key = getEventKey(evt)
@@ -273,12 +273,25 @@ const Debug: React.FC<DebugProps> = ({
})
})
// Subscribe to decrypt complete events for Debug UI display
const unsubscribeDecrypt = bookmarkController.onDecryptComplete((eventId, publicCount, privateCount) => {
console.log('[bunker] ✅ Auto-decrypted:', eventId.slice(0, 8), {
public: publicCount,
private: privateCount
})
setDecryptedEvents(prev => new Map(prev).set(eventId, {
public: publicCount,
private: privateCount
}))
})
// Start the controller (triggers app bookmark population too)
bookmarkController.reset()
await bookmarkController.start({ relayPool, activeAccount, accountManager })
// Clean up subscription
unsubscribe()
// Clean up subscriptions
unsubscribeRaw()
unsubscribeDecrypt()
const ms = Math.round(performance.now() - start)
setLiveTiming(prev => ({ ...prev, loadBookmarks: undefined }))

View File

@@ -38,6 +38,7 @@ function hasEncryptedContent(evt: NostrEvent): boolean {
type RawEventCallback = (event: NostrEvent) => void
type BookmarksCallback = (bookmarks: Bookmark[]) => void
type LoadingCallback = (loading: boolean) => void
type DecryptCompleteCallback = (eventId: string, publicCount: number, privateCount: number) => void
/**
* Shared bookmark streaming controller
@@ -47,6 +48,7 @@ class BookmarkController {
private rawEventListeners: RawEventCallback[] = []
private bookmarksListeners: BookmarksCallback[] = []
private loadingListeners: LoadingCallback[] = []
private decryptCompleteListeners: DecryptCompleteCallback[] = []
private currentEvents: Map<string, NostrEvent> = new Map()
private decryptedEvents: Map<string, { public: number; private: number }> = new Map()
@@ -74,6 +76,13 @@ class BookmarkController {
}
}
onDecryptComplete(cb: DecryptCompleteCallback): () => void {
this.decryptCompleteListeners.push(cb)
return () => {
this.decryptCompleteListeners = this.decryptCompleteListeners.filter(l => l !== cb)
}
}
reset(): void {
this.currentEvents.clear()
this.decryptedEvents.clear()
@@ -301,6 +310,11 @@ class BookmarkController {
private: privateItemsAll.length
})
// Emit decrypt complete for Debug UI
this.decryptCompleteListeners.forEach(cb =>
cb(evt.id, publicItemsAll.length, privateItemsAll.length)
)
// Schedule another update after decrypt
this.scheduleBookmarkUpdate(relayPool, maybeAccount, signerCandidate)
})