refactoring of cache methods in GiftWraps

pull/823/head
Vitor Pamplona 2024-04-04 14:59:49 -04:00
rodzic e1c134830e
commit 7fd37367fc
2 zmienionych plików z 18 dodań i 4 usunięć

Wyświetl plik

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

Wyświetl plik

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