adds recursive markAsSeen to mark the inner chat element of NIP-17 DMs for each relay that that message was received.
This commit is contained in:
+38
-1
@@ -21,11 +21,14 @@
|
|||||||
package com.vitorpamplona.amethyst.service.relayClient
|
package com.vitorpamplona.amethyst.service.relayClient
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.client.INostrClient
|
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.EventCollector
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.RelayInsertConfirmationCollector
|
import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.RelayInsertConfirmationCollector
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||||
|
import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealedRumorEvent
|
||||||
|
import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
|
||||||
|
|
||||||
class CacheClientConnector(
|
class CacheClientConnector(
|
||||||
val client: INostrClient,
|
val client: INostrClient,
|
||||||
@@ -50,5 +53,39 @@ class CacheClientConnector(
|
|||||||
private fun markAsSeen(
|
private fun markAsSeen(
|
||||||
eventId: HexKey,
|
eventId: HexKey,
|
||||||
info: NormalizedRelayUrl,
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -1309,9 +1309,7 @@ class AccountViewModel(
|
|||||||
if (existingNoteEvent != null) {
|
if (existingNoteEvent != null) {
|
||||||
unwrapIfNeeded(existingNoteEvent)
|
unwrapIfNeeded(existingNoteEvent)
|
||||||
} else {
|
} else {
|
||||||
val newEvent = event.unwrapOrNull(account.signer)
|
val newEvent = event.unwrapOrNull(account.signer) ?: return null
|
||||||
|
|
||||||
if (newEvent == null) return null
|
|
||||||
|
|
||||||
// clear the encrypted payload to save memory
|
// clear the encrypted payload to save memory
|
||||||
LocalCache.getOrCreateNote(event.id).event = event.copyNoContent()
|
LocalCache.getOrCreateNote(event.id).event = event.copyNoContent()
|
||||||
|
|||||||
Reference in New Issue
Block a user