diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/CacheClientConnector.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/CacheClientConnector.kt index 079fcd01d..a91a08a84 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/CacheClientConnector.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/CacheClientConnector.kt @@ -21,11 +21,14 @@ package com.vitorpamplona.amethyst.service.relayClient import com.vitorpamplona.amethyst.model.LocalCache +import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.quartz.nip01Core.core.HexKey import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.EventCollector import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.RelayInsertConfirmationCollector import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl +import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealedRumorEvent +import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent class CacheClientConnector( val client: INostrClient, @@ -50,5 +53,39 @@ class CacheClientConnector( private fun markAsSeen( eventId: HexKey, info: NormalizedRelayUrl, - ) = LocalCache.getNoteIfExists(eventId)?.addRelay(info) + ) { + val note = LocalCache.getNoteIfExists(eventId) + if (note != null) { + note.addRelay(info) + markAsSeenInner(note, info) + } + } + + private fun markAsSeenInner( + note: Note, + info: NormalizedRelayUrl, + ) { + val noteEvent = note.event + if (noteEvent is GiftWrapEvent) { + val innerEvent = noteEvent.innerEventId + if (innerEvent != null) { + val innerNote = cache.getNoteIfExists(innerEvent) + if (innerNote != null) { + innerNote.addRelay(info) + markAsSeenInner(innerNote, info) + } + } + } + + if (noteEvent is SealedRumorEvent) { + val innerEvent = noteEvent.innerEventId + if (innerEvent != null) { + val innerNote = cache.getNoteIfExists(innerEvent) + if (innerNote != null) { + innerNote.addRelay(info) + markAsSeenInner(innerNote, info) + } + } + } + } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index 6958fd4a3..66283da30 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -1309,9 +1309,7 @@ class AccountViewModel( if (existingNoteEvent != null) { unwrapIfNeeded(existingNoteEvent) } else { - val newEvent = event.unwrapOrNull(account.signer) - - if (newEvent == null) return null + val newEvent = event.unwrapOrNull(account.signer) ?: return null // clear the encrypted payload to save memory LocalCache.getOrCreateNote(event.id).event = event.copyNoContent()