From 43659dffd333c75abba3623a735c2e7a430a8bb4 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 4 Apr 2019 11:10:45 +0200 Subject: [PATCH] Improve signout task --- .../android/internal/auth/SessionParamsStore.kt | 2 +- .../internal/auth/db/RealmSessionParamsStore.kt | 16 +++++++++------- .../internal/session/signout/SignOutTask.kt | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/SessionParamsStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/SessionParamsStore.kt index fa9c73a9..df8b71e4 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/SessionParamsStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/SessionParamsStore.kt @@ -25,5 +25,5 @@ internal interface SessionParamsStore { fun save(sessionParams: SessionParams): Try - fun delete() + fun delete(): Try } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt index e621c6d0..08449586 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/auth/db/RealmSessionParamsStore.kt @@ -50,14 +50,16 @@ internal class RealmSessionParamsStore(private val mapper: SessionParamsMapper, return sessionParams } - override fun delete() { - val realm = Realm.getInstance(realmConfiguration) - realm.executeTransaction { - it.where(SessionParamsEntity::class.java) - .findAll() - .deleteAllFromRealm() + override fun delete(): Try { + return Try { + val realm = Realm.getInstance(realmConfiguration) + realm.executeTransaction { + it.where(SessionParamsEntity::class.java) + .findAll() + .deleteAllFromRealm() + } + realm.close() } - realm.close() } } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutTask.kt index 7ef65e70..6ca971e3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/signout/SignOutTask.kt @@ -30,7 +30,7 @@ internal class DefaultSignOutTask(private val signOutAPI: SignOutAPI, override fun execute(params: Unit): Try { return executeRequest { apiCall = signOutAPI.signOut() - }.map { + }.flatMap { // TODO Clear DB, media cache, etc. sessionParamsStore.delete() }