Adds 90 day expiration to all drafts.

This commit is contained in:
Vitor Pamplona
2025-08-19 12:40:53 -04:00
parent 5685f227f9
commit f56d927f72
5 changed files with 11 additions and 56 deletions

View File

@@ -159,7 +159,6 @@ import com.vitorpamplona.quartz.nip19Bech32.entities.NPub
import com.vitorpamplona.quartz.nip19Bech32.entities.NRelay
import com.vitorpamplona.quartz.nip19Bech32.entities.NSec
import com.vitorpamplona.quartz.nip36SensitiveContent.contentWarning
import com.vitorpamplona.quartz.nip37Drafts.DraftBuilder
import com.vitorpamplona.quartz.nip37Drafts.DraftEventCache
import com.vitorpamplona.quartz.nip37Drafts.DraftWrapEvent
import com.vitorpamplona.quartz.nip42RelayAuth.RelayAuthEvent
@@ -1151,7 +1150,7 @@ class Account(
val extraRelays = cache.getAddressableNoteIfExists(DraftWrapEvent.createAddressTag(signer.pubKey, draftTag))?.relays ?: emptyList()
val rumor = RumorAssembler.assembleRumor(signer.pubKey, template)
val draftEvent = DraftBuilder.encryptAndSign(draftTag, rumor, signer)
val draftEvent = DraftWrapEvent.create(draftTag, rumor, signer)
draftsDecryptionCache.preload(draftEvent, rumor)
cache.justConsumeMyOwnEvent(draftEvent)

View File

@@ -1,54 +0,0 @@
/**
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.quartz.nip37Drafts
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
import com.vitorpamplona.quartz.nip01Core.signers.eventTemplate
import com.vitorpamplona.quartz.nip01Core.tags.dTags.dTag
import com.vitorpamplona.quartz.nip01Core.tags.kinds.kind
import com.vitorpamplona.quartz.nip31Alts.alt
import com.vitorpamplona.quartz.utils.TimeUtils
class DraftBuilder {
companion object {
suspend fun <T : Event> encryptAndSign(
dTag: String,
draft: T,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
): DraftWrapEvent {
val encryptedContent = signer.nip44Encrypt(draft.toJson(), signer.pubKey)
val template =
eventTemplate<DraftWrapEvent>(DraftWrapEvent.KIND, encryptedContent, createdAt) {
alt(DraftWrapEvent.ALT_DESCRIPTION)
dTag(dTag)
kind(draft.kind)
if (draft is ExposeInDraft) {
addAll(draft.exposeInDraft())
}
}
return signer.sign(template)
}
}
}

View File

@@ -34,6 +34,7 @@ import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
import com.vitorpamplona.quartz.nip01Core.tags.dTags.dTag
import com.vitorpamplona.quartz.nip01Core.tags.kinds.kind
import com.vitorpamplona.quartz.nip31Alts.alt
import com.vitorpamplona.quartz.nip40Expiration.expiration
import com.vitorpamplona.quartz.utils.TimeUtils
@Immutable
@@ -91,6 +92,11 @@ class DraftWrapEvent(
alt(ALT_DESCRIPTION)
dTag(dTag)
kind(draft.kind)
expiration(TimeUtils.ninetyDaysFromNow())
if (draft is ExposeInDraft) {
addAll(draft.exposeInDraft())
}
initializer()
}
@@ -105,6 +111,7 @@ class DraftWrapEvent(
createdAt = createdAt,
) {
alt(ALT_DESCRIPTION)
expiration(TimeUtils.oneMinuteFromNow())
dTag(dTag)
initializer()
}

View File

@@ -28,6 +28,7 @@ object TimeUtils {
const val ONE_HOUR = 60 * ONE_MINUTE
const val EIGHT_HOURS = 8 * ONE_HOUR
const val ONE_DAY = 24 * ONE_HOUR
const val NINETY_DAYS = 90 * ONE_DAY
const val ONE_WEEK = 7 * ONE_DAY
const val ONE_MONTH = 30 * ONE_DAY
const val ONE_YEAR = 365 * ONE_DAY
@@ -61,4 +62,6 @@ object TimeUtils {
fun oneMonthAgo() = now() - ONE_MONTH
fun randomWithTwoDays() = now() - RandomInstance.int(twoDays())
fun ninetyDaysFromNow() = now() + NINETY_DAYS
}