diff --git a/app-common/src/main/java/eu/darken/octi/common/debug/Bugs.kt b/app-common/src/main/java/eu/darken/octi/common/debug/Bugs.kt
index ac04d726..3d77667f 100644
--- a/app-common/src/main/java/eu/darken/octi/common/debug/Bugs.kt
+++ b/app-common/src/main/java/eu/darken/octi/common/debug/Bugs.kt
@@ -1,11 +1,13 @@
package eu.darken.octi.common.debug
+import eu.darken.octi.common.BuildConfigWrap
import eu.darken.octi.common.debug.logging.Logging.Priority.VERBOSE
import eu.darken.octi.common.debug.logging.Logging.Priority.WARN
import eu.darken.octi.common.debug.logging.log
import eu.darken.octi.common.debug.logging.logTag
object Bugs {
+ var isDebug: Boolean = BuildConfigWrap.DEBUG
var reporter: AutomaticBugReporter? = null
fun report(exception: Exception) {
log(TAG, VERBOSE) { "Reporting $exception" }
diff --git a/app/src/main/java/eu/darken/octi/syncs/gdrive/ui/actions/GDriveActionsFragment.kt b/app/src/main/java/eu/darken/octi/syncs/gdrive/ui/actions/GDriveActionsFragment.kt
index c7c13a01..81856946 100644
--- a/app/src/main/java/eu/darken/octi/syncs/gdrive/ui/actions/GDriveActionsFragment.kt
+++ b/app/src/main/java/eu/darken/octi/syncs/gdrive/ui/actions/GDriveActionsFragment.kt
@@ -33,11 +33,11 @@ class GDriveActionsFragment : BottomSheetDialogFragment2() {
setNegativeButton(R.string.general_cancel_action) { _, _ -> }
}.show()
}
- ui.wipeAction.setOnClickListener {
+ ui.resetAction.setOnClickListener {
MaterialAlertDialogBuilder(requireContext()).apply {
- setMessage(R.string.sync_gdrive_wipe_confirmation_desc)
- setPositiveButton(R.string.general_wipe_action) { _, _ ->
- vm.wipe()
+ setMessage(R.string.sync_gdrive_reset_confirmation_desc)
+ setPositiveButton(R.string.general_reset_action) { _, _ ->
+ vm.reset()
}
setNegativeButton(R.string.general_cancel_action) { _, _ -> }
}.show()
diff --git a/app/src/main/java/eu/darken/octi/syncs/gdrive/ui/actions/GDriveActionsVM.kt b/app/src/main/java/eu/darken/octi/syncs/gdrive/ui/actions/GDriveActionsVM.kt
index 4b8dadb1..1a7d5849 100644
--- a/app/src/main/java/eu/darken/octi/syncs/gdrive/ui/actions/GDriveActionsVM.kt
+++ b/app/src/main/java/eu/darken/octi/syncs/gdrive/ui/actions/GDriveActionsVM.kt
@@ -42,9 +42,9 @@ class GDriveActionsVM @Inject constructor(
popNavStack()
}
- fun wipe() = launch {
- log(TAG) { "wipe()" }
- syncManager.wipe(navArgs.identifier)
+ fun reset() = launch {
+ log(TAG) { "reset()" }
+ syncManager.resetData(navArgs.identifier)
popNavStack()
}
diff --git a/app/src/main/java/eu/darken/octi/syncs/jserver/ui/actions/JServerActionsFragment.kt b/app/src/main/java/eu/darken/octi/syncs/jserver/ui/actions/JServerActionsFragment.kt
index 8d18674b..93bb5274 100644
--- a/app/src/main/java/eu/darken/octi/syncs/jserver/ui/actions/JServerActionsFragment.kt
+++ b/app/src/main/java/eu/darken/octi/syncs/jserver/ui/actions/JServerActionsFragment.kt
@@ -45,11 +45,11 @@ class JServerActionsFragment : BottomSheetDialogFragment2() {
}
}.show()
}
- ui.wipeAction.setOnClickListener {
+ ui.resetAction.setOnClickListener {
MaterialAlertDialogBuilder(requireContext()).apply {
- setMessage(R.string.sync_jserver_wipe_confirmation_desc)
- setPositiveButton(R.string.general_wipe_action) { _, _ ->
- vm.wipe()
+ setMessage(R.string.sync_jserver_reset_confirmation_desc)
+ setPositiveButton(R.string.general_reset_action) { _, _ ->
+ vm.reset()
}
setNegativeButton(R.string.general_cancel_action) { _, _ ->
diff --git a/app/src/main/java/eu/darken/octi/syncs/jserver/ui/actions/JServerActionsVM.kt b/app/src/main/java/eu/darken/octi/syncs/jserver/ui/actions/JServerActionsVM.kt
index 270f1db6..dbc70560 100644
--- a/app/src/main/java/eu/darken/octi/syncs/jserver/ui/actions/JServerActionsVM.kt
+++ b/app/src/main/java/eu/darken/octi/syncs/jserver/ui/actions/JServerActionsVM.kt
@@ -55,9 +55,9 @@ class JServerActionsVM @Inject constructor(
navEvents.postValue(null)
}
- fun wipe() = launch {
- log(TAG) { "wipe()" }
- syncManager.wipe(navArgs.identifier)
+ fun reset() = launch {
+ log(TAG) { "reset()" }
+ syncManager.resetData(navArgs.identifier)
navEvents.postValue(null)
}
diff --git a/app/src/main/java/eu/darken/octi/syncs/kserver/ui/actions/KServerActionsFragment.kt b/app/src/main/java/eu/darken/octi/syncs/kserver/ui/actions/KServerActionsFragment.kt
index efd36d70..f61c5f79 100644
--- a/app/src/main/java/eu/darken/octi/syncs/kserver/ui/actions/KServerActionsFragment.kt
+++ b/app/src/main/java/eu/darken/octi/syncs/kserver/ui/actions/KServerActionsFragment.kt
@@ -36,11 +36,11 @@ class KServerActionsFragment : BottomSheetDialogFragment2() {
}
}.show()
}
- ui.wipeAction.setOnClickListener {
+ ui.resetAction.setOnClickListener {
MaterialAlertDialogBuilder(requireContext()).apply {
- setMessage(R.string.sync_kserver_wipe_confirmation_desc)
- setPositiveButton(R.string.general_wipe_action) { _, _ ->
- vm.wipe()
+ setMessage(R.string.sync_kserver_reset_confirmation_desc)
+ setPositiveButton(R.string.general_reset_action) { _, _ ->
+ vm.reset()
}
setNegativeButton(R.string.general_cancel_action) { _, _ ->
diff --git a/app/src/main/java/eu/darken/octi/syncs/kserver/ui/actions/KServerActionsVM.kt b/app/src/main/java/eu/darken/octi/syncs/kserver/ui/actions/KServerActionsVM.kt
index 0028f7f9..e15f826c 100644
--- a/app/src/main/java/eu/darken/octi/syncs/kserver/ui/actions/KServerActionsVM.kt
+++ b/app/src/main/java/eu/darken/octi/syncs/kserver/ui/actions/KServerActionsVM.kt
@@ -54,9 +54,9 @@ class KServerActionsVM @Inject constructor(
navEvents.postValue(null)
}
- fun wipe() = launch {
- log(TAG) { "wipe()" }
- syncManager.wipe(navArgs.identifier)
+ fun reset() = launch {
+ log(TAG) { "reset()" }
+ syncManager.resetData(navArgs.identifier)
navEvents.postValue(null)
}
diff --git a/app/src/main/res/layout/sync_actions_gdrive_fragment.xml b/app/src/main/res/layout/sync_actions_gdrive_fragment.xml
index c8a59129..6b21d38a 100644
--- a/app/src/main/res/layout/sync_actions_gdrive_fragment.xml
+++ b/app/src/main/res/layout/sync_actions_gdrive_fragment.xml
@@ -50,12 +50,11 @@
app:iconGravity="textStart" />
diff --git a/app/src/main/res/layout/sync_actions_jserver_fragment.xml b/app/src/main/res/layout/sync_actions_jserver_fragment.xml
index 73751e5c..ffaa13f6 100644
--- a/app/src/main/res/layout/sync_actions_jserver_fragment.xml
+++ b/app/src/main/res/layout/sync_actions_jserver_fragment.xml
@@ -70,12 +70,11 @@
app:iconGravity="textStart" />
diff --git a/app/src/main/res/layout/sync_actions_kserver_fragment.xml b/app/src/main/res/layout/sync_actions_kserver_fragment.xml
index 053167de..26569e12 100644
--- a/app/src/main/res/layout/sync_actions_kserver_fragment.xml
+++ b/app/src/main/res/layout/sync_actions_kserver_fragment.xml
@@ -59,12 +59,11 @@
app:iconGravity="textStart" />
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index 77d6671b..8452c911 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -6,7 +6,6 @@
Listo
Copiar
Eliminar
- Limpiar
Cancelar
Gracias
Entendido
@@ -109,7 +108,7 @@
Los datos se colocan en Google Drive. Esta variante específicada utiliza el alcance "datos de la aplicación". Solo se otorga acceso a una nueva carpeta solo para esta aplicación. La carpeta no está visible en su disco. Es similar a cómo funcionan las copias de seguridad de WhatsApp.
Agregar un nuevo Google Drive
Haz clic en el botón de inicio de sesión a continuación para configurar el acceso a Google Drive.
- Restablezce todos los datos de Octi almacenados en Google Drive. Tu dispositivo permanece conectado a Google Drive.
+ Restablezce todos los datos de Octi almacenados en Google Drive. Tu dispositivo permanece conectado a Google Drive.
Cerrar la sesión en Google Drive y eliminar los datos de este dispositivo.
Este dispositivo no está registrado en ninguna cuenta de Google.
@@ -122,7 +121,7 @@
JServer es un servidor de sincronización de código abierto para Octi de Jakob Möller.
Autor
Código fuente
- Restablece esta cuenta y elimine todos los datos almacenados. Tu dispositivo permanecerá vinculado a la cuenta.
+ Restablece esta cuenta y elimine todos los datos almacenados. Tu dispositivo permanecerá vinculado a la cuenta.
Esto eliminará este dispositivo de tu cuenta. Si este es el último dispositivo vinculado, tu cuenta será eliminada.
Vincular un nuevo dispositivo
Código del enlace
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7159c224..5a6a44a1 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -6,7 +6,6 @@
Done
Copy
Remove
- Wipe
Cancel
Thanks
Got it
@@ -82,6 +81,7 @@
Uptime: %s
Disconnect
Info
+ Reset
Server
Account
@@ -115,7 +115,7 @@
Data is placed in Google Drive. This specific variant uses the "app-data" scope. Access is only granted to a new folder just for this app. The folder is not visible in your drive. It is similar to how WhatsApp backups work.
Add new Google Drive
Click the sign-in button below to setup Google Drive access.
- Reset all Octi data stored on Google Drive. Your device stays logged into Google Drive.
+ Reset all Octi data stored on Google Drive. Your device stays logged into Google Drive.
Log out from Google Drive and delete data related to this device.
This device is not signed into any Google account.
@@ -128,7 +128,7 @@
JServer is an open-source sync server for Octi by Jakob Möller.
Author
Source code
- Reset this account and delete all stored data. Your device stays linked to the account.
+ Reset this account and delete stored data. Your device stays linked to the account.
This will remove this device from your account. If this is the last linked device, your account will be deleted.
Link new device
Link code
@@ -154,7 +154,7 @@
KServer is an open-source sync server (in Kotlin) for Octi by darken.
Author
Source code
- Reset this account and delete all stored data. Your device stays linked to the account.
+ Clear device\'s data on this account. Devices stay linked but their stored data is removed.
This will remove this device from your account. If this is the last linked device, your account will be deleted.
Link new device
Link code
diff --git a/sync-core/src/main/java/eu/darken/octi/sync/core/SyncConnector.kt b/sync-core/src/main/java/eu/darken/octi/sync/core/SyncConnector.kt
index 078a78da..e73cd268 100644
--- a/sync-core/src/main/java/eu/darken/octi/sync/core/SyncConnector.kt
+++ b/sync-core/src/main/java/eu/darken/octi/sync/core/SyncConnector.kt
@@ -17,7 +17,7 @@ interface SyncConnector {
/**
* Wipe all Octi data stored via this connector
*/
- suspend fun deleteAll()
+ suspend fun resetData()
suspend fun deleteDevice(deviceId: DeviceId)
diff --git a/sync-core/src/main/java/eu/darken/octi/sync/core/SyncManager.kt b/sync-core/src/main/java/eu/darken/octi/sync/core/SyncManager.kt
index ff9d69e7..90c1da8c 100644
--- a/sync-core/src/main/java/eu/darken/octi/sync/core/SyncManager.kt
+++ b/sync-core/src/main/java/eu/darken/octi/sync/core/SyncManager.kt
@@ -109,31 +109,30 @@ class SyncManager @Inject constructor(
log(TAG) { "write(data=$toWrite) done (${System.currentTimeMillis() - start}ms)" }
}
- suspend fun wipe(identifier: ConnectorId) = withContext(NonCancellable) {
- log(TAG) { "wipe(identifier=$identifier)" }
- getConnectorById(identifier).first().deleteAll()
- log(TAG) { "wipe(identifier=$identifier) done" }
+ suspend fun resetData(identifier: ConnectorId) = withContext(NonCancellable) {
+ log(TAG) { "resetData(identifier=$identifier)" }
+ getConnectorById(identifier).first().resetData()
+ log(TAG) { "resetData(identifier=$identifier) done" }
}
- suspend fun disconnect(identifier: ConnectorId, wipe: Boolean = false) = withContext(NonCancellable) {
- log(TAG) { "disconnect(identifier=$identifier, wipe=$wipe)" }
+ suspend fun disconnect(identifier: ConnectorId) = withContext(NonCancellable) {
+ log(TAG) { "disconnect(identifier=$identifier)" }
val connector = getConnectorById(identifier).first()
- disabledConnectors.value = disabledConnectors.value + connector
+ disabledConnectors.value += connector
try {
hubs.first().filter { it.owns(identifier) }.forEach {
it.remove(identifier)
}
- if (wipe) connector.deleteAll()
} catch (e: Exception) {
- log(TAG, ERROR) { "disconnect($identifier,$wipe=$wipe) failed: ${e.asLog()}" }
+ log(TAG, ERROR) { "disconnect($identifier) failed: ${e.asLog()}" }
} finally {
- disabledConnectors.value = disabledConnectors.value - connector
+ disabledConnectors.value -= connector
}
- log(TAG) { "disconnect(connector=$connector, wipe=$wipe) done" }
+ log(TAG) { "disconnect(connector=$connector) done" }
}
companion object {
diff --git a/syncs-gdrive/src/main/java/eu/darken/octi/syncs/gdrive/core/GDriveAppDataConnector.kt b/syncs-gdrive/src/main/java/eu/darken/octi/syncs/gdrive/core/GDriveAppDataConnector.kt
index 6d84d139..111e8919 100644
--- a/syncs-gdrive/src/main/java/eu/darken/octi/syncs/gdrive/core/GDriveAppDataConnector.kt
+++ b/syncs-gdrive/src/main/java/eu/darken/octi/syncs/gdrive/core/GDriveAppDataConnector.kt
@@ -7,7 +7,11 @@ import dagger.assisted.AssistedInject
import dagger.hilt.android.qualifiers.ApplicationContext
import eu.darken.octi.common.coroutine.AppScope
import eu.darken.octi.common.coroutine.DispatcherProvider
-import eu.darken.octi.common.debug.logging.Logging.Priority.*
+import eu.darken.octi.common.debug.logging.Logging.Priority.DEBUG
+import eu.darken.octi.common.debug.logging.Logging.Priority.ERROR
+import eu.darken.octi.common.debug.logging.Logging.Priority.INFO
+import eu.darken.octi.common.debug.logging.Logging.Priority.VERBOSE
+import eu.darken.octi.common.debug.logging.Logging.Priority.WARN
import eu.darken.octi.common.debug.logging.asLog
import eu.darken.octi.common.debug.logging.log
import eu.darken.octi.common.debug.logging.logTag
@@ -15,11 +19,29 @@ import eu.darken.octi.common.flow.DynamicStateFlow
import eu.darken.octi.common.flow.setupCommonEventHandlers
import eu.darken.octi.common.network.NetworkStateProvider
import eu.darken.octi.module.core.ModuleId
-import eu.darken.octi.sync.core.*
-import kotlinx.coroutines.*
-import kotlinx.coroutines.flow.*
+import eu.darken.octi.sync.core.ConnectorId
+import eu.darken.octi.sync.core.DeviceId
+import eu.darken.octi.sync.core.SyncConnector
+import eu.darken.octi.sync.core.SyncConnectorState
+import eu.darken.octi.sync.core.SyncOptions
+import eu.darken.octi.sync.core.SyncRead
+import eu.darken.octi.sync.core.SyncWrite
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.NonCancellable
+import kotlinx.coroutines.async
+import kotlinx.coroutines.awaitAll
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.MutableSharedFlow
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.flow.launchIn
+import kotlinx.coroutines.flow.onEach
+import kotlinx.coroutines.flow.retry
+import kotlinx.coroutines.plus
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
+import kotlinx.coroutines.withContext
import java.time.Instant
import kotlin.math.max
@@ -88,8 +110,8 @@ class GDriveAppDataConnector @AssistedInject constructor(
writeQueue.emit(toWrite)
}
- override suspend fun deleteAll() {
- log(TAG, INFO) { "deleteAll()" }
+ override suspend fun resetData() {
+ log(TAG, INFO) { "resetData()" }
writeAction {
appDataRoot()
.listFiles()
diff --git a/syncs-jserver/src/main/java/eu/darken/octi/syncs/jserver/core/JServerConnector.kt b/syncs-jserver/src/main/java/eu/darken/octi/syncs/jserver/core/JServerConnector.kt
index e5ed4fc9..7efb482b 100644
--- a/syncs-jserver/src/main/java/eu/darken/octi/syncs/jserver/core/JServerConnector.kt
+++ b/syncs-jserver/src/main/java/eu/darken/octi/syncs/jserver/core/JServerConnector.kt
@@ -7,7 +7,11 @@ import eu.darken.octi.common.collections.fromGzip
import eu.darken.octi.common.collections.toGzip
import eu.darken.octi.common.coroutine.AppScope
import eu.darken.octi.common.coroutine.DispatcherProvider
-import eu.darken.octi.common.debug.logging.Logging.Priority.*
+import eu.darken.octi.common.debug.logging.Logging.Priority.DEBUG
+import eu.darken.octi.common.debug.logging.Logging.Priority.ERROR
+import eu.darken.octi.common.debug.logging.Logging.Priority.INFO
+import eu.darken.octi.common.debug.logging.Logging.Priority.VERBOSE
+import eu.darken.octi.common.debug.logging.Logging.Priority.WARN
import eu.darken.octi.common.debug.logging.asLog
import eu.darken.octi.common.debug.logging.log
import eu.darken.octi.common.debug.logging.logTag
@@ -15,12 +19,31 @@ import eu.darken.octi.common.flow.DynamicStateFlow
import eu.darken.octi.common.flow.setupCommonEventHandlers
import eu.darken.octi.common.network.NetworkStateProvider
import eu.darken.octi.module.core.ModuleId
-import eu.darken.octi.sync.core.*
+import eu.darken.octi.sync.core.ConnectorId
+import eu.darken.octi.sync.core.DeviceId
+import eu.darken.octi.sync.core.SyncConnector
+import eu.darken.octi.sync.core.SyncConnectorState
+import eu.darken.octi.sync.core.SyncOptions
+import eu.darken.octi.sync.core.SyncRead
+import eu.darken.octi.sync.core.SyncSettings
+import eu.darken.octi.sync.core.SyncWrite
import eu.darken.octi.sync.core.encryption.PayloadEncryption
-import kotlinx.coroutines.*
-import kotlinx.coroutines.flow.*
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.NonCancellable
+import kotlinx.coroutines.async
+import kotlinx.coroutines.awaitAll
+import kotlinx.coroutines.delay
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.MutableSharedFlow
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.flow.launchIn
+import kotlinx.coroutines.flow.onEach
+import kotlinx.coroutines.flow.retry
+import kotlinx.coroutines.plus
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
+import kotlinx.coroutines.withContext
import okio.ByteString
import retrofit2.HttpException
import java.time.Duration
@@ -101,13 +124,13 @@ class JServerConnector @AssistedInject constructor(
writeQueue.emit(toWrite)
}
- override suspend fun deleteAll() = writeServerWrapper {
- log(TAG, INFO) { "deleteAll()" }
+ override suspend fun resetData() = writeServerWrapper {
+ log(TAG, INFO) { "resetData()" }
val deviceIds = endpoint.listDevices()
- log(TAG, VERBOSE) { "deleteAll(): Found devices: $deviceIds" }
+ log(TAG, VERBOSE) { "resetData(): Found devices: $deviceIds" }
deviceIds.forEach {
- log(TAG, VERBOSE) { "deleteAll(): Deleting module data for $it" }
+ log(TAG, VERBOSE) { "resetData(): Deleting module data for $it" }
try {
endpoint.deleteModules(it)
} catch (e: Exception) {
diff --git a/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerApi.kt b/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerApi.kt
index 2588d5bc..95e00f1b 100644
--- a/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerApi.kt
+++ b/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerApi.kt
@@ -2,6 +2,7 @@ package eu.darken.octi.syncs.kserver.core
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
+import eu.darken.octi.sync.core.DeviceId
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Response
@@ -58,6 +59,23 @@ interface KServerApi {
@Header("X-Device-ID") deviceID: String,
): DevicesResponse
+ @JsonClass(generateAdapter = true)
+ data class ResetRequest(
+ @Json(name = "targets") val targets: Set,
+ )
+
+ @POST("devices/reset")
+ suspend fun resetDevices(
+ @Header("X-Device-ID") deviceId: String,
+ @Body targets: ResetRequest,
+ )
+
+ @DELETE("devices/{deviceId}")
+ suspend fun deleteDevice(
+ @Header("X-Device-ID") callerDeviceId: String,
+ @Path("deviceId") target: String,
+ )
+
@GET("module/{moduleId}")
suspend fun readModule(
@Path("moduleId") moduleId: String,
@@ -73,9 +91,4 @@ interface KServerApi {
@Body payload: RequestBody,
)
- @DELETE("module")
- suspend fun deleteModules(
- @Header("X-Device-ID") callerDeviceId: String,
- @Query("device-id") targetDeviceId: String,
- )
}
\ No newline at end of file
diff --git a/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerConnector.kt b/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerConnector.kt
index 1be43012..e2439269 100644
--- a/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerConnector.kt
+++ b/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerConnector.kt
@@ -45,7 +45,6 @@ import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withContext
import okio.ByteString
-import retrofit2.HttpException
import java.time.Duration
import java.time.Instant
import kotlin.math.max
@@ -124,33 +123,14 @@ class KServerConnector @AssistedInject constructor(
writeQueue.emit(toWrite)
}
- override suspend fun deleteAll() = writeServerWrapper {
- log(TAG, INFO) { "deleteAll()" }
- val deviceIds = endpoint.listDevices()
- log(TAG, VERBOSE) { "deleteAll(): Found devices: $deviceIds" }
-
- deviceIds.forEach {
- log(TAG, VERBOSE) { "deleteAll(): Deleting module data for $it" }
- try {
- endpoint.deleteModules(it)
- } catch (e: Exception) {
- log(TAG, WARN) { "Failed to delete $it" }
- }
- }
+ override suspend fun resetData() = writeServerWrapper {
+ log(TAG, INFO) { "resetData()" }
+ endpoint.resetDevices()
}
override suspend fun deleteDevice(deviceId: DeviceId) = writeServerWrapper {
log(TAG, INFO) { "deleteDevice(deviceId=$deviceId)" }
- try {
- endpoint.deleteModules(deviceId)
- } catch (e: HttpException) {
- // TODO once we have device deletion as an API, remove this edge case catch
- if (e.code() == 401) {
- log(TAG, WARN) { "Can't delete device because we are not authorized" }
- } else {
- throw e
- }
- }
+ endpoint.deleteDevice(deviceId)
}
suspend fun createLinkCode(): LinkingData {
diff --git a/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerEndpoint.kt b/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerEndpoint.kt
index c5e562de..fa58ec32 100644
--- a/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerEndpoint.kt
+++ b/syncs-kserver/src/main/java/eu/darken/octi/syncs/kserver/core/KServerEndpoint.kt
@@ -104,6 +104,24 @@ class KServerEndpoint @AssistedInject constructor(
response.devices.map { DeviceId(it.id) }
}
+ suspend fun resetDevices(deviceIds: Set = emptySet()): Unit = withContext(dispatcherProvider.IO) {
+ log(TAG) { "resetDevices(deviceIds=$deviceIds)" }
+
+ api.resetDevices(
+ deviceId = ourDeviceIdString,
+ targets = KServerApi.ResetRequest(targets = deviceIds)
+ )
+ }
+
+ suspend fun deleteDevice(deviceId: DeviceId): Unit = withContext(dispatcherProvider.IO) {
+ log(TAG) { "deleteDevice($deviceId)" }
+
+ api.deleteDevice(
+ callerDeviceId = ourDeviceIdString,
+ target = deviceId.id,
+ )
+ }
+
data class ReadData(
val modifiedAt: Instant,
val payload: ByteString,
@@ -141,13 +159,6 @@ class KServerEndpoint @AssistedInject constructor(
)
}
- suspend fun deleteModules(deviceId: DeviceId) = withContext(dispatcherProvider.IO) {
- api.deleteModules(
- callerDeviceId = ourDeviceIdString,
- targetDeviceId = deviceId.id,
- )
- }
-
@AssistedFactory
interface Factory {
fun create(account: KServer.Address): KServerEndpoint