refactoring of cache methods in GiftWraps

This commit is contained in:
Vitor Pamplona
2024-04-04 14:59:49 -04:00
parent e1c134830e
commit 7fd37367fc
2 changed files with 18 additions and 4 deletions

View File

@@ -44,6 +44,13 @@ class GiftWrapEvent(
return cachedInnerEvent[signer.pubKey] return cachedInnerEvent[signer.pubKey]
} }
fun addToCache(
pubKey: HexKey,
gift: Event,
) {
cachedInnerEvent = cachedInnerEvent + Pair(pubKey, gift)
}
fun cachedGift( fun cachedGift(
signer: NostrSigner, signer: NostrSigner,
onReady: (Event) -> Unit, onReady: (Event) -> Unit,
@@ -56,7 +63,7 @@ class GiftWrapEvent(
if (gift is WrappedEvent) { if (gift is WrappedEvent) {
gift.host = this gift.host = this
} }
cachedInnerEvent = cachedInnerEvent + Pair(signer.pubKey, gift) addToCache(signer.pubKey, gift)
onReady(gift) onReady(gift)
} }
@@ -98,8 +105,8 @@ class GiftWrapEvent(
val serializedContent = toJson(event) val serializedContent = toJson(event)
val tags = arrayOf(arrayOf("p", recipientPubKey)) val tags = arrayOf(arrayOf("p", recipientPubKey))
signer.nip44Encrypt(serializedContent, recipientPubKey) { signer.nip44Encrypt(serializedContent, recipientPubKey) { content ->
signer.sign(createdAt, KIND, tags, it, onReady) signer.sign(createdAt, KIND, tags, content, onReady)
} }
} }
} }

View File

@@ -45,6 +45,13 @@ class SealedGossipEvent(
return cachedInnerEvent[signer.pubKey] return cachedInnerEvent[signer.pubKey]
} }
fun addToCache(
pubKey: HexKey,
gift: Event,
) {
cachedInnerEvent = cachedInnerEvent + Pair(pubKey, gift)
}
fun cachedGossip( fun cachedGossip(
signer: NostrSigner, signer: NostrSigner,
onReady: (Event) -> Unit, onReady: (Event) -> Unit,
@@ -59,8 +66,8 @@ class SealedGossipEvent(
if (event is WrappedEvent) { if (event is WrappedEvent) {
event.host = host ?: this event.host = host ?: this
} }
addToCache(signer.pubKey, event)
cachedInnerEvent = cachedInnerEvent + Pair(signer.pubKey, event)
onReady(event) onReady(event)
} }
} }