Add helper functions to create mantra nostr event

This commit is contained in:
Kgothatso Ngako
2026-07-15 23:34:37 +02:00
parent d2370a512a
commit a84628acbb
26 changed files with 318 additions and 43 deletions

View File

@@ -3,6 +3,10 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.ArtifactEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30300
@@ -19,4 +23,17 @@ data class MantraArtifact(
val license: String,
// val artifactApprovalId: String,
)
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
fun toArtifactEvent(): ArtifactEvent {
return ArtifactEvent(
id = "",
pubKey = publicKey,
createdAt = createdAt.epochSeconds,
tags = emptyArray(),
content = "",
sig = ""
)
}
}

View File

@@ -3,6 +3,10 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.ArtifactVersionEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30301
@@ -18,4 +22,18 @@ data class MantraArtifactVersion(
* Version Tag...
*/
val versionLabel: String,
)
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
fun toArtifactVersionEvent(): ArtifactVersionEvent {
return ArtifactVersionEvent(
id = "",
pubKey = publicKey,
createdAt = createdAt.epochSeconds,
tags = emptyArray(),
content = "",
sig = ""
)
}
}

View File

@@ -3,6 +3,10 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.ChapterEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30302
@@ -19,4 +23,18 @@ data class MantraChapter(
val wordCount: Int,
val characterCount: Int,
)
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
fun toChapterEvent(): ChapterEvent {
return ChapterEvent(
id = "",
pubKey = publicKey,
createdAt = createdAt.epochSeconds,
tags = emptyArray(),
content = "",
sig = ""
)
}
}

View File

@@ -3,6 +3,10 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.ChunkEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30303
@@ -16,5 +20,20 @@ data class MantraChunk(
val text: String,
val index: Int,
val wordCount: Int,
val characterCount: Int
)
val characterCount: Int,
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
fun toChunkEvent(): ChunkEvent {
return ChunkEvent(
id = "",
pubKey = publicKey,
createdAt = createdAt.epochSeconds,
tags = emptyArray(),
content = "",
sig = ""
)
}
}

View File

@@ -3,6 +3,10 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.DialectEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30304
@@ -10,5 +14,25 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
@Entity
data class MantraDialect(
@PrimaryKey
val id: HexKey
)
val id: HexKey,
val publicKey: HexKey,
val name: String,
val country: String,
val language: String,
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
fun toDialectEvent(): DialectEvent {
return DialectEvent(
id = "",
pubKey = publicKey,
createdAt = createdAt.epochSeconds,
tags = emptyArray(),
content = "",
sig = ""
)
}
}

View File

@@ -3,6 +3,10 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.TranslationEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30305
@@ -15,4 +19,19 @@ data class MantraTranslation(
val translationChunkId: HexKey,
val translationArtifactVersionId: HexKey,
val text: String,
)
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
fun toTranslationEvent(): TranslationEvent {
return TranslationEvent(
id = "",
pubKey = publicKey,
createdAt = createdAt.epochSeconds,
tags = emptyArray(),
content = "",
sig = ""
)
}
}

View File

@@ -3,6 +3,10 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.TranslationArtifactVersionEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30306
@@ -11,8 +15,25 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
data class MantraTranslationArtifactVersion(
@PrimaryKey
val id: HexKey,
val publicKey: HexKey,
val artifactVersionId: HexKey,
val dialectId: HexKey,
val name: String,
val visibility: String,
)
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
fun toTranslationArtifactVersionEvent(): TranslationArtifactVersionEvent {
return TranslationArtifactVersionEvent(
id = "",
pubKey = publicKey,
createdAt = createdAt.epochSeconds,
tags = emptyArray(),
content = "",
sig = ""
)
}
}

View File

@@ -3,6 +3,11 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.utils.TimeUtils
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.TranslationArtifactVersionEditorListEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30307
@@ -11,6 +16,26 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
data class MantraTranslationArtifactVersionEditor(
@PrimaryKey
val id: HexKey,
val publicKey: HexKey,
val translationArtifactVersionId: HexKey,
val editorPublicKey: HexKey,
)
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
companion object {
fun toTranslationChapterProofReaderListEvent(mantraTranslationChapterProofReaders: List<MantraTranslationChapterProofReader>): TranslationArtifactVersionEditorListEvent {
// TODO: create TranslationChapterProofReaderListEvent from mantraTranslationChapterProofReaders
return TranslationArtifactVersionEditorListEvent(
id = "",
pubKey = "",
createdAt = TimeUtils.now(),
tags = emptyArray(),
content = "",
sig = ""
)
}
}
}

View File

@@ -2,6 +2,10 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.TranslationChapterEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30308
@@ -9,7 +13,23 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
@Entity
data class MantraTranslationChapter(
val id: HexKey,
val publicKey: HexKey,
val chapterId: HexKey,
val translationArtifactVersionId: HexKey,
val index: Int
)
val index: Int,
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
fun toTranslationChapterEvent(): TranslationChapterEvent {
return TranslationChapterEvent(
id = "",
pubKey = publicKey,
createdAt = createdAt.epochSeconds,
tags = emptyArray(),
content = "",
sig = ""
)
}
}

View File

@@ -3,6 +3,11 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.utils.TimeUtils
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.TranslationChapterProofReaderListEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30309
@@ -11,6 +16,26 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
data class MantraTranslationChapterProofReader(
@PrimaryKey
val id: HexKey,
val publicKey: HexKey,
val translationChapterId: HexKey,
val proofReaderPublicKey: HexKey,
)
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
companion object {
fun toTranslationChapterProofReaderListEvent(mantraTranslationChapterProofReaders: List<MantraTranslationChapterProofReader>): TranslationChapterProofReaderListEvent {
// TODO: create TranslationChapterProofReaderListEvent from mantraTranslationChapterProofReaders
return TranslationChapterProofReaderListEvent(
id = "",
pubKey = "",
createdAt = TimeUtils.now(),
tags = emptyArray(),
content = "",
sig = ""
)
}
}
}

View File

@@ -3,6 +3,11 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.utils.TimeUtils
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.TranslationChapterTranslatorListEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30310
@@ -11,6 +16,26 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
data class MantraTranslationChapterTranslator(
@PrimaryKey
val id: HexKey,
val publicKey: HexKey,
val translationChapterId: HexKey,
val translatorPublicKey: HexKey,
)
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
companion object {
fun toTranslationChapterTranslatorListEvent(mantraTranslationChapterTranslators: List<MantraTranslationChapterTranslator>): TranslationChapterTranslatorListEvent {
// TODO: create TranslationChapterProofReaderListEvent from mantraTranslationChapterProofReaders
return TranslationChapterTranslatorListEvent(
id = "",
pubKey = "",
createdAt = TimeUtils.now(),
tags = emptyArray(),
content = "",
sig = ""
)
}
}
}

View File

@@ -3,6 +3,10 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.TranslationChunkEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30311
@@ -11,8 +15,24 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
data class MantraTranslationChunk(
@PrimaryKey
val id: HexKey,
val publicKey: HexKey,
val text: String,
val index: Int,
val chunkId: HexKey,
val translationChapterId: HexKey,
)
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
fun toTranslationChunkEvent(): TranslationChunkEvent {
return TranslationChunkEvent(
id = "",
pubKey = publicKey,
createdAt = createdAt.epochSeconds,
tags = emptyArray(),
content = "",
sig = ""
)
}
}

View File

@@ -3,6 +3,11 @@ package press.mantra.compose.database.model
import androidx.room3.Entity
import androidx.room3.PrimaryKey
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.utils.TimeUtils
import press.mantra.compose.database.model.traits.TimestampedEntity
import press.mantra.compose.nostr.nip30303.TranslationTranslatorListEvent
import kotlin.time.Clock
import kotlin.time.Instant
/**
* 30312
@@ -11,7 +16,26 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
data class MantraTranslationTranslator(
@PrimaryKey
val id: HexKey,
val publicKey: HexKey,
val translationId: HexKey,
val translatorPublicKey: HexKey,
val content: String,
)
override val createdAt: Instant = Clock.System.now(),
override val updatedAt: Instant = createdAt
): TimestampedEntity {
companion object {
fun toTranslationChapterProofReaderListEvent(mantraTranslationChapterProofReaders: List<MantraTranslationChapterProofReader>): TranslationTranslatorListEvent {
// TODO: create TranslationChapterProofReaderListEvent from mantraTranslationChapterProofReaders
return TranslationTranslatorListEvent(
id = "",
pubKey = "",
createdAt = TimeUtils.now(),
tags = emptyArray(),
content = "",
sig = ""
)
}
}
}

View File

@@ -26,10 +26,10 @@ class ArtifactEvent(
const val ALT_DESCRIPTION = "Artifact"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class ArtifactVersionEvent(
const val ALT_DESCRIPTION = "ArtifactVersion"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class ChapterEvent(
const val ALT_DESCRIPTION = "Chapter"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class ChunkEvent(
const val ALT_DESCRIPTION = "Chunk"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class DialectEvent(
const val ALT_DESCRIPTION = "Dialect"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class TranslationArtifactVersionEditorListEvent(
const val ALT_DESCRIPTION = "TranslationArtifactVersionEditorList"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class TranslationArtifactVersionEvent(
const val ALT_DESCRIPTION = "TranslationArtifactVersion"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class TranslationChapterEvent(
const val ALT_DESCRIPTION = "TranslationChapter"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class TranslationChapterProofReaderListEvent(
const val ALT_DESCRIPTION = "TranslationChapterProofReaderList"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class TranslationChapterTranslatorListEvent(
const val ALT_DESCRIPTION = "TranslationChapterTranslatorList"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class TranslationChunkEvent(
const val ALT_DESCRIPTION = "TranslationChunk"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class TranslationEvent(
const val ALT_DESCRIPTION = "Translation"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}

View File

@@ -26,10 +26,10 @@ class TranslationTranslatorListEvent(
const val ALT_DESCRIPTION = "TranslationTranslatorList"
fun build(
description: String,
content: String,
createdAt: Long = TimeUtils.now(),
initializer: TagArrayBuilder<ArtifactEvent>.() -> Unit = {},
) = eventTemplate(KIND, description, createdAt) {
) = eventTemplate(KIND, content, createdAt) {
alt(ALT_DESCRIPTION)
initializer()
}