diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index e0dae499bb..cab81b0283 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -215,7 +215,7 @@ dependencies { implementation libs.google.phonenumber - implementation("org.matrix.rustcomponents:crypto-android:0.3.15") + implementation("org.matrix.rustcomponents:crypto-android:0.3.16") // api project(":library:rustCrypto") testImplementation libs.tests.junit diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/CryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/CryptoService.kt index 31d11f6730..3ed6dd1450 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/CryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/crypto/CryptoService.kt @@ -240,7 +240,8 @@ interface CryptoService { toDevice: ToDeviceSyncResponse?, deviceChanges: DeviceListResponse?, keyCounts: DeviceOneTimeKeysCountSyncResponse?, - deviceUnusedFallbackKeyTypes: List?) + deviceUnusedFallbackKeyTypes: List?, + nextBatch: String?) suspend fun onLiveEvent(roomId: String, event: Event, isInitialSync: Boolean, cryptoStoreAggregator: CryptoStoreAggregator?) suspend fun onStateEvent(roomId: String, event: Event, cryptoStoreAggregator: CryptoStoreAggregator?) {} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt index 998c6ef753..225852a094 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt @@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto import androidx.lifecycle.LiveData import androidx.lifecycle.asLiveData import com.squareup.moshi.Moshi -import com.squareup.moshi.Types import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.channelFlow import kotlinx.coroutines.runBlocking @@ -262,6 +261,7 @@ internal class OlmMachine @Inject constructor( deviceChanges: DeviceListResponse?, keyCounts: DeviceOneTimeKeysCountSyncResponse?, deviceUnusedFallbackKeyTypes: List?, + nextBatch: String? ): ToDeviceSyncResponse { val response = withContext(coroutineDispatchers.io) { val counts: MutableMap = mutableMapOf() @@ -281,18 +281,16 @@ internal class OlmMachine @Inject constructor( val events = adapter.toJson(toDevice ?: ToDeviceSyncResponse()) // field pass in the list of unused fallback keys here - val receiveSyncChanges = inner.receiveSyncChanges(events, devices, counts, deviceUnusedFallbackKeyTypes) + val receiveSyncChanges = inner.receiveSyncChanges(events, devices, counts, deviceUnusedFallbackKeyTypes, nextBatch ?: "") - val outAdapter = moshi.adapter>( - Types.newParameterizedType( - List::class.java, - Event::class.java, - String::class.java, - Integer::class.java, - Any::class.java, - ) - ) - outAdapter.fromJson(receiveSyncChanges) ?: emptyList() + val outAdapter = moshi.adapter(Event::class.java) + + // we don't need to use `roomKeyInfos` as we are for now we are + // checking the returned to devices to check for room keys. + // XXX Anyhow there is now proper signaling we should soon stop parsing them manually + receiveSyncChanges.toDeviceEvents.map { + outAdapter.fromJson(it) ?: Event() + } } // We may get cross signing keys over a to-device event, update our listeners. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt index 558b186cdd..44fd9e6797 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/RustCryptoService.kt @@ -618,9 +618,10 @@ internal class RustCryptoService @Inject constructor( deviceChanges: DeviceListResponse?, keyCounts: DeviceOneTimeKeysCountSyncResponse?, deviceUnusedFallbackKeyTypes: List?, + nextBatch: String?, ) { // Decrypt and handle our to-device events - val toDeviceEvents = this.olmMachine.receiveSyncChanges(toDevice, deviceChanges, keyCounts, deviceUnusedFallbackKeyTypes) + val toDeviceEvents = this.olmMachine.receiveSyncChanges(toDevice, deviceChanges, keyCounts, deviceUnusedFallbackKeyTypes, nextBatch) // Notify the our listeners about room keys so decryption is retried. toDeviceEvents.events.orEmpty().forEach { event -> diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt index 3d0c816cb0..8331786072 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt @@ -184,7 +184,8 @@ internal class SyncResponseHandler @Inject constructor( syncResponse.toDevice, syncResponse.deviceLists, syncResponse.deviceOneTimeKeysCount, - syncResponse.deviceUnusedFallbackKeyTypes + syncResponse.deviceUnusedFallbackKeyTypes, + syncResponse.nextBatch ) }.also { Timber.v("Finish handling toDevice in $it ms")