diff --git a/cryptography/src/androidMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt b/cryptography/src/androidMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt index 8233db701af..40e62aac8b3 100644 --- a/cryptography/src/androidMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt +++ b/cryptography/src/androidMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt @@ -20,13 +20,16 @@ package com.wire.kalium.cryptography import android.util.Base64 import com.wire.cryptobox.CryptoBox +import com.wire.cryptobox.CryptoBox.getFingerprintFromPrekey import com.wire.cryptobox.CryptoException import com.wire.kalium.cryptography.exceptions.ProteusException +import io.ktor.util.decodeBase64Bytes import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.coroutines.withContext import java.io.File import kotlin.coroutines.CoroutineContext +import com.wire.cryptobox.PreKey as CryptoBoxPreKey @Suppress("TooManyFunctions") class ProteusClientCryptoBoxImpl constructor( @@ -54,6 +57,12 @@ class ProteusClientCryptoBoxImpl constructor( wrapException { box.getSession(sessionId.value).remoteFingerprint } } + override suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray = + withContext(defaultContext) { + val cryptoBoxPreKey = CryptoBoxPreKey(preKey.id, preKey.encodedData.decodeBase64Bytes()) + getFingerprintFromPrekey(cryptoBoxPreKey) + } + /** * Create the crypto files if missing and call box.open * this must be called only one time diff --git a/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/ProteusClientCoreCryptoImpl.kt b/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/ProteusClientCoreCryptoImpl.kt index 24417a75d82..5ac3c328386 100644 --- a/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/ProteusClientCoreCryptoImpl.kt +++ b/cryptography/src/appleMain/kotlin/com/wire/kalium/cryptography/ProteusClientCoreCryptoImpl.kt @@ -45,6 +45,11 @@ class ProteusClientCoreCryptoImpl private constructor(private val coreCrypto: Co return wrapException { coreCrypto.proteusFingerprintRemote(sessionId.value).toByteArray() } } + override suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray { + // TODO this is a hack, we need to expose the fingerprint from the core + return "".toByteArray() + } + override suspend fun newPreKeys(from: Int, count: Int): ArrayList { return wrapException { from.until(from + count).map { diff --git a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt index 367db38fbf7..8404bf72f6e 100644 --- a/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt +++ b/cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt @@ -20,6 +20,7 @@ package com.wire.kalium.cryptography import com.wire.crypto.CoreCrypto import com.wire.crypto.CoreCryptoException +import com.wire.crypto.client.toByteArray import com.wire.kalium.cryptography.exceptions.ProteusException import io.ktor.util.decodeBase64Bytes import io.ktor.util.encodeBase64 @@ -45,6 +46,9 @@ class ProteusClientCoreCryptoImpl private constructor( override suspend fun remoteFingerPrint(sessionId: CryptoSessionId): ByteArray = wrapException { coreCrypto.proteusFingerprintRemote(sessionId.value).toByteArray() } + override suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray = wrapException { + coreCrypto.proteusFingerprintPrekeybundle(preKey.encodedData.decodeBase64Bytes()).toByteArray() + } override suspend fun newPreKeys(from: Int, count: Int): ArrayList { return wrapException { diff --git a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/ProteusClient.kt b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/ProteusClient.kt index dc05db78d9e..8790fd1e345 100644 --- a/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/ProteusClient.kt +++ b/cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/ProteusClient.kt @@ -67,6 +67,9 @@ interface ProteusClient { @Throws(ProteusException::class, CancellationException::class) suspend fun remoteFingerPrint(sessionId: CryptoSessionId): ByteArray + @Throws(ProteusException::class, CancellationException::class) + suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray + suspend fun newPreKeys(from: Int, count: Int): List @Throws(ProteusException::class, CancellationException::class) diff --git a/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt b/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt index dc0916b1075..f2603db7334 100644 --- a/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt +++ b/cryptography/src/jsMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt @@ -26,6 +26,7 @@ import com.wire.kalium.cryptography.externals.PreKeyBundle import io.ktor.util.InternalAPI import io.ktor.util.decodeBase64Bytes import io.ktor.util.encodeBase64 +import io.ktor.utils.io.core.toByteArray import kotlinx.coroutines.await import org.khronos.webgl.ArrayBuffer import org.khronos.webgl.Int8Array @@ -57,6 +58,11 @@ class ProteusClientCryptoBoxImpl : ProteusClient { return box.identity.public_key.fingerprint().encodeToByteArray() } + override suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray { + // TODO ("we need to expose the fingerprint from the core") + return "".toByteArray() + } + override suspend fun remoteFingerPrint(sessionId: CryptoSessionId): ByteArray { return box.session_load(sessionId.value).await().fingerprint_remote().encodeToByteArray() } diff --git a/cryptography/src/jvmMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt b/cryptography/src/jvmMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt index 9b1a9de2e9e..765101643a6 100644 --- a/cryptography/src/jvmMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt +++ b/cryptography/src/jvmMain/kotlin/com/wire/kalium/cryptography/ProteusClientCryptoBoxImpl.kt @@ -19,6 +19,7 @@ package com.wire.kalium.cryptography import com.wire.bots.cryptobox.CryptoBox +import com.wire.bots.cryptobox.CryptoBox.getFingerprintFromPrekey import com.wire.bots.cryptobox.CryptoException import com.wire.kalium.cryptography.exceptions.ProteusException import java.io.File @@ -63,6 +64,10 @@ class ProteusClientCryptoBoxImpl constructor( TODO("get session is private in Cryptobox4j") } + override suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray = wrapException { + getFingerprintFromPrekey(toPreKey(preKey)) + } + override suspend fun newLastResortPreKey(): PreKeyCrypto { return wrapException { toPreKey(box.newLastPreKey()) } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/UserConfigRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/UserConfigRepository.kt index 69486ca7109..9240a028204 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/UserConfigRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/UserConfigRepository.kt @@ -19,9 +19,12 @@ package com.wire.kalium.logic.configuration import com.wire.kalium.logic.StorageFailure +import com.wire.kalium.logic.data.conversation.ClientId import com.wire.kalium.logic.data.featureConfig.MLSMigrationModel import com.wire.kalium.logic.data.featureConfig.toEntity import com.wire.kalium.logic.data.featureConfig.toModel +import com.wire.kalium.logic.data.legalhold.LastPreKey +import com.wire.kalium.logic.data.legalhold.LegalHoldRequest import com.wire.kalium.logic.data.message.SelfDeletionMapper.toSelfDeletionTimerEntity import com.wire.kalium.logic.data.message.SelfDeletionMapper.toTeamSelfDeleteTimer import com.wire.kalium.logic.data.message.TeamSettingsSelfDeletionStatus @@ -112,6 +115,8 @@ interface UserConfigRepository { lastPreKeyId: Int, lastPreKey: String ): Either + + fun observeLegalHoldRequest(): Flow> suspend fun deleteLegalHoldRequest(): Either } @@ -398,7 +403,19 @@ internal class UserConfigDataSource internal constructor( userConfigDAO.persistLegalHoldRequest(clientId, lastPreKeyId, lastPreKey) } - override suspend fun deleteLegalHoldRequest(): Either = wrapStorageRequest { - userConfigDAO.clearLegalHoldRequest() - } + override fun observeLegalHoldRequest(): Flow> = + userConfigDAO.observeLegalHoldRequest().wrapStorageRequest().mapRight { + LegalHoldRequest( + clientId = ClientId(it.clientId), + lastPreKey = LastPreKey( + it.lastPreKey.id, + it.lastPreKey.key + ) + ) + } + + override suspend fun deleteLegalHoldRequest(): Either = + wrapStorageRequest { + userConfigDAO.clearLegalHoldRequest() + } } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LastPreKey.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LastPreKey.kt index 5901b76c12c..4dfcc494a87 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LastPreKey.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LastPreKey.kt @@ -19,5 +19,5 @@ package com.wire.kalium.logic.data.legalhold data class LastPreKey( val id: Int, - val key: String, + val key: String ) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LegalHoldRequest.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LegalHoldRequest.kt new file mode 100644 index 00000000000..bdf6afdb7d7 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/legalhold/LegalHoldRequest.kt @@ -0,0 +1,25 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.data.legalhold + +import com.wire.kalium.logic.data.conversation.ClientId + +data class LegalHoldRequest( + val clientId: ClientId, + val lastPreKey: LastPreKey +) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/prekey/PreKeyRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/prekey/PreKeyRepository.kt index 7e38cd32a01..87c5838af75 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/prekey/PreKeyRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/prekey/PreKeyRepository.kt @@ -49,6 +49,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import kotlinx.datetime.Instant +@Suppress("TooManyFunctions") interface PreKeyRepository { /** * Fetches the IDs of the prekeys currently available on the backend. @@ -121,9 +122,11 @@ interface PreKeyRepository { suspend fun establishSessions( missingContactClients: Map> ): Either + + suspend fun getFingerprintForPreKey(preKeyCrypto: PreKeyCrypto): Either } -@Suppress("LongParameterList") +@Suppress("LongParameterList", "TooManyFunctions") class PreKeyDataSource( private val preKeyApi: PreKeyApi, private val proteusClientProvider: ProteusClientProvider, @@ -218,6 +221,13 @@ class PreKeyDataSource( } } + override suspend fun getFingerprintForPreKey(preKeyCrypto: PreKeyCrypto): Either = + proteusClientProvider.getOrError().flatMap { proteusClient -> + wrapProteusRequest { + proteusClient.getFingerprintFromPreKey(preKeyCrypto) + } + } + internal suspend fun preKeysOfClientsByQualifiedUsers( qualifiedIdsMap: Map> ): Either = wrapApiRequest { diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index 84df6ddabf0..780af5283c4 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -217,6 +217,8 @@ import com.wire.kalium.logic.feature.featureConfig.handler.SecondFactorPasswordC import com.wire.kalium.logic.feature.featureConfig.handler.SelfDeletingMessagesConfigHandler import com.wire.kalium.logic.feature.keypackage.KeyPackageManager import com.wire.kalium.logic.feature.keypackage.KeyPackageManagerImpl +import com.wire.kalium.logic.feature.legalhold.LegalHoldRequestUseCase +import com.wire.kalium.logic.feature.legalhold.LegalHoldRequestUseCaseImpl import com.wire.kalium.logic.feature.message.AddSystemMessageToAllConversationsUseCase import com.wire.kalium.logic.feature.message.AddSystemMessageToAllConversationsUseCaseImpl import com.wire.kalium.logic.feature.message.EphemeralEventsNotificationManagerImpl @@ -1736,6 +1738,12 @@ class UserSessionScope internal constructor( } } + val legalHoldRequestUseCase: LegalHoldRequestUseCase + get() = LegalHoldRequestUseCaseImpl( + userConfigRepository = userConfigRepository, + preKeyRepository = preKeyRepository + ) + internal val getProxyCredentials: GetProxyCredentialsUseCase get() = GetProxyCredentialsUseCaseImpl(sessionManager) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/legalhold/LegalHoldRequestUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/legalhold/LegalHoldRequestUseCase.kt new file mode 100644 index 00000000000..96bdccfb311 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/legalhold/LegalHoldRequestUseCase.kt @@ -0,0 +1,90 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.legalhold + +import com.wire.kalium.cryptography.PreKeyCrypto +import com.wire.kalium.logic.CoreFailure +import com.wire.kalium.logic.StorageFailure +import com.wire.kalium.logic.configuration.UserConfigRepository +import com.wire.kalium.logic.data.prekey.PreKeyRepository +import com.wire.kalium.logic.functional.fold +import com.wire.kalium.logic.kaliumLogger +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +/** + * Use case that observes the legal hold request. + */ +interface LegalHoldRequestUseCase { + operator fun invoke(): Flow +} + +internal class LegalHoldRequestUseCaseImpl internal constructor( + val userConfigRepository: UserConfigRepository, + val preKeyRepository: PreKeyRepository +) : LegalHoldRequestUseCase { + override fun invoke(): Flow = + userConfigRepository.observeLegalHoldRequest().map { + it.fold( + { failure -> + if (failure is StorageFailure.DataNotFound) { + kaliumLogger.i("No legal hold request found") + LegalHoldRequestObserverResult.NoLegalHoldRequest + } else { + kaliumLogger.i("Legal hold request failure: $failure") + LegalHoldRequestObserverResult.Failure(failure) + } + }, + { request -> + val preKeyCrypto = PreKeyCrypto(request.lastPreKey.id, request.lastPreKey.key) + val result = preKeyRepository.getFingerprintForPreKey(preKeyCrypto) + result.fold( + { failure -> + kaliumLogger.i("Legal hold request fingerprint failure: $failure") + LegalHoldRequestObserverResult.Failure(failure) + }, + { fingerprint -> + LegalHoldRequestObserverResult.LegalHoldRequestAvailable( + fingerprint + ) + } + ) + } + ) + } +} + +sealed class LegalHoldRequestObserverResult { + data class LegalHoldRequestAvailable(val fingerprint: ByteArray) : LegalHoldRequestObserverResult() { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other == null || this::class != other::class) return false + + other as LegalHoldRequestAvailable + + return fingerprint.contentEquals(other.fingerprint) + } + + override fun hashCode(): Int { + return fingerprint.contentHashCode() + } + } + + data object NoLegalHoldRequest : LegalHoldRequestObserverResult() + data class Failure(val failure: CoreFailure) : LegalHoldRequestObserverResult() +} diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/legalhold/LegalHoldRequestObserverTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/legalhold/LegalHoldRequestObserverTest.kt new file mode 100644 index 00000000000..2061036d44e --- /dev/null +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/legalhold/LegalHoldRequestObserverTest.kt @@ -0,0 +1,148 @@ +/* + * Wire + * Copyright (C) 2023 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.legalhold + +import com.wire.kalium.logic.CoreFailure +import com.wire.kalium.logic.StorageFailure +import com.wire.kalium.logic.configuration.UserConfigRepository +import com.wire.kalium.logic.data.conversation.ClientId +import com.wire.kalium.logic.data.legalhold.LastPreKey +import com.wire.kalium.logic.data.legalhold.LegalHoldRequest +import com.wire.kalium.logic.data.prekey.PreKeyRepository +import com.wire.kalium.logic.functional.Either +import io.ktor.utils.io.core.toByteArray +import io.mockative.Mock +import io.mockative.any +import io.mockative.given +import io.mockative.mock +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertTrue + +class LegalHoldRequestObserverTest { + + @Test + fun givenUserConfigRepositoryDataNotFoundFailure_whenObserving_thenPropagateNoLegalHoldRequest() = + runTest { + val (_, legalHoldRequestObserver) = Arrangement() + .withUserConfigRepositoryDataNotFound() + .arrange() + + val result = legalHoldRequestObserver() + + assertTrue(result.first() is LegalHoldRequestObserverResult.NoLegalHoldRequest) + } + + @Test + fun givenUserConfigRepositoryOtherFailure_whenObserving_thenPropagateFailure() = runTest { + val (_, legalHoldRequestObserver) = Arrangement() + .withUserConfigRepositoryFailure() + .arrange() + + val result = legalHoldRequestObserver() + + assertTrue(result.first() is LegalHoldRequestObserverResult.Failure) + } + + @Test + fun givenPreKeyRepositoryFailure_whenObserving_thenPropagateFailure() = runTest { + val (_, legalHoldRequestObserver) = Arrangement() + .withUserConfigRepositorySuccess() + .withPreKeyRepositoryFailure() + .arrange() + + val result = legalHoldRequestObserver() + + assertTrue(result.first() is LegalHoldRequestObserverResult.Failure) + } + + @Test + fun givenPreKeyRepositorySuccess_whenObserving_thenPropagateLegalHoldRequestAvailable() = + runTest { + val (_, legalHoldRequestObserver) = Arrangement() + .withUserConfigRepositorySuccess() + .withPreKeyRepositorySuccess() + .arrange() + + val result = legalHoldRequestObserver() + + assertTrue(result.first() is LegalHoldRequestObserverResult.LegalHoldRequestAvailable) + } + + private class Arrangement { + + @Mock + val userConfigRepository = mock(UserConfigRepository::class) + + @Mock + val preKeyRepository = mock(PreKeyRepository::class) + + fun withUserConfigRepositorySuccess() = apply { + given(userConfigRepository) + .function(userConfigRepository::observeLegalHoldRequest) + .whenInvoked() + .thenReturn(flowOf(Either.Right(legalHoldRequest))) + } + + fun withUserConfigRepositoryDataNotFound() = apply { + given(userConfigRepository) + .function(userConfigRepository::observeLegalHoldRequest) + .whenInvoked() + .thenReturn(flowOf(Either.Left(StorageFailure.DataNotFound))) + } + + fun withUserConfigRepositoryFailure() = apply { + given(userConfigRepository) + .function(userConfigRepository::observeLegalHoldRequest) + .whenInvoked() + .thenReturn(flowOf(Either.Left(StorageFailure.Generic(IllegalStateException())))) + } + + fun withPreKeyRepositoryFailure() = apply { + given(preKeyRepository) + .suspendFunction(preKeyRepository::getFingerprintForPreKey) + .whenInvokedWith(any()) + .thenReturn(Either.Left(CoreFailure.SyncEventOrClientNotFound)) + } + + fun withPreKeyRepositorySuccess() = apply { + given(preKeyRepository) + .suspendFunction(preKeyRepository::getFingerprintForPreKey) + .whenInvokedWith(any()) + .thenReturn(Either.Right(fingerPrint)) + } + + fun arrange() = this to LegalHoldRequestUseCaseImpl( + userConfigRepository = userConfigRepository, + preKeyRepository = preKeyRepository + ) + } + + companion object { + val legalHoldRequest = LegalHoldRequest( + clientId = ClientId("clientId"), + lastPreKey = LastPreKey( + id = 1, + key = "key" + ) + ) + val fingerPrint = "fingerPrint".toByteArray() + } +} \ No newline at end of file diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MetadataDAO.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MetadataDAO.kt index 7a37aaab2b8..c492658e65c 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MetadataDAO.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MetadataDAO.kt @@ -29,5 +29,5 @@ interface MetadataDAO { suspend fun clear(keysToKeep: List?) suspend fun putSerializable(key: String, value: T, kSerializer: KSerializer) suspend fun getSerializable(key: String, kSerializer: KSerializer): T? - suspend fun observeSerializable(key: String, kSerializer: KSerializer): Flow + fun observeSerializable(key: String, kSerializer: KSerializer): Flow } diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MetadataDAOImpl.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MetadataDAOImpl.kt index ec4d9e436cd..30c4e20981d 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MetadataDAOImpl.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/MetadataDAOImpl.kt @@ -80,7 +80,7 @@ class MetadataDAOImpl internal constructor( } } - override suspend fun observeSerializable(key: String, kSerializer: KSerializer): Flow { + override fun observeSerializable(key: String, kSerializer: KSerializer): Flow { return metadataQueries.selectValueByKey(key) .asFlow() .mapToOneOrNull() diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/unread/UserConfigDAO.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/unread/UserConfigDAO.kt index e2e310b253d..34af338ad1e 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/unread/UserConfigDAO.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/unread/UserConfigDAO.kt @@ -43,7 +43,7 @@ interface UserConfigDAO { suspend fun setSupportedProtocols(protocols: Set) suspend fun persistLegalHoldRequest(clientId: String, lastPreKeyId: Int, lastPreKey: String) suspend fun clearLegalHoldRequest() - suspend fun observeLegalHoldRequest(): Flow + fun observeLegalHoldRequest(): Flow } internal class UserConfigDAOImpl internal constructor( @@ -93,7 +93,7 @@ internal class UserConfigDAOImpl internal constructor( metadataDAO.putSerializable( LEGAL_HOLD_REQUEST, LegalHoldRequestEntity(clientId, LastPreKey(lastPreKeyId, lastPreKey)), - LegalHoldRequestEntity.serializer(), + LegalHoldRequestEntity.serializer() ) } @@ -101,7 +101,7 @@ internal class UserConfigDAOImpl internal constructor( metadataDAO.deleteValue(LEGAL_HOLD_REQUEST) } - override suspend fun observeLegalHoldRequest(): Flow = + override fun observeLegalHoldRequest(): Flow = metadataDAO.observeSerializable(LEGAL_HOLD_REQUEST, LegalHoldRequestEntity.serializer()) private companion object {