From b0a368fc64c73b00b20972182676d149aa0d5ba7 Mon Sep 17 00:00:00 2001 From: Gigi Date: Sun, 19 Oct 2025 23:44:56 +0200 Subject: [PATCH] fix: properly handle kind:7 mark-as-read reactions with event ID to naddr mapping Restored kind:7 reaction handling with proper implementation: 1. Fetch kind:7 reactions with MARK_AS_READ_EMOJI 2. Extract event IDs from #e tags 3. Fetch the referenced articles (kind:30023) 4. Build mapping of event IDs to nadrs 5. Add marked articles to markedAsReadIds using their nadrs Now both kind:7 (Nostr articles) and kind:17 (URLs) mark-as-read reactions are properly tracked and will appear in /me/reads/completed. Added nip19 import for naddr encoding. --- src/services/readingProgressController.ts | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/services/readingProgressController.ts b/src/services/readingProgressController.ts index f042eea1..8f37c141 100644 --- a/src/services/readingProgressController.ts +++ b/src/services/readingProgressController.ts @@ -7,6 +7,7 @@ import { RELAYS } from '../config/relays' import { processReadingProgress } from './readingDataProcessor' import { ReadItem } from './readsService' import { MARK_AS_READ_EMOJI } from './reactionService' +import { nip19 } from 'nostr-tools' type ProgressMapCallback = (progressMap: Map) => void type LoadingCallback = (loading: boolean) => void @@ -257,6 +258,55 @@ class ReadingProgressController { } } }) + + // Also fetch kind:7 reactions (for Nostr articles) + const kind7Events = await queryEvents(relayPool, { kinds: [7], authors: [pubkey] }, { relayUrls: RELAYS }) + + if (startGeneration !== this.generation) { + return + } + + // Process kind:7 reactions - need to map event IDs to nadrs + const kind7WithMarkAsRead = kind7Events.filter(evt => evt.content === MARK_AS_READ_EMOJI) + if (kind7WithMarkAsRead.length > 0) { + // Extract event IDs from #e tags + const eventIds = Array.from(new Set( + kind7WithMarkAsRead + .flatMap(evt => evt.tags.filter(t => t[0] === 'e')) + .map(t => t[1]) + )) + + // Fetch the articles to get their coordinates + if (eventIds.length > 0) { + const articleEvents = await queryEvents(relayPool, { kinds: [KINDS.BlogPost], ids: eventIds }, { relayUrls: RELAYS }) + + // Build a mapping of event IDs to nadrs + const eventIdToNaddr = new Map() + for (const article of articleEvents) { + const dTag = article.tags.find(t => t[0] === 'd')?.[1] + if (dTag) { + try { + const naddr = nip19.naddrEncode({ + kind: KINDS.BlogPost, + pubkey: article.pubkey, + identifier: dTag + }) + eventIdToNaddr.set(article.id, naddr) + } catch (e) { + // Skip if naddr encoding fails + } + } + } + + // Add marked articles to our set using their nadrs + kind7WithMarkAsRead.forEach(evt => { + const eTag = evt.tags.find(t => t[0] === 'e')?.[1] + if (eTag && eventIdToNaddr.has(eTag)) { + this.markedAsReadIds.add(eventIdToNaddr.get(eTag)!) + } + }) + } + } } catch (err) { console.error('📊 [ReadingProgress] Failed to load:', err) } finally {