mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 22:36:49 +01:00
refactoring of cache methods in GiftWraps
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user