diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/util/Try.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/util/Try.kt
new file mode 100644
index 00000000..365d5472
--- /dev/null
+++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/util/Try.kt
@@ -0,0 +1,30 @@
+/*
+ *
+ * * Copyright 2019 New Vector Ltd
+ * *
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ *
+ */
+
+package im.vector.matrix.android.api.util
+
+import arrow.core.*
+
+inline fun TryOf.onError(f: (Throwable) -> Unit): Try = fix()
+ .fold(
+ {
+ f(it)
+ Failure(it)
+ },
+ { Success(it) }
+ )
diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DeviceListManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DeviceListManager.kt
index 48ddb197..0309af8e 100755
--- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DeviceListManager.kt
+++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/crypto/DeviceListManager.kt
@@ -19,9 +19,9 @@ package im.vector.matrix.android.internal.crypto
import android.text.TextUtils
import arrow.core.Try
-import arrow.instances.`try`.applicativeError.handleError
import im.vector.matrix.android.api.MatrixPatterns
import im.vector.matrix.android.api.auth.data.Credentials
+import im.vector.matrix.android.api.util.onError
import im.vector.matrix.android.internal.crypto.model.MXDeviceInfo
import im.vector.matrix.android.internal.crypto.model.MXUsersDevicesMap
import im.vector.matrix.android.internal.crypto.store.IMXCryptoStore
@@ -270,10 +270,10 @@ internal class DeviceListManager(private val cryptoStore: IMXCryptoStore,
Timber.v("## downloadKeys() : starts")
val t0 = System.currentTimeMillis()
doKeyDownloadForUsers(downloadUsers)
- .flatMap {
+ .map {
Timber.v("## downloadKeys() : doKeyDownloadForUsers succeeds after " + (System.currentTimeMillis() - t0) + " ms")
it.addEntriesFromMap(stored)
- Try.just(it)
+ it
}
}
}
@@ -333,10 +333,9 @@ internal class DeviceListManager(private val cryptoStore: IMXCryptoStore,
}
onKeysDownloadSucceed(filteredUsers, response.failures)
}
- .handleError {
+ .onError {
Timber.e(it, "##doKeyDownloadForUsers(): error")
onKeysDownloadFailed(filteredUsers)
- throw it
}
}
@@ -411,7 +410,7 @@ internal class DeviceListManager(private val cryptoStore: IMXCryptoStore,
if (!isVerified) {
Timber.e("## validateDeviceKeys() : Unable to verify signature on device " + userId + ":"
- + deviceKeys.deviceId + " with error " + errorMessage)
+ + deviceKeys.deviceId + " with error " + errorMessage)
return false
}
@@ -422,8 +421,8 @@ internal class DeviceListManager(private val cryptoStore: IMXCryptoStore,
//
// Should we warn the user about it somehow?
Timber.e("## validateDeviceKeys() : WARNING:Ed25519 key for device " + userId + ":"
- + deviceKeys.deviceId + " has changed : "
- + previouslyStoredDeviceKeys.fingerprint() + " -> " + signKey)
+ + deviceKeys.deviceId + " has changed : "
+ + previouslyStoredDeviceKeys.fingerprint() + " -> " + signKey)
Timber.e("## validateDeviceKeys() : $previouslyStoredDeviceKeys -> $deviceKeys")
Timber.e("## validateDeviceKeys() : " + previouslyStoredDeviceKeys.keys + " -> " + deviceKeys.keys)
diff --git a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt
index 31736e33..8d07b3af 100644
--- a/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt
+++ b/vector/src/main/java/im/vector/riotredesign/features/crypto/keysbackup/restore/KeysBackupRestoreFromKeyFragment.kt
@@ -87,7 +87,7 @@ class KeysBackupRestoreFromKeyFragment : VectorBaseFragment() {
if (value.isNullOrBlank()) {
viewModel.recoveryCodeErrorText.value = context?.getString(R.string.keys_backup_recovery_code_empty_error_message)
} else {
- viewModel.recoverKeys(context!!, sharedViewModel)
+ viewModel.recoverKeys(requireContext(), sharedViewModel)
}
}