Fixes giftwrap date mismatch

This commit is contained in:
Vitor Pamplona
2024-06-17 16:20:40 -04:00
parent aad95595eb
commit 0fa6dce42c
3 changed files with 6 additions and 12 deletions
@@ -56,9 +56,7 @@ class GiftWrapEvent(
override fun isContentEncoded() = true override fun isContentEncoded() = true
fun preCachedGift(signer: NostrSigner): Event? { fun preCachedGift(signer: NostrSigner): Event? = cachedInnerEvent[signer.pubKey]
return cachedInnerEvent[signer.pubKey]
}
fun addToCache( fun addToCache(
pubKey: HexKey, pubKey: HexKey,
@@ -114,7 +112,7 @@ class GiftWrapEvent(
fun create( fun create(
event: Event, event: Event,
recipientPubKey: HexKey, recipientPubKey: HexKey,
createdAt: Long = TimeUtils.randomWithinAWeek(), createdAt: Long = TimeUtils.randomWithTwoDays(),
onReady: (GiftWrapEvent) -> Unit, onReady: (GiftWrapEvent) -> Unit,
) { ) {
val signer = NostrSignerInternal(KeyPair()) // GiftWrap is always a random key val signer = NostrSignerInternal(KeyPair()) // GiftWrap is always a random key
@@ -58,9 +58,7 @@ class SealedGossipEvent(
override fun isContentEncoded() = true override fun isContentEncoded() = true
fun preCachedGossip(signer: NostrSigner): Event? { fun preCachedGossip(signer: NostrSigner): Event? = cachedInnerEvent[signer.pubKey]
return cachedInnerEvent[signer.pubKey]
}
fun addToCache( fun addToCache(
pubKey: HexKey, pubKey: HexKey,
@@ -133,7 +131,7 @@ class SealedGossipEvent(
gossip: Gossip, gossip: Gossip,
encryptTo: HexKey, encryptTo: HexKey,
signer: NostrSigner, signer: NostrSigner,
createdAt: Long = TimeUtils.randomWithinAWeek(), createdAt: Long = TimeUtils.randomWithTwoDays(),
onReady: (SealedGossipEvent) -> Unit, onReady: (SealedGossipEvent) -> Unit,
) { ) {
val msg = Gossip.toJson(gossip) val msg = Gossip.toJson(gossip)
@@ -172,8 +170,6 @@ class Gossip(
fun toJson(event: Gossip): String = Event.mapper.writeValueAsString(event) fun toJson(event: Gossip): String = Event.mapper.writeValueAsString(event)
fun create(event: Event): Gossip { fun create(event: Event): Gossip = Gossip(event.id, event.pubKey, event.createdAt, event.kind, event.tags, event.content)
return Gossip(event.id, event.pubKey, event.createdAt, event.kind, event.tags, event.content)
}
} }
} }
@@ -55,5 +55,5 @@ object TimeUtils {
fun oneWeekAgo() = now() - ONE_WEEK fun oneWeekAgo() = now() - ONE_WEEK
fun randomWithinAWeek() = System.currentTimeMillis() / 1000 - CryptoUtils.randomInt(ONE_WEEK) fun randomWithTwoDays() = System.currentTimeMillis() / 1000 - CryptoUtils.randomInt(twoDays())
} }