refactor: drop the local path a chunk's translation no longer takes

The translation editor was the only caller of `saveTranslationChunk`, and it
stopped calling it when it started proposing. What is left behind is dead: the
method on `MantraRepository`, its no-op for previews, its implementation in
`DatabaseMantraRepository`, and `MantraDao.saveTranslation` underneath them.

Deleting it rather than leaving it is the point. Two ways to create a
translation chunk, one of which bypasses the quorum, is one too many -- the next
screen wanting one would find it and take it, and the group would end up with a
translation in its name that nobody signed.

The rule it enforced does not go with it. Keeping one translation per source
chunk moved to `ChatMessage.applyInnerEvent`, where the row is now made, in the
commit before this one -- and covers more there than it ever did here, since the
group's other members were always able to leave a duplicate behind.

`MarmotInnerEventDao.deleteByPayloadEventId` loses its only production caller
here and stays. It is a DAO query rather than a private helper, the invariant
behind it is still true and still tested -- a submission's id is the envelope's,
so a superseded payload cannot be un-queued by its own id -- and `MantraDao`'s
remaining `addDialect` and `addArtifactVersion` are in the same position:
reachable now only from `MantraDaoJvmTest`, and a decision about the whole
submit-to-group path rather than about this screen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso Ngako
2026-09-06 13:14:17 +02:00
parent abbb84bb29
commit 90c6db7827
3 changed files with 0 additions and 95 deletions

View File

@@ -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,

View File

@@ -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<MantraTranslationArtifactVersion> =
database.mantraTranslationArtifactVersionDao().getTranslationsByArtifactId(artifactId)

View File

@@ -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<MantraTranslationArtifactVersion>
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<MantraTranslationArtifactVersion> = emptyList()
override suspend fun getTranslation(id: String): MantraTranslationArtifactVersion? = null