diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/DefaultIdentityService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/DefaultIdentityService.kt index 1a271e659e..00c4c48a6d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/DefaultIdentityService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/DefaultIdentityService.kt @@ -37,16 +37,16 @@ import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.NoOpCancellable import im.vector.matrix.android.internal.di.AuthenticatedIdentity import im.vector.matrix.android.internal.di.Unauthenticated +import im.vector.matrix.android.internal.extensions.observeNotNull import im.vector.matrix.android.internal.network.RetrofitFactory import im.vector.matrix.android.internal.session.SessionScope import im.vector.matrix.android.internal.session.identity.data.IdentityStore -import im.vector.matrix.android.internal.session.identity.todelete.AccountDataDataSource -import im.vector.matrix.android.internal.session.identity.todelete.observeNotNull import im.vector.matrix.android.internal.session.openid.GetOpenIdTokenTask import im.vector.matrix.android.internal.session.profile.BindThreePidsTask import im.vector.matrix.android.internal.session.profile.UnbindThreePidsTask import im.vector.matrix.android.internal.session.sync.model.accountdata.IdentityServerContent import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData +import im.vector.matrix.android.internal.session.user.accountdata.AccountDataDataSource import im.vector.matrix.android.internal.session.user.accountdata.UpdateUserAccountDataTask import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.launchToCallback diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/todelete/AccountDataDataSource.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/todelete/AccountDataDataSource.kt deleted file mode 100644 index 37b0da9101..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/todelete/AccountDataDataSource.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.matrix.android.internal.session.identity.todelete - -import androidx.lifecycle.LiveData -import androidx.lifecycle.Transformations -import com.zhuinden.monarchy.Monarchy -import im.vector.matrix.android.api.util.Optional -import im.vector.matrix.android.api.util.toOptional -import im.vector.matrix.android.internal.database.model.UserAccountDataEntity -import im.vector.matrix.android.internal.database.model.UserAccountDataEntityFields -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent -import io.realm.Realm -import io.realm.RealmQuery -import javax.inject.Inject - -// There will be a duplicated class when Integration manager will be merged, so delete this one -internal class AccountDataDataSource @Inject constructor(private val monarchy: Monarchy, - private val accountDataMapper: AccountDataMapper) { - - fun getAccountDataEvent(type: String): UserAccountDataEvent? { - return getAccountDataEvents(setOf(type)).firstOrNull() - } - - fun getLiveAccountDataEvent(type: String): LiveData> { - return Transformations.map(getLiveAccountDataEvents(setOf(type))) { - it.firstOrNull()?.toOptional() - } - } - - fun getAccountDataEvents(types: Set): List { - return monarchy.fetchAllMappedSync( - { accountDataEventsQuery(it, types) }, - accountDataMapper::map - ) - } - - fun getLiveAccountDataEvents(types: Set): LiveData> { - return monarchy.findAllMappedWithChanges( - { accountDataEventsQuery(it, types) }, - accountDataMapper::map - ) - } - - private fun accountDataEventsQuery(realm: Realm, types: Set): RealmQuery { - val query = realm.where(UserAccountDataEntity::class.java) - if (types.isNotEmpty()) { - query.`in`(UserAccountDataEntityFields.TYPE, types.toTypedArray()) - } - return query - } -} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/todelete/AccountDataMapper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/todelete/AccountDataMapper.kt deleted file mode 100644 index 3a736681e2..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/todelete/AccountDataMapper.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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.matrix.android.internal.session.identity.todelete - -import com.squareup.moshi.Moshi -import im.vector.matrix.android.api.util.JSON_DICT_PARAMETERIZED_TYPE -import im.vector.matrix.android.internal.database.model.UserAccountDataEntity -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent -import javax.inject.Inject - -// There will be a duplicated class when Integration manager will be merged, so delete this one -internal class AccountDataMapper @Inject constructor(moshi: Moshi) { - - private val adapter = moshi.adapter>(JSON_DICT_PARAMETERIZED_TYPE) - - fun map(entity: UserAccountDataEntity): UserAccountDataEvent { - return UserAccountDataEvent( - type = entity.type ?: "", - content = entity.contentStr?.let { adapter.fromJson(it) }.orEmpty() - ) - } -} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/todelete/LiveData.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/todelete/LiveData.kt deleted file mode 100644 index f84756fa86..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/identity/todelete/LiveData.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.matrix.android.internal.session.identity.todelete - -import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.LiveData -import androidx.lifecycle.Observer - -// There will be a duplicated class when Integration manager will be merged, so delete this one -inline fun LiveData.observeK(owner: LifecycleOwner, crossinline observer: (T?) -> Unit) { - this.observe(owner, Observer { observer(it) }) -} - -inline fun LiveData.observeNotNull(owner: LifecycleOwner, crossinline observer: (T) -> Unit) { - this.observe(owner, Observer { it?.run(observer) }) -} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/terms/DefaultTermsService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/terms/DefaultTermsService.kt index 6d5e597da8..70fc9b1449 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/terms/DefaultTermsService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/terms/DefaultTermsService.kt @@ -28,10 +28,10 @@ import im.vector.matrix.android.internal.network.RetrofitFactory import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.identity.IdentityAuthAPI import im.vector.matrix.android.internal.session.identity.IdentityRegisterTask -import im.vector.matrix.android.internal.session.identity.todelete.AccountDataDataSource import im.vector.matrix.android.internal.session.openid.GetOpenIdTokenTask import im.vector.matrix.android.internal.session.sync.model.accountdata.AcceptedTermsContent import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData +import im.vector.matrix.android.internal.session.user.accountdata.AccountDataDataSource import im.vector.matrix.android.internal.session.user.accountdata.UpdateUserAccountDataTask import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.launchToCallback