@@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.crypto
1919import androidx.lifecycle.LiveData
2020import androidx.lifecycle.asLiveData
2121import com.squareup.moshi.Moshi
22- import com.squareup.moshi.Types
2322import kotlinx.coroutines.flow.Flow
2423import kotlinx.coroutines.flow.channelFlow
2524import kotlinx.coroutines.runBlocking
@@ -254,6 +253,8 @@ internal class OlmMachine @Inject constructor(
254253 *
255254 * @param deviceUnusedFallbackKeyTypes The key algorithms for which the server has an unused fallback key for the device.
256255 *
256+ * @param nextBatch The batch token to pass in the next sync request.
257+ *
257258 * @return The handled events, decrypted if needed (secrets are zeroised).
258259 */
259260 @Throws(CryptoStoreException ::class )
@@ -262,6 +263,7 @@ internal class OlmMachine @Inject constructor(
262263 deviceChanges : DeviceListResponse ? ,
263264 keyCounts : DeviceOneTimeKeysCountSyncResponse ? ,
264265 deviceUnusedFallbackKeyTypes : List <String >? ,
266+ nextBatch : String?
265267 ): ToDeviceSyncResponse {
266268 val response = withContext(coroutineDispatchers.io) {
267269 val counts: MutableMap <String , Int > = mutableMapOf ()
@@ -281,18 +283,16 @@ internal class OlmMachine @Inject constructor(
281283 val events = adapter.toJson(toDevice ? : ToDeviceSyncResponse ())
282284
283285 // field pass in the list of unused fallback keys here
284- val receiveSyncChanges = inner.receiveSyncChanges(events, devices, counts, deviceUnusedFallbackKeyTypes)
285-
286- val outAdapter = moshi.adapter<List <Event >>(
287- Types .newParameterizedType(
288- List ::class .java,
289- Event ::class .java,
290- String ::class .java,
291- Integer ::class .java,
292- Any ::class .java,
293- )
294- )
295- outAdapter.fromJson(receiveSyncChanges) ? : emptyList()
286+ val receiveSyncChanges = inner.receiveSyncChanges(events, devices, counts, deviceUnusedFallbackKeyTypes, nextBatch ? : " " )
287+
288+ val outAdapter = moshi.adapter(Event ::class .java)
289+
290+ // we don't need to use `roomKeyInfos` as for now we are manually
291+ // checking the returned to devices to check for room keys.
292+ // XXX Anyhow there is now proper signaling we should soon stop parsing them manually
293+ receiveSyncChanges.toDeviceEvents.map {
294+ outAdapter.fromJson(it) ? : Event ()
295+ }
296296 }
297297
298298 // We may get cross signing keys over a to-device event, update our listeners.
0 commit comments