app(write): on UploadFailed, queue to outbox via shared use case; persist image locally and schedule upload worker

This commit is contained in:
2025-09-14 23:23:04 +02:00
parent c65f230665
commit 9deca99711
2 changed files with 164 additions and 42 deletions

View File

@@ -0,0 +1,33 @@
package app.klottr.create
/** Resultat från outbox-köning (offline). */
sealed class QueueOutboxOutcome {
data object Queued : QueueOutboxOutcome() // Lyckades lägga i utkorgen
data object ImagePersistFailed : QueueOutboxOutcome() // Bilden kunde inte sparas lokalt
}
/**
* Orkestrerar offline-flödet: ev. spara bild lokalt → lägg DOC i outbox → schemalägg uppladdning.
* Plattformsspecifika detaljer injiceras via lambdas (DI).
*/
suspend fun queueNoteDocOutbox(
lat: Double,
lon: Double,
title: String,
body: String,
createdAt: Long,
radiusM: Int,
hasImage: Boolean,
persistImageIfAny: suspend () -> Pair<String, String>?, // returnerar (imagePath, imageMime) eller null vid fel
addOutboxDoc: (lat: Double, lon: Double, title: String, body: String, createdAt: Long, radiusM: Int, imagePath: String?, imageMime: String?) -> Unit,
scheduleUpload: () -> Unit
): QueueOutboxOutcome {
val (imagePath, imageMime) = if (hasImage) {
val res = persistImageIfAny() ?: return QueueOutboxOutcome.ImagePersistFailed
res
} else null to null
addOutboxDoc(lat, lon, title, body, createdAt, radiusM, imagePath, imageMime)
scheduleUpload()
return QueueOutboxOutcome.Queued
}