From 1436477a144cc82c4642b1c51a0dcfb414ff4067 Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 20 Jul 2020 19:52:24 +0200 Subject: [PATCH] Rework a bit user account data (and avoid blocking syncs) --- .../java/im/vector/matrix/rx/RxSession.kt | 5 +- .../internal/crypto/ssss/QuadSTests.kt | 2 +- .../session/accountdata/AccountDataService.kt | 1 - .../accountdata/UserAccountDataEvent.kt} | 16 +++--- .../accountdata/UserAccountDataTypes.kt | 32 +++++++++++ .../database/mapper/AccountDataMapper.kt | 2 +- .../android/internal/di/MoshiProvider.kt | 12 ----- .../identity/DefaultIdentityService.kt | 4 +- .../integrationmanager/IntegrationManager.kt | 20 +++---- .../sync/UserAccountDataSyncHandler.kt | 54 +++++++++---------- ...ceptedTerms.kt => AcceptedTermsContent.kt} | 6 --- ...taBreadcrumbs.kt => BreadcrumbsContent.kt} | 6 --- ...tDataEvent.kt => DirectMessagesContent.kt} | 10 +--- ...tityServer.kt => IdentityServerContent.kt} | 6 --- .../sync/model/accountdata/UserAccountData.kt | 38 ------------- .../UserAccountDataDirectMessages.kt | 26 --------- .../UserAccountDataIgnoredUsers.kt | 26 --------- .../UserAccountDataIntegrationProvisioning.kt | 27 ---------- .../accountdata/UserAccountDataPushRules.kt | 27 ---------- .../model/accountdata/UserAccountDataSync.kt | 4 +- .../accountdata/UserAccountDataWidgets.kt | 50 ----------------- .../session/terms/DefaultTermsService.kt | 4 +- .../user/accountdata/AccountDataDataSource.kt | 2 +- .../accountdata/DefaultAccountDataService.kt | 2 +- .../accountdata/UpdateIgnoredUserIdsTask.kt | 4 +- .../accountdata/UpdateUserAccountDataTask.kt | 14 ++--- .../internal/session/widgets/WidgetManager.kt | 10 ++-- .../widgets/helper/UserAccountWidgets.kt | 2 +- .../devtools/AccountDataEpoxyController.kt | 5 +- .../settings/devtools/AccountDataFragment.kt | 9 ++-- .../settings/devtools/AccountDataViewModel.kt | 4 +- .../features/widgets/WidgetPostAPIHandler.kt | 4 +- .../signout/ServerBackupStatusViewModel.kt | 4 +- 33 files changed, 117 insertions(+), 321 deletions(-) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/{internal/session/sync/model/accountdata/UserAccountDataAllowedWidgets.kt => api/session/accountdata/UserAccountDataEvent.kt} (64%) create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/accountdata/UserAccountDataTypes.kt rename matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/{UserAccountDataAcceptedTerms.kt => AcceptedTermsContent.kt} (78%) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/{UserAccountDataBreadcrumbs.kt => BreadcrumbsContent.kt} (78%) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/{UserAccountDataEvent.kt => DirectMessagesContent.kt} (67%) rename matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/{UserAccountDataIdentityServer.kt => IdentityServerContent.kt} (77%) delete mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountData.kt delete mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataDirectMessages.kt delete mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataIgnoredUsers.kt delete mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataIntegrationProvisioning.kt delete mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataPushRules.kt delete mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataWidgets.kt diff --git a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt index ca0bb46f4b..f09015e80d 100644 --- a/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt +++ b/matrix-sdk-android-rx/src/main/java/im/vector/matrix/rx/RxSession.kt @@ -42,8 +42,7 @@ import im.vector.matrix.android.api.util.toOptional import im.vector.matrix.android.internal.crypto.model.CryptoDeviceInfo import im.vector.matrix.android.internal.crypto.model.rest.DeviceInfo import im.vector.matrix.android.internal.crypto.store.PrivateKeysInfo -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent import io.reactivex.Observable import io.reactivex.Single import io.reactivex.functions.Function3 @@ -179,7 +178,7 @@ class RxSession(private val session: Session) { } fun liveSecretSynchronisationInfo(): Observable { - return Observable.combineLatest, Optional, Optional, SecretsSynchronisationInfo>( + return Observable.combineLatest, Optional, Optional, SecretsSynchronisationInfo>( liveAccountData(setOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME, KEYBACKUP_SECRET_SSSS_NAME)), liveCrossSigningInfo(session.myUserId), liveCrossSigningPrivateKeys(), diff --git a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/ssss/QuadSTests.kt b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/ssss/QuadSTests.kt index d93b151ded..8bbc74011a 100644 --- a/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/ssss/QuadSTests.kt +++ b/matrix-sdk-android/src/androidTest/java/im/vector/matrix/android/internal/crypto/ssss/QuadSTests.kt @@ -35,7 +35,7 @@ import im.vector.matrix.android.common.TestMatrixCallback import im.vector.matrix.android.internal.crypto.SSSS_ALGORITHM_AES_HMAC_SHA2 import im.vector.matrix.android.internal.crypto.crosssigning.toBase64NoPadding import im.vector.matrix.android.internal.crypto.secrets.DefaultSharedSecretStorageService -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/accountdata/AccountDataService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/accountdata/AccountDataService.kt index ee13d1f097..3d5637caa1 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/accountdata/AccountDataService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/accountdata/AccountDataService.kt @@ -21,7 +21,6 @@ import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.session.events.model.Content import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.Optional -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent interface AccountDataService { /** diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataAllowedWidgets.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/accountdata/UserAccountDataEvent.kt similarity index 64% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataAllowedWidgets.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/accountdata/UserAccountDataEvent.kt index 43f3b3b32a..4ff0975de9 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataAllowedWidgets.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/accountdata/UserAccountDataEvent.kt @@ -14,14 +14,18 @@ * limitations under the License. */ -package im.vector.matrix.android.internal.session.sync.model.accountdata +package im.vector.matrix.android.api.session.accountdata import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.internal.session.integrationmanager.AllowedWidgetsContent +import im.vector.matrix.android.api.session.events.model.Content +/** + * This is a simplified Event with just a type and a content. + * Currently used types are defined in [UserAccountDataTypes]. + */ @JsonClass(generateAdapter = true) -internal data class UserAccountDataAllowedWidgets( - @Json(name = "type") override val type: String = TYPE_ALLOWED_WIDGETS, - @Json(name = "content") val content: AllowedWidgetsContent -) : UserAccountData() +data class UserAccountDataEvent( + @Json(name = "type") val type: String, + @Json(name = "content") val content: Content +) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/accountdata/UserAccountDataTypes.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/accountdata/UserAccountDataTypes.kt new file mode 100644 index 0000000000..49b0c56726 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/accountdata/UserAccountDataTypes.kt @@ -0,0 +1,32 @@ +/* + * 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.session.accountdata + +object UserAccountDataTypes { + + const val TYPE_IGNORED_USER_LIST = "m.ignored_user_list" + const val TYPE_DIRECT_MESSAGES = "m.direct" + const val TYPE_BREADCRUMBS = "im.vector.setting.breadcrumbs" // Was previously "im.vector.riot.breadcrumb_rooms" + const val TYPE_PREVIEW_URLS = "org.matrix.preview_urls" + const val TYPE_WIDGETS = "m.widgets" + const val TYPE_PUSH_RULES = "m.push_rules" + const val TYPE_INTEGRATION_PROVISIONING = "im.vector.setting.integration_provisioning" + const val TYPE_ALLOWED_WIDGETS = "im.vector.setting.allowed_widgets" + const val TYPE_IDENTITY_SERVER = "m.identity_server" + const val TYPE_ACCEPTED_TERMS = "m.accepted_terms" + +} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/AccountDataMapper.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/AccountDataMapper.kt index 528712b731..621267ca40 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/AccountDataMapper.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/mapper/AccountDataMapper.kt @@ -19,7 +19,7 @@ package im.vector.matrix.android.internal.database.mapper 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 im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent import javax.inject.Inject internal class AccountDataMapper @Inject constructor(moshi: Moshi) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MoshiProvider.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MoshiProvider.kt index 3164bf75c0..8a2cc50456 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MoshiProvider.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/MoshiProvider.kt @@ -34,24 +34,12 @@ import im.vector.matrix.android.api.session.room.model.message.MessageVideoConte import im.vector.matrix.android.internal.network.parsing.ForceToBooleanJsonAdapter import im.vector.matrix.android.internal.network.parsing.RuntimeJsonAdapterFactory import im.vector.matrix.android.internal.network.parsing.UriMoshiAdapter -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataBreadcrumbs -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataDirectMessages -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataIgnoredUsers -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataPushRules object MoshiProvider { private val moshi: Moshi = Moshi.Builder() .add(UriMoshiAdapter()) .add(ForceToBooleanJsonAdapter()) - .add(RuntimeJsonAdapterFactory.of(UserAccountData::class.java, "type", UserAccountDataEvent::class.java) - .registerSubtype(UserAccountDataDirectMessages::class.java, UserAccountData.TYPE_DIRECT_MESSAGES) - .registerSubtype(UserAccountDataIgnoredUsers::class.java, UserAccountData.TYPE_IGNORED_USER_LIST) - .registerSubtype(UserAccountDataPushRules::class.java, UserAccountData.TYPE_PUSH_RULES) - .registerSubtype(UserAccountDataBreadcrumbs::class.java, UserAccountData.TYPE_BREADCRUMBS) - ) .add(RuntimeJsonAdapterFactory.of(MessageContent::class.java, "msgtype", MessageDefaultContent::class.java) .registerSubtype(MessageTextContent::class.java, MessageType.MSGTYPE_TEXT) .registerSubtype(MessageNoticeContent::class.java, MessageType.MSGTYPE_NOTICE) 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 13c97599f7..c0462d7af6 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 @@ -46,7 +46,7 @@ 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.api.session.accountdata.UserAccountDataTypes 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 @@ -95,7 +95,7 @@ internal class DefaultIdentityService @Inject constructor( lifecycleRegistry.currentState = Lifecycle.State.STARTED // Observe the account data change accountDataDataSource - .getLiveAccountDataEvent(UserAccountData.TYPE_IDENTITY_SERVER) + .getLiveAccountDataEvent(UserAccountDataTypes.TYPE_IDENTITY_SERVER) .observeNotNull(lifecycleOwner) { notifyIdentityServerUrlChange(it.getOrNull()?.content?.toModel()?.baseUrl) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt index ac50f2118a..27e035e093 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/integrationmanager/IntegrationManager.kt @@ -34,8 +34,8 @@ import im.vector.matrix.android.internal.di.SessionDatabase import im.vector.matrix.android.internal.extensions.observeNotNull import im.vector.matrix.android.internal.session.SessionLifecycleObserver import im.vector.matrix.android.internal.session.SessionScope -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent +import im.vector.matrix.android.api.session.accountdata.UserAccountDataTypes +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent 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.session.widgets.helper.WidgetFactory @@ -87,7 +87,7 @@ internal class IntegrationManager @Inject constructor(matrixConfiguration: Matri lifecycleRegistry.currentState = Lifecycle.State.STARTED observeWellknownConfig() accountDataDataSource - .getLiveAccountDataEvent(UserAccountData.TYPE_ALLOWED_WIDGETS) + .getLiveAccountDataEvent(UserAccountDataTypes.TYPE_ALLOWED_WIDGETS) .observeNotNull(lifecycleOwner) { val allowedWidgetsContent = it.getOrNull()?.content?.toModel() if (allowedWidgetsContent != null) { @@ -95,7 +95,7 @@ internal class IntegrationManager @Inject constructor(matrixConfiguration: Matri } } accountDataDataSource - .getLiveAccountDataEvent(UserAccountData.TYPE_INTEGRATION_PROVISIONING) + .getLiveAccountDataEvent(UserAccountDataTypes.TYPE_INTEGRATION_PROVISIONING) .observeNotNull(lifecycleOwner) { val integrationProvisioningContent = it.getOrNull()?.content?.toModel() if (integrationProvisioningContent != null) { @@ -103,7 +103,7 @@ internal class IntegrationManager @Inject constructor(matrixConfiguration: Matri } } accountDataDataSource - .getLiveAccountDataEvent(UserAccountData.TYPE_WIDGETS) + .getLiveAccountDataEvent(UserAccountDataTypes.TYPE_WIDGETS) .observeNotNull(lifecycleOwner) { val integrationManagerContent = it.getOrNull()?.asIntegrationManagerWidgetContent() val config = integrationManagerContent?.extractIntegrationManagerConfig() @@ -132,7 +132,7 @@ internal class IntegrationManager @Inject constructor(matrixConfiguration: Matri * Returns false if the user as disabled integration manager feature */ fun isIntegrationEnabled(): Boolean { - val integrationProvisioningData = accountDataDataSource.getAccountDataEvent(UserAccountData.TYPE_INTEGRATION_PROVISIONING) + val integrationProvisioningData = accountDataDataSource.getAccountDataEvent(UserAccountDataTypes.TYPE_INTEGRATION_PROVISIONING) val integrationProvisioningContent = integrationProvisioningData?.content?.toModel() return integrationProvisioningContent?.enabled ?: false } @@ -153,7 +153,7 @@ internal class IntegrationManager @Inject constructor(matrixConfiguration: Matri } fun setWidgetAllowed(stateEventId: String, allowed: Boolean, callback: MatrixCallback): Cancelable { - val currentAllowedWidgets = accountDataDataSource.getAccountDataEvent(UserAccountData.TYPE_ALLOWED_WIDGETS) + val currentAllowedWidgets = accountDataDataSource.getAccountDataEvent(UserAccountDataTypes.TYPE_ALLOWED_WIDGETS) val currentContent = currentAllowedWidgets?.content?.toModel() val newContent = if (currentContent == null) { val allowedWidget = mapOf(stateEventId to allowed) @@ -173,13 +173,13 @@ internal class IntegrationManager @Inject constructor(matrixConfiguration: Matri } fun isWidgetAllowed(stateEventId: String): Boolean { - val currentAllowedWidgets = accountDataDataSource.getAccountDataEvent(UserAccountData.TYPE_ALLOWED_WIDGETS) + val currentAllowedWidgets = accountDataDataSource.getAccountDataEvent(UserAccountDataTypes.TYPE_ALLOWED_WIDGETS) val currentContent = currentAllowedWidgets?.content?.toModel() return currentContent?.widgets?.get(stateEventId) ?: false } fun setNativeWidgetDomainAllowed(widgetType: String, domain: String, allowed: Boolean, callback: MatrixCallback): Cancelable { - val currentAllowedWidgets = accountDataDataSource.getAccountDataEvent(UserAccountData.TYPE_ALLOWED_WIDGETS) + val currentAllowedWidgets = accountDataDataSource.getAccountDataEvent(UserAccountDataTypes.TYPE_ALLOWED_WIDGETS) val currentContent = currentAllowedWidgets?.content?.toModel() val newContent = if (currentContent == null) { val nativeAllowedWidgets = mapOf(widgetType to mapOf(domain to allowed)) @@ -203,7 +203,7 @@ internal class IntegrationManager @Inject constructor(matrixConfiguration: Matri } fun isNativeWidgetDomainAllowed(widgetType: String, domain: String?): Boolean { - val currentAllowedWidgets = accountDataDataSource.getAccountDataEvent(UserAccountData.TYPE_ALLOWED_WIDGETS) + val currentAllowedWidgets = accountDataDataSource.getAccountDataEvent(UserAccountDataTypes.TYPE_ALLOWED_WIDGETS) val currentContent = currentAllowedWidgets?.content?.toModel() return currentContent?.native?.get(widgetType)?.get(domain) ?: false } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt index 4d7d056a2b..afa4fb680e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/UserAccountDataSyncHandler.kt @@ -16,11 +16,14 @@ package im.vector.matrix.android.internal.session.sync +import com.squareup.moshi.Moshi import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.pushrules.RuleScope import im.vector.matrix.android.api.pushrules.RuleSetKey +import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent +import im.vector.matrix.android.api.session.accountdata.UserAccountDataTypes import im.vector.matrix.android.api.session.events.model.Content -import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.session.room.model.RoomMemberContent import im.vector.matrix.android.api.session.room.model.RoomSummary @@ -37,16 +40,13 @@ import im.vector.matrix.android.internal.database.model.UserAccountDataEntityFie import im.vector.matrix.android.internal.database.query.getDirectRooms import im.vector.matrix.android.internal.database.query.getOrCreate import im.vector.matrix.android.internal.database.query.where -import im.vector.matrix.android.internal.di.MoshiProvider import im.vector.matrix.android.internal.di.SessionDatabase import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.session.room.membership.RoomMemberHelper import im.vector.matrix.android.internal.session.sync.model.InvitedRoomSync -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataBreadcrumbs -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataDirectMessages -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataIgnoredUsers -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataPushRules +import im.vector.matrix.android.internal.session.sync.model.accountdata.BreadcrumbsContent +import im.vector.matrix.android.internal.session.sync.model.accountdata.DirectMessagesContent +import im.vector.matrix.android.internal.session.sync.model.accountdata.IgnoredUsersContent import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataSync import im.vector.matrix.android.internal.session.user.accountdata.DirectChatsHelper import im.vector.matrix.android.internal.session.user.accountdata.UpdateUserAccountDataTask @@ -60,25 +60,18 @@ internal class UserAccountDataSyncHandler @Inject constructor( @SessionDatabase private val monarchy: Monarchy, @UserId private val userId: String, private val directChatsHelper: DirectChatsHelper, + private val moshi: Moshi, private val updateUserAccountDataTask: UpdateUserAccountDataTask) { fun handle(realm: Realm, accountData: UserAccountDataSync?) { - accountData?.list?.forEach { + accountData?.list?.forEach { event -> // Generic handling, just save in base - handleGenericAccountData(realm, it.type, it.content) - - // Didn't want to break too much thing, so i re-serialize to jsonString before reparsing - // TODO would be better to have a mapper? - val toJson = MoshiProvider.providesMoshi().adapter(Event::class.java).toJson(it) - val model = toJson?.let { json -> - MoshiProvider.providesMoshi().adapter(UserAccountData::class.java).fromJson(json) - } - // Specific parsing - when (model) { - is UserAccountDataDirectMessages -> handleDirectChatRooms(realm, model) - is UserAccountDataPushRules -> handlePushRules(realm, model) - is UserAccountDataIgnoredUsers -> handleIgnoredUsers(realm, model) - is UserAccountDataBreadcrumbs -> handleBreadcrumbs(realm, model) + handleGenericAccountData(realm, event.type, event.content) + when (event.type) { + UserAccountDataTypes.TYPE_DIRECT_MESSAGES -> handleDirectChatRooms(realm, event) + UserAccountDataTypes.TYPE_PUSH_RULES -> handlePushRules(realm, event) + UserAccountDataTypes.TYPE_IGNORED_USER_LIST -> handleIgnoredUsers(realm, event) + UserAccountDataTypes.TYPE_BREADCRUMBS -> handleBreadcrumbs(realm, event) } } } @@ -116,8 +109,8 @@ internal class UserAccountDataSyncHandler @Inject constructor( } } - private fun handlePushRules(realm: Realm, userAccountDataPushRules: UserAccountDataPushRules) { - val pushRules = userAccountDataPushRules.content + private fun handlePushRules(realm: Realm, event: UserAccountDataEvent) { + val pushRules = event.content.toModel() ?: return realm.where(PushRulesEntity::class.java) .findAll() .deleteAllFromRealm() @@ -158,13 +151,14 @@ internal class UserAccountDataSyncHandler @Inject constructor( realm.insertOrUpdate(underrides) } - private fun handleDirectChatRooms(realm: Realm, directMessages: UserAccountDataDirectMessages) { + private fun handleDirectChatRooms(realm: Realm, event: UserAccountDataEvent) { val oldDirectRooms = RoomSummaryEntity.getDirectRooms(realm) oldDirectRooms.forEach { it.isDirect = false it.directUserId = null } - directMessages.content.forEach { + val content = event.content.toModel() ?: return + content.forEach { val userId = it.key it.value.forEach { roomId -> val roomSummaryEntity = RoomSummaryEntity.where(realm, roomId).findFirst() @@ -177,8 +171,8 @@ internal class UserAccountDataSyncHandler @Inject constructor( } } - private fun handleIgnoredUsers(realm: Realm, userAccountDataIgnoredUsers: UserAccountDataIgnoredUsers) { - val userIds = userAccountDataIgnoredUsers.content.ignoredUsers.keys + private fun handleIgnoredUsers(realm: Realm, event: UserAccountDataEvent) { + val userIds = event.content.toModel()?.ignoredUsers?.keys ?: return realm.where(IgnoredUserEntity::class.java) .findAll() .deleteAllFromRealm() @@ -187,8 +181,8 @@ internal class UserAccountDataSyncHandler @Inject constructor( // TODO If not initial sync, we should execute a init sync } - private fun handleBreadcrumbs(realm: Realm, userAccountDataBreadcrumbs: UserAccountDataBreadcrumbs) { - val recentRoomIds = userAccountDataBreadcrumbs.content.recentRoomIds + private fun handleBreadcrumbs(realm: Realm, event: UserAccountDataEvent) { + val recentRoomIds = event.content.toModel()?.recentRoomIds ?: return val entity = BreadcrumbsEntity.getOrCreate(realm) // And save the new received list diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataAcceptedTerms.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/AcceptedTermsContent.kt similarity index 78% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataAcceptedTerms.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/AcceptedTermsContent.kt index ef34503463..c62a9a9502 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataAcceptedTerms.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/AcceptedTermsContent.kt @@ -19,12 +19,6 @@ package im.vector.matrix.android.internal.session.sync.model.accountdata import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -@JsonClass(generateAdapter = true) -internal data class UserAccountDataAcceptedTerms( - @Json(name = "type") override val type: String = TYPE_ACCEPTED_TERMS, - @Json(name = "content") val content: AcceptedTermsContent -) : UserAccountData() - @JsonClass(generateAdapter = true) internal data class AcceptedTermsContent( @Json(name = "accepted") val acceptedTerms: List = emptyList() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataBreadcrumbs.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/BreadcrumbsContent.kt similarity index 78% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataBreadcrumbs.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/BreadcrumbsContent.kt index cf5ee9c5e1..143093b1fd 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataBreadcrumbs.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/BreadcrumbsContent.kt @@ -19,12 +19,6 @@ package im.vector.matrix.android.internal.session.sync.model.accountdata import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -@JsonClass(generateAdapter = true) -internal data class UserAccountDataBreadcrumbs( - @Json(name = "type") override val type: String = TYPE_BREADCRUMBS, - @Json(name = "content") val content: BreadcrumbsContent -) : UserAccountData() - @JsonClass(generateAdapter = true) internal data class BreadcrumbsContent( @Json(name = "recent_rooms") val recentRoomIds: List = emptyList() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataEvent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/DirectMessagesContent.kt similarity index 67% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataEvent.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/DirectMessagesContent.kt index 65d3ce1ce7..875badc736 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataEvent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/DirectMessagesContent.kt @@ -16,12 +16,4 @@ package im.vector.matrix.android.internal.session.sync.model.accountdata -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.util.JsonDict - -@JsonClass(generateAdapter = true) -data class UserAccountDataEvent( - @Json(name = "type") override val type: String, - @Json(name = "content") val content: JsonDict -) : UserAccountData() +typealias DirectMessagesContent = Map> diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataIdentityServer.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/IdentityServerContent.kt similarity index 77% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataIdentityServer.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/IdentityServerContent.kt index 4af2034d64..bf373aaef5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataIdentityServer.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/IdentityServerContent.kt @@ -19,12 +19,6 @@ package im.vector.matrix.android.internal.session.sync.model.accountdata import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -@JsonClass(generateAdapter = true) -internal data class UserAccountDataIdentityServer( - @Json(name = "type") override val type: String = TYPE_IDENTITY_SERVER, - @Json(name = "content") val content: IdentityServerContent? = null -) : UserAccountData() - @JsonClass(generateAdapter = true) internal data class IdentityServerContent( @Json(name = "base_url") val baseUrl: String? = null diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountData.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountData.kt deleted file mode 100644 index d758110e09..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountData.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.internal.session.sync.model.accountdata - -import com.squareup.moshi.Json -import im.vector.matrix.android.internal.session.user.accountdata.AccountDataContent - -abstract class UserAccountData : AccountDataContent { - - @Json(name = "type") abstract val type: String - - companion object { - const val TYPE_IGNORED_USER_LIST = "m.ignored_user_list" - const val TYPE_DIRECT_MESSAGES = "m.direct" - const val TYPE_BREADCRUMBS = "im.vector.setting.breadcrumbs" // Was previously "im.vector.riot.breadcrumb_rooms" - const val TYPE_PREVIEW_URLS = "org.matrix.preview_urls" - const val TYPE_WIDGETS = "m.widgets" - const val TYPE_PUSH_RULES = "m.push_rules" - const val TYPE_INTEGRATION_PROVISIONING = "im.vector.setting.integration_provisioning" - const val TYPE_ALLOWED_WIDGETS = "im.vector.setting.allowed_widgets" - const val TYPE_IDENTITY_SERVER = "m.identity_server" - const val TYPE_ACCEPTED_TERMS = "m.accepted_terms" - } -} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataDirectMessages.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataDirectMessages.kt deleted file mode 100644 index e5c6135bd1..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataDirectMessages.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.internal.session.sync.model.accountdata - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass - -@JsonClass(generateAdapter = true) -internal data class UserAccountDataDirectMessages( - @Json(name = "type") override val type: String = TYPE_DIRECT_MESSAGES, - @Json(name = "content") val content: Map> -) : UserAccountData() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataIgnoredUsers.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataIgnoredUsers.kt deleted file mode 100644 index 63a7604305..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataIgnoredUsers.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.internal.session.sync.model.accountdata - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass - -@JsonClass(generateAdapter = true) -internal data class UserAccountDataIgnoredUsers( - @Json(name = "type") override val type: String = TYPE_IGNORED_USER_LIST, - @Json(name = "content") val content: IgnoredUsersContent -) : UserAccountData() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataIntegrationProvisioning.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataIntegrationProvisioning.kt deleted file mode 100644 index a47bb761cd..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataIntegrationProvisioning.kt +++ /dev/null @@ -1,27 +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.sync.model.accountdata - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass -import im.vector.matrix.android.internal.session.integrationmanager.IntegrationProvisioningContent - -@JsonClass(generateAdapter = true) -internal data class UserAccountDataIntegrationProvisioning( - @Json(name = "type") override val type: String = TYPE_INTEGRATION_PROVISIONING, - @Json(name = "content") val content: IntegrationProvisioningContent -) : UserAccountData() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataPushRules.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataPushRules.kt deleted file mode 100644 index 0d549d1667..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataPushRules.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.internal.session.sync.model.accountdata - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse - -@JsonClass(generateAdapter = true) -internal data class UserAccountDataPushRules( - @Json(name = "type") override val type: String = TYPE_PUSH_RULES, - @Json(name = "content") val content: GetPushRulesResponse -) : UserAccountData() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataSync.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataSync.kt index 8acac86e1a..ff018a5181 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataSync.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataSync.kt @@ -18,9 +18,9 @@ package im.vector.matrix.android.internal.session.sync.model.accountdata import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.session.events.model.Event +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent @JsonClass(generateAdapter = true) internal data class UserAccountDataSync( - @Json(name = "events") val list: List = emptyList() + @Json(name = "events") val list: List = emptyList() ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataWidgets.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataWidgets.kt deleted file mode 100644 index 5c13b4d5fe..0000000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/model/accountdata/UserAccountDataWidgets.kt +++ /dev/null @@ -1,50 +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.sync.model.accountdata - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.session.events.model.Event - -/* -"m.widgets":{ - "stickerpicker_@rxl881:matrix.org_1514573757015":{ - "content":{ - "creatorUserId":"@rxl881:matrix.org", - "data":{ - "..." - }, - "id":"stickerpicker_@rxl881:matrix.org_1514573757015", - "name":"Stickerpicker", - "type":"m.stickerpicker", - "url":"https://...", - "waitForIframeLoad":true - }, - "sender":"@rxl881:matrix.org" - "state_key":"stickerpicker_@rxl881:matrix.org_1514573757015", - "type":"m.widget" - }, -{ - "..." - } -} - */ -@JsonClass(generateAdapter = true) -internal data class UserAccountDataWidgets( - @Json(name = "type") override val type: String = TYPE_WIDGETS, - @Json(name = "content") val content: Map -) : UserAccountData() 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 1781fcc3dc..c70fb11d0c 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 @@ -30,7 +30,7 @@ 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.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.api.session.accountdata.UserAccountDataTypes 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 @@ -109,7 +109,7 @@ internal class DefaultTermsService @Inject constructor( } private fun getAlreadyAcceptedTermUrlsFromAccountData(): Set { - return accountDataDataSource.getAccountDataEvent(UserAccountData.TYPE_ACCEPTED_TERMS) + return accountDataDataSource.getAccountDataEvent(UserAccountDataTypes.TYPE_ACCEPTED_TERMS) ?.content ?.toModel() ?.acceptedTerms diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/AccountDataDataSource.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/AccountDataDataSource.kt index 964ce3509b..ed5f26ab18 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/AccountDataDataSource.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/AccountDataDataSource.kt @@ -25,7 +25,7 @@ import im.vector.matrix.android.internal.database.mapper.AccountDataMapper import im.vector.matrix.android.internal.database.model.UserAccountDataEntity import im.vector.matrix.android.internal.database.model.UserAccountDataEntityFields import im.vector.matrix.android.internal.di.SessionDatabase -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent import io.realm.Realm import io.realm.RealmQuery import javax.inject.Inject diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/DefaultAccountDataService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/DefaultAccountDataService.kt index 82864bb9fb..c8dafcc33e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/DefaultAccountDataService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/DefaultAccountDataService.kt @@ -25,7 +25,7 @@ import im.vector.matrix.android.api.util.Cancelable import im.vector.matrix.android.api.util.Optional import im.vector.matrix.android.internal.di.SessionDatabase import im.vector.matrix.android.internal.session.sync.UserAccountDataSyncHandler -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.configureWith import javax.inject.Inject diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt index bd5af7817a..3a224b273a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateIgnoredUserIdsTask.kt @@ -22,7 +22,7 @@ import im.vector.matrix.android.internal.di.SessionDatabase import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.session.sync.model.accountdata.IgnoredUsersContent -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData +import im.vector.matrix.android.api.session.accountdata.UserAccountDataTypes import im.vector.matrix.android.internal.task.Task import org.greenrobot.eventbus.EventBus import javax.inject.Inject @@ -64,7 +64,7 @@ internal class DefaultUpdateIgnoredUserIdsTask @Inject constructor( val body = IgnoredUsersContent.createWithUserIds(list) executeRequest(eventBus) { - apiCall = accountDataApi.setAccountData(userId, UserAccountData.TYPE_IGNORED_USER_LIST, body) + apiCall = accountDataApi.setAccountData(userId, UserAccountDataTypes.TYPE_IGNORED_USER_LIST, body) } // Update the DB right now (do not wait for the sync to come back with updated data, for a faster UI update) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateUserAccountDataTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateUserAccountDataTask.kt index 8db2ad9781..f456bbebd3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateUserAccountDataTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/user/accountdata/UpdateUserAccountDataTask.kt @@ -23,7 +23,7 @@ import im.vector.matrix.android.internal.session.integrationmanager.IntegrationP import im.vector.matrix.android.internal.session.sync.model.accountdata.AcceptedTermsContent import im.vector.matrix.android.internal.session.sync.model.accountdata.BreadcrumbsContent 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.api.session.accountdata.UserAccountDataTypes import im.vector.matrix.android.internal.task.Task import org.greenrobot.eventbus.EventBus import javax.inject.Inject @@ -35,7 +35,7 @@ internal interface UpdateUserAccountDataTask : Task> ) : Params { @@ -63,7 +63,7 @@ internal interface UpdateUserAccountDataTask : Task? = null, excludedTypes: Set? = null ): LiveData> { - val widgetsAccountData = accountDataDataSource.getLiveAccountDataEvent(UserAccountData.TYPE_WIDGETS) + val widgetsAccountData = accountDataDataSource.getLiveAccountDataEvent(UserAccountDataTypes.TYPE_WIDGETS) return Transformations.map(widgetsAccountData) { it.getOrNull()?.mapToWidgets(widgetTypes, excludedTypes) ?: emptyList() } @@ -146,12 +146,12 @@ internal class WidgetManager @Inject constructor(private val integrationManager: widgetTypes: Set? = null, excludedTypes: Set? = null ): List { - val widgetsAccountData = accountDataDataSource.getAccountDataEvent(UserAccountData.TYPE_WIDGETS) ?: return emptyList() + val widgetsAccountData = accountDataDataSource.getAccountDataEvent(UserAccountDataTypes.TYPE_WIDGETS) ?: return emptyList() return widgetsAccountData.mapToWidgets(widgetTypes, excludedTypes) } private fun UserAccountDataEvent.mapToWidgets(widgetTypes: Set? = null, - excludedTypes: Set? = null): List { + excludedTypes: Set? = null): List { return extractWidgetSequence(widgetFactory) .filter { val widgetType = it.widgetContent.type ?: return@filter false diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/helper/UserAccountWidgets.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/helper/UserAccountWidgets.kt index 113047246e..7f64c8a81e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/helper/UserAccountWidgets.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/widgets/helper/UserAccountWidgets.kt @@ -19,7 +19,7 @@ package im.vector.matrix.android.internal.session.widgets.helper import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.toModel import im.vector.matrix.android.api.util.JsonDict -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent import im.vector.matrix.android.api.session.widgets.model.Widget internal fun UserAccountDataEvent.extractWidgetSequence(widgetFactory: WidgetFactory): Sequence { diff --git a/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataEpoxyController.kt b/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataEpoxyController.kt index c8a09bfb64..821a654342 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataEpoxyController.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataEpoxyController.kt @@ -21,7 +21,8 @@ import com.airbnb.epoxy.TypedEpoxyController import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Loading import com.airbnb.mvrx.Success -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent +import im.vector.matrix.android.api.session.accountdata.UserAccountDataTypes import im.vector.riotx.R import im.vector.riotx.core.epoxy.loadingItem import im.vector.riotx.core.resources.StringProvider @@ -35,7 +36,7 @@ class AccountDataEpoxyController @Inject constructor( ) : TypedEpoxyController() { interface InteractionListener { - fun didTap(data: UserAccountData) + fun didTap(data: UserAccountDataEvent) } var interactionListener: InteractionListener? = null diff --git a/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataFragment.kt index ad8831124a..c873805d7c 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataFragment.kt @@ -21,8 +21,8 @@ import android.view.View import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.matrix.android.internal.di.MoshiProvider -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountDataEvent +import im.vector.matrix.android.api.session.accountdata.UserAccountDataTypes +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent import im.vector.riotx.R import im.vector.riotx.core.extensions.cleanup import im.vector.riotx.core.extensions.configureWith @@ -65,11 +65,10 @@ class AccountDataFragment @Inject constructor( epoxyController.interactionListener = null } - override fun didTap(data: UserAccountData) { - val fb = data as? UserAccountDataEvent ?: return + override fun didTap(data: UserAccountDataEvent) { val jsonString = MoshiProvider.providesMoshi() .adapter(UserAccountDataEvent::class.java) - .toJson(fb) + .toJson(data) JSonViewerDialog.newInstance( jsonString, -1, // open All diff --git a/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataViewModel.kt b/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataViewModel.kt index 32ce17c660..825af6e397 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/devtools/AccountDataViewModel.kt @@ -25,14 +25,14 @@ import com.airbnb.mvrx.ViewModelContext import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import im.vector.matrix.android.api.session.Session -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent import im.vector.matrix.rx.rx import im.vector.riotx.core.platform.EmptyAction import im.vector.riotx.core.platform.EmptyViewEvents import im.vector.riotx.core.platform.VectorViewModel data class AccountDataViewState( - val accountData: Async> = Uninitialized + val accountData: Async> = Uninitialized ) : MvRxState class AccountDataViewModel @AssistedInject constructor(@Assisted initialState: AccountDataViewState, diff --git a/vector/src/main/java/im/vector/riotx/features/widgets/WidgetPostAPIHandler.kt b/vector/src/main/java/im/vector/riotx/features/widgets/WidgetPostAPIHandler.kt index 7115a2ea62..ce3ad466e2 100644 --- a/vector/src/main/java/im/vector/riotx/features/widgets/WidgetPostAPIHandler.kt +++ b/vector/src/main/java/im/vector/riotx/features/widgets/WidgetPostAPIHandler.kt @@ -31,7 +31,7 @@ import im.vector.matrix.android.api.session.room.model.PowerLevelsContent import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsHelper import im.vector.matrix.android.api.session.widgets.WidgetPostAPIMediator import im.vector.matrix.android.api.util.JsonDict -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData +import im.vector.matrix.android.api.session.accountdata.UserAccountDataTypes import im.vector.riotx.R import im.vector.riotx.core.resources.StringProvider import timber.log.Timber @@ -280,7 +280,7 @@ class WidgetPostAPIHandler @AssistedInject constructor(@Assisted private val roo ) ) session.updateAccountData( - type = UserAccountData.TYPE_WIDGETS, + type = UserAccountDataTypes.TYPE_WIDGETS, content = addUserWidgetBody, callback = createWidgetAPICallback(widgetPostAPIMediator, eventData) ) diff --git a/vector/src/main/java/im/vector/riotx/features/workers/signout/ServerBackupStatusViewModel.kt b/vector/src/main/java/im/vector/riotx/features/workers/signout/ServerBackupStatusViewModel.kt index bfeb959534..35dff87ecb 100644 --- a/vector/src/main/java/im/vector/riotx/features/workers/signout/ServerBackupStatusViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/workers/signout/ServerBackupStatusViewModel.kt @@ -28,6 +28,7 @@ import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject import im.vector.matrix.android.api.extensions.orFalse import im.vector.matrix.android.api.session.Session +import im.vector.matrix.android.api.session.accountdata.UserAccountDataEvent import im.vector.matrix.android.api.session.crypto.crosssigning.MASTER_KEY_SSSS_NAME import im.vector.matrix.android.api.session.crypto.crosssigning.MXCrossSigningInfo import im.vector.matrix.android.api.session.crypto.crosssigning.SELF_SIGNING_KEY_SSSS_NAME @@ -36,7 +37,6 @@ import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupState import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupStateListener import im.vector.matrix.android.api.util.Optional import im.vector.matrix.android.internal.crypto.store.PrivateKeysInfo -import im.vector.matrix.android.internal.session.sync.model.accountdata.UserAccountData import im.vector.matrix.rx.rx import im.vector.riotx.core.platform.EmptyAction import im.vector.riotx.core.platform.EmptyViewEvents @@ -97,7 +97,7 @@ class ServerBackupStatusViewModel @AssistedInject constructor(@Assisted initialS keysBackupState.value = session.cryptoService().keysBackupService().state - Observable.combineLatest, Optional, KeysBackupState, Optional, BannerState>( + Observable.combineLatest, Optional, KeysBackupState, Optional, BannerState>( session.rx().liveAccountData(setOf(MASTER_KEY_SSSS_NAME, USER_SIGNING_KEY_SSSS_NAME, SELF_SIGNING_KEY_SSSS_NAME)), session.rx().liveCrossSigningInfo(session.myUserId), keyBackupPublishSubject,