diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/db/IdentityServerQuery.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/db/IdentityServerQuery.kt index b20b6bbdf5..906b4d8d7c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/db/IdentityServerQuery.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/db/IdentityServerQuery.kt @@ -47,7 +47,7 @@ internal fun IdentityServerEntity.Companion.setUrl(realm: Realm, internal fun IdentityServerEntity.Companion.setToken(realm: Realm, newToken: String?) { - getOrCreate(realm).apply { + get(realm)?.apply { token = newToken } } @@ -55,7 +55,7 @@ internal fun IdentityServerEntity.Companion.setToken(realm: Realm, internal fun IdentityServerEntity.Companion.setHashDetails(realm: Realm, pepper: String, algorithms: List) { - getOrCreate(realm).apply { + get(realm)?.apply { hashLookupPepper = pepper hashLookupAlgorithm = RealmList().apply { addAll(algorithms) } } diff --git a/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsAction.kt b/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsAction.kt new file mode 100644 index 0000000000..852a4c3301 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsAction.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2020 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.riotx.features.terms + +import im.vector.riotx.core.platform.VectorViewModelAction + +sealed class ReviewTermsAction : VectorViewModelAction { + data class LoadTerms(val preferredLanguageCode: String) : ReviewTermsAction() + data class MarkTermAsAccepted(val url: String, val accepted: Boolean) : ReviewTermsAction() + object Accept : ReviewTermsAction() +} diff --git a/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsViewEvents.kt b/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsViewEvents.kt new file mode 100644 index 0000000000..7366a1389c --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsViewEvents.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 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.riotx.features.terms + +import im.vector.riotx.core.platform.VectorViewEvents + +sealed class ReviewTermsViewEvents : VectorViewEvents { + data class Failure(val throwable: Throwable, val finish: Boolean) : ReviewTermsViewEvents() + object Success : ReviewTermsViewEvents() +} diff --git a/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsViewModel.kt b/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsViewModel.kt index dd8929869a..90fd01e9e5 100644 --- a/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsViewModel.kt @@ -16,9 +16,7 @@ package im.vector.riotx.features.terms import com.airbnb.mvrx.ActivityViewModelContext -import com.airbnb.mvrx.Async import com.airbnb.mvrx.Loading -import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.MvRxViewModelFactory import com.airbnb.mvrx.Success import com.airbnb.mvrx.Uninitialized @@ -29,34 +27,9 @@ import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.terms.GetTermsResponse import im.vector.riotx.core.extensions.exhaustive -import im.vector.riotx.core.platform.VectorViewEvents import im.vector.riotx.core.platform.VectorViewModel -import im.vector.riotx.core.platform.VectorViewModelAction import timber.log.Timber -data class Term( - val url: String, - val name: String, - val version: String? = null, - val accepted: Boolean = false -) - -data class ReviewTermsViewState( - val termsList: Async> = Uninitialized, - val acceptingTerms: Async = Uninitialized -) : MvRxState - -sealed class ReviewTermsAction : VectorViewModelAction { - data class LoadTerms(val preferredLanguageCode: String) : ReviewTermsAction() - data class MarkTermAsAccepted(val url: String, val accepted: Boolean) : ReviewTermsAction() - object Accept : ReviewTermsAction() -} - -sealed class ReviewTermsViewEvents : VectorViewEvents { - data class Failure(val throwable: Throwable, val finish: Boolean) : ReviewTermsViewEvents() - object Success : ReviewTermsViewEvents() -} - class ReviewTermsViewModel @AssistedInject constructor( @Assisted initialState: ReviewTermsViewState, private val session: Session diff --git a/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsViewState.kt b/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsViewState.kt new file mode 100644 index 0000000000..ccd827f87e --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/terms/ReviewTermsViewState.kt @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 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.riotx.features.terms + +import com.airbnb.mvrx.Async +import com.airbnb.mvrx.MvRxState +import com.airbnb.mvrx.Uninitialized + +data class ReviewTermsViewState( + val termsList: Async> = Uninitialized, + val acceptingTerms: Async = Uninitialized +) : MvRxState diff --git a/vector/src/main/java/im/vector/riotx/features/terms/Term.kt b/vector/src/main/java/im/vector/riotx/features/terms/Term.kt new file mode 100644 index 0000000000..29fae43c64 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/terms/Term.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 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.riotx.features.terms + +data class Term( + val url: String, + val name: String, + val version: String? = null, + val accepted: Boolean = false +)