diff --git a/composeApp/src/commonMain/kotlin/press/mantra/compose/database/dao/MantraDao.kt b/composeApp/src/commonMain/kotlin/press/mantra/compose/database/dao/MantraDao.kt index 875bd8c4..d336122b 100644 --- a/composeApp/src/commonMain/kotlin/press/mantra/compose/database/dao/MantraDao.kt +++ b/composeApp/src/commonMain/kotlin/press/mantra/compose/database/dao/MantraDao.kt @@ -11,13 +11,11 @@ import press.mantra.compose.database.MantraDatabase import press.mantra.compose.database.model.ChatMessage import press.mantra.compose.database.model.MantraArtifactVersion import press.mantra.compose.database.model.MantraDialect -import press.mantra.compose.database.model.MantraTranslationChunk import press.mantra.compose.database.model.MarmotInnerEvent import press.mantra.compose.database.model.intermdiate.LocalChatRoom import press.mantra.compose.nostr.nip30303.ArtifactVersionEvent import press.mantra.compose.nostr.nip30303.DialectEvent import press.mantra.compose.nostr.nip30303.SubmissionEvent -import press.mantra.compose.nostr.nip30303.TranslationChunkEvent import press.mantra.compose.nostr.nip30303.tags.ArtifactIdTag import press.mantra.compose.repository.MantraRepository.Companion.DEFAULT_LICENSE import press.mantra.compose.repository.MantraRepository.Companion.DEFAULT_VISIBILITY @@ -192,60 +190,6 @@ abstract class MantraDao( return mantraArtifactVersion } - @Transaction - open suspend fun saveTranslation( - translationChapterId: String, - chunkId: String, - text: String, - chatRoomId: String, - userPublicKey: HexKey, - ): MantraTranslationChunk? { - // The translation chunk mirrors the source chunk's position. - val sourceChunk = database.mantraChunkDao().getChunkById(chunkId) ?: return null - - val translationChunkTemplate = TranslationChunkEvent.build( - translationChapterId = translationChapterId, - chunkId = chunkId, - index = sourceChunk.index, - text = text, - ) - val translationChunk = MantraTranslationChunk.fromTranslationChunkEventTemplate( - translationChunkEventTemplate = translationChunkTemplate, - chatRoomId = chatRoomId, - userPublicKey = userPublicKey, - ) ?: return null - - return try { - // Replace any existing translation chunk for this source chunk. Its id - // is derived from the (now changed) content, so it becomes a new row — - // drop the old one (and the submission carrying it) to keep one per - // source chunk. The submission is found by what it carries, since its - // own id is the envelope's rather than the chunk's. - database.mantraTranslationChunkDao() - .getTranslationChunksByTranslationChapterId(translationChapterId) - .filter { it.chunkId == chunkId && it.id != translationChunk.id } - .forEach { stale -> - database.mantraTranslationChunkDao().deleteById(stale.id) - database.marmotInnerEventDao().deleteById(stale.id) - database.marmotInnerEventDao().deleteByPayloadEventId(stale.id) - } - - database.mantraTranslationChunkDao().upsert(translationChunk) - - submitToGroup( - chatRoomId = chatRoomId, - submitterPublicKey = userPublicKey, - payload = rumorOf(translationChunkTemplate, userPublicKey), - text = "Translated chunk ${translationChunk.index}", // TODO: Use a portion of the translation and name the language - ) - - translationChunk - } catch (error: Throwable) { - logger.e("Failed to save translation for chunk $chunkId", error) - null - } - } - private suspend fun sendMarmotInnerEvent( chatRoomId: String, userPublicKey: HexKey, diff --git a/composeApp/src/commonMain/kotlin/press/mantra/compose/database/repository/DatabaseMantraRepository.kt b/composeApp/src/commonMain/kotlin/press/mantra/compose/database/repository/DatabaseMantraRepository.kt index 39967f2e..74552762 100644 --- a/composeApp/src/commonMain/kotlin/press/mantra/compose/database/repository/DatabaseMantraRepository.kt +++ b/composeApp/src/commonMain/kotlin/press/mantra/compose/database/repository/DatabaseMantraRepository.kt @@ -14,7 +14,6 @@ import press.mantra.compose.database.model.MantraTranslationChapter import press.mantra.compose.database.model.MantraTranslationChunk import press.mantra.compose.database.model.MarmotInnerEvent import press.mantra.compose.database.model.intermdiate.LocalChatRoom -import press.mantra.compose.nostr.nip30303.TranslationChunkEvent import press.mantra.compose.repository.MantraRepository class DatabaseMantraRepository( @@ -51,22 +50,6 @@ class DatabaseMantraRepository( override suspend fun getChunk(id: String): MantraChunk? = database.mantraChunkDao().getChunkById(id) - override suspend fun saveTranslationChunk( - translationChapterId: String, - chunkId: String, - text: String, - chatRoomId: String, - userPublicKey: HexKey, - ): MantraTranslationChunk? { - return database.mantraDao().saveTranslation( - translationChapterId = translationChapterId, - chunkId = chunkId, - text = text, - chatRoomId = chatRoomId, - userPublicKey = userPublicKey - ) - } - override suspend fun getTranslationsForArtifact(artifactId: String): List = database.mantraTranslationArtifactVersionDao().getTranslationsByArtifactId(artifactId) diff --git a/composeApp/src/commonMain/kotlin/press/mantra/compose/repository/MantraRepository.kt b/composeApp/src/commonMain/kotlin/press/mantra/compose/repository/MantraRepository.kt index 1bf79271..677998d6 100644 --- a/composeApp/src/commonMain/kotlin/press/mantra/compose/repository/MantraRepository.kt +++ b/composeApp/src/commonMain/kotlin/press/mantra/compose/repository/MantraRepository.kt @@ -35,20 +35,6 @@ interface MantraRepository { suspend fun getChunk(id: String): MantraChunk? - /** - * Create or replace the translation of a source chunk within a translation - * chapter. Any existing translation chunk for the same (translationChapterId, - * chunkId) is replaced. Returns the saved chunk, or null if the source chunk - * can't be found. - */ - suspend fun saveTranslationChunk( - translationChapterId: String, - chunkId: String, - text: String, - chatRoomId: String, - userPublicKey: HexKey, - ): MantraTranslationChunk? - suspend fun getTranslationsForArtifact(artifactId: String): List suspend fun getTranslation(id: String): MantraTranslationArtifactVersion? @@ -100,14 +86,6 @@ interface MantraRepository { override suspend fun getChunk(id: String): MantraChunk? = null - override suspend fun saveTranslationChunk( - translationChapterId: String, - chunkId: String, - text: String, - chatRoomId: String, - userPublicKey: HexKey, - ): MantraTranslationChunk? = null - override suspend fun getTranslationsForArtifact(artifactId: String): List = emptyList() override suspend fun getTranslation(id: String): MantraTranslationArtifactVersion? = null