Auto-review

This commit is contained in:
Benoit Marty 2020-05-11 02:22:08 +02:00
parent a17932e17e
commit 4b2f8e9174
6 changed files with 101 additions and 29 deletions

View File

@ -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<String>) {
getOrCreate(realm).apply {
get(realm)?.apply {
hashLookupPepper = pepper
hashLookupAlgorithm = RealmList<String>().apply { addAll(algorithms) }
}

View File

@ -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()
}

View File

@ -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()
}

View File

@ -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<List<Term>> = Uninitialized,
val acceptingTerms: Async<Unit> = 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

View File

@ -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<List<Term>> = Uninitialized,
val acceptingTerms: Async<Unit> = Uninitialized
) : MvRxState

View File

@ -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
)