From 8cde36c08c44c3b7f5d35d5b76dc722df3bbce0c Mon Sep 17 00:00:00 2001 From: Gigi Date: Mon, 20 Oct 2025 11:17:30 +0200 Subject: [PATCH] fix(archive): add 'a' coord tag to mark-as-read reactions for articles; archiveController maps a-tag instantly; add debug --- src/components/ContentPanel.tsx | 11 ++++++++++- src/components/Me.tsx | 10 ++++++++-- src/services/archiveController.ts | 19 +++++++++++++++++-- src/services/reactionService.ts | 7 ++++++- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/components/ContentPanel.tsx b/src/components/ContentPanel.tsx index 0bfcb008..d0b413dd 100644 --- a/src/components/ContentPanel.tsx +++ b/src/components/ContentPanel.tsx @@ -621,7 +621,16 @@ const ContentPanel: React.FC = ({ currentArticle.pubkey, currentArticle.kind, activeAccount, - relayPool + relayPool, + { + aCoord: (() => { + try { + const dTag = currentArticle.tags.find(t => t[0] === 'd')?.[1] + if (!dTag) return undefined + return `${30023}:${currentArticle.pubkey}:${dTag}` + } catch { return undefined } + })() + } ) // Update archiveController immediately try { diff --git a/src/components/Me.tsx b/src/components/Me.tsx index 37b7ab86..175b1f98 100644 --- a/src/components/Me.tsx +++ b/src/components/Me.tsx @@ -635,6 +635,10 @@ const Me: React.FC = ({ // Debug logs for archive filter issues if (readingProgressFilter === 'archive') { + const ids = archiveController.getMarkedIds() + const readIds = new Set(readsWithProgress.map(i => i.id)) + const matches = ids.filter(id => readIds.has(id)) + const nonMatches = ids.filter(id => !readIds.has(id)).slice(0, 5) console.log('[archive][me] counts', { reads: reads.length, readsWithProgress: readsWithProgress.length, @@ -642,8 +646,10 @@ const Me: React.FC = ({ links: links.length, linksWithProgress: linksWithProgress.length, filteredLinks: filteredLinks.length, - markedIds: archiveController.getMarkedIds().length, - sampleMarked: archiveController.getMarkedIds().slice(0, 3) + markedIds: ids.length, + sampleMarked: ids.slice(0, 3), + matches: matches.length, + nonMatches }) } const sections: Array<{ key: string; title: string; items: IndividualBookmark[] }> = diff --git a/src/services/archiveController.ts b/src/services/archiveController.ts index 5ac55966..577adc6a 100644 --- a/src/services/archiveController.ts +++ b/src/services/archiveController.ts @@ -85,6 +85,21 @@ class ArchiveController { const handleEventReaction = (evt: NostrEvent) => { if (evt.content !== MARK_AS_READ_EMOJI) return + // Direct coordinate tag ('a') - can be mapped immediately + const aTag = evt.tags.find(t => t[0] === 'a')?.[1] + if (aTag) { + try { + const [kindStr, pubkey, identifier] = aTag.split(':') + const kind = Number(kindStr) + if (kind === KINDS.BlogPost && pubkey && identifier) { + const naddr = nip19.naddrEncode({ kind, pubkey, identifier }) + this.markedIds.add(naddr) + this.emit() + console.log('[archive] mark naddr via a-tag:', naddr.slice(0, 24), '...') + return + } + } catch { /* ignore malformed a-tag */ } + } const eTag = evt.tags.find(t => t[0] === 'e')?.[1] if (!eTag) return this.pendingEventIds.add(eTag) @@ -130,8 +145,8 @@ class ArchiveController { const stillPending = new Set() for (const eId of this.pendingEventIds) { try { - // @ts-expect-error eventStore may have getEvent - const evt: NostrEvent | undefined = (eventStore as unknown as { getEvent?: (id: string) => NostrEvent | undefined }).getEvent?.(eId) + const store = eventStore as unknown as { getEvent?: (id: string) => NostrEvent | undefined } + const evt: NostrEvent | undefined = typeof store.getEvent === 'function' ? store.getEvent(eId) : undefined if (evt && evt.kind === KINDS.BlogPost) { const dTag = evt.tags.find(t => t[0] === 'd')?.[1] if (dTag) { diff --git a/src/services/reactionService.ts b/src/services/reactionService.ts index b4494ba4..b09446a7 100644 --- a/src/services/reactionService.ts +++ b/src/services/reactionService.ts @@ -23,7 +23,8 @@ export async function createEventReaction( eventAuthor: string, eventKind: number, account: IAccount, - relayPool: RelayPool + relayPool: RelayPool, + options?: { aCoord?: string } ): Promise { const factory = new EventFactory({ signer: account }) @@ -32,6 +33,10 @@ export async function createEventReaction( ['p', eventAuthor], ['k', eventKind.toString()] ] + if (options?.aCoord) { + tags.push(['a', options.aCoord]) + console.log('[archive] createEventReaction add a-tag:', options.aCoord) + } const draft = await factory.create(async () => ({ kind: 7, // Reaction