From 385720b89da9bae501094821a9ac156e5330e577 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 15 Jun 2022 11:46:57 +0200 Subject: [PATCH 01/24] Replaces flatten parents with direct parent name in RoomSummary --- .../sdk/api/session/room/RoomService.kt | 3 -- .../sdk/api/session/room/model/RoomSummary.kt | 4 +-- .../database/RealmSessionStoreMigration.kt | 2 ++ .../database/mapper/RoomSummaryMapper.kt | 1 + .../database/migration/MigrateSessionTo030.kt | 30 +++++++++++++++++++ .../database/model/RoomSummaryEntity.kt | 5 ++++ .../session/room/DefaultRoomService.kt | 3 +- .../room/summary/RoomSummaryDataSource.kt | 10 +------ .../room/summary/RoomSummaryUpdater.kt | 14 ++++----- .../room/list/RoomListSectionBuilderGroup.kt | 2 +- .../room/list/RoomListSectionBuilderSpace.kt | 2 +- .../home/room/list/RoomSummaryItemFactory.kt | 6 ++-- 12 files changed, 52 insertions(+), 30 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt index 5dfb8961e3..cb4e7d9365 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt @@ -231,14 +231,11 @@ interface RoomService { * @param queryParams The filter to use * @param pagedListConfig The paged list configuration (page size, initial load, prefetch distance...) * @param sortOrder defines how to sort the results - * @param getFlattenParents When true, the list of known parents and grand parents summaries will be resolved. - * This can have significant impact on performance, better be used only on manageable list (filtered by displayName, ..). */ fun getFilteredPagedRoomSummariesLive( queryParams: RoomSummaryQueryParams, pagedListConfig: PagedList.Config = defaultPagedListConfig, sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY, - getFlattenParents: Boolean = false, ): UpdatableLivePageResult /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt index 1ab23b7a11..04c90cdc83 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt @@ -164,9 +164,9 @@ data class RoomSummary( */ val spaceChildren: List? = null, /** - * List of all the space parents. Will be empty by default, you have to explicitly request it. + * The name of the room's direct space parent if any */ - val flattenParents: List = emptyList(), + val directParentName: String? = null, /** * List of all the space parent Ids. */ diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt index 592461f927..4021efb4d5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt @@ -47,6 +47,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo026 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo027 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo028 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo029 +import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo030 import org.matrix.android.sdk.internal.util.Normalizer import timber.log.Timber import javax.inject.Inject @@ -95,5 +96,6 @@ internal class RealmSessionStoreMigration @Inject constructor( if (oldVersion < 27) MigrateSessionTo027(realm).perform() if (oldVersion < 28) MigrateSessionTo028(realm).perform() if (oldVersion < 29) MigrateSessionTo029(realm).perform() + if (oldVersion < 30) MigrateSessionTo030(realm).perform() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt index 735cfe411c..2697a44395 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt @@ -106,6 +106,7 @@ internal class RoomSummaryMapper @Inject constructor( worldReadable = it.childSummaryEntity?.joinRules == RoomJoinRules.PUBLIC ) }, + directParentName = roomSummaryEntity.directParentName, flattenParentIds = roomSummaryEntity.flattenParentIds?.split("|") ?: emptyList(), roomEncryptionAlgorithm = when (val alg = roomSummaryEntity.e2eAlgorithm) { // I should probably use #hasEncryptorClassForAlgorithm but it says it supports diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt new file mode 100644 index 0000000000..9a28cf34c7 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 The Matrix.org Foundation C.I.C. + * + * 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 org.matrix.android.sdk.internal.database.migration + +import io.realm.DynamicRealm +import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields +import org.matrix.android.sdk.internal.util.database.RealmMigrator + +internal class MigrateSessionTo030(realm: DynamicRealm) : RealmMigrator(realm, 30) { + + override fun doMigrate(realm: DynamicRealm) { + realm.schema.get("RoomSummaryEntity") + ?.addField(RoomSummaryEntityFields.DIRECT_PARENT_NAME, String::class.java) + ?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAME, "") } // TODO: make this get the direct parent name + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt index cd755590be..1bdc2d92d3 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt @@ -235,6 +235,11 @@ internal open class RoomSummaryEntity( if (value != field) field = value } + var directParentName: String? = null + set(value) { + if (value != field) field = value + } + var flattenParentIds: String? = null set(value) { if (value != field) field = value diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt index 5e6d052443..646e9fb80c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt @@ -140,9 +140,8 @@ internal class DefaultRoomService @Inject constructor( queryParams: RoomSummaryQueryParams, pagedListConfig: PagedList.Config, sortOrder: RoomSortOrder, - getFlattenParents: Boolean ): UpdatableLivePageResult { - return roomSummaryDataSource.getUpdatablePagedRoomSummariesLive(queryParams, pagedListConfig, sortOrder, getFlattenParents) + return roomSummaryDataSource.getUpdatablePagedRoomSummariesLive(queryParams, pagedListConfig, sortOrder) } override fun getRoomCountLive(queryParams: RoomSummaryQueryParams): LiveData { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt index cb7dc270e8..0895df3fd0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt @@ -200,14 +200,13 @@ internal class RoomSummaryDataSource @Inject constructor( queryParams: RoomSummaryQueryParams, pagedListConfig: PagedList.Config, sortOrder: RoomSortOrder, - getFlattenedParents: Boolean = false ): UpdatableLivePageResult { val realmDataSourceFactory = monarchy.createDataSourceFactory { realm -> roomSummariesQuery(realm, queryParams).process(sortOrder) } val dataSourceFactory = realmDataSourceFactory.map { roomSummaryMapper.map(it) - }.map { if (getFlattenedParents) it.getWithParents() else it } + } val boundaries = MutableLiveData(ResultBoundaries()) @@ -246,13 +245,6 @@ internal class RoomSummaryDataSource @Inject constructor( } } - private fun RoomSummary.getWithParents(): RoomSummary { - val parents = flattenParentIds.mapNotNull { parentId -> - getRoomSummary(parentId) - } - return copy(flattenParents = parents) - } - fun getCountLive(queryParams: RoomSummaryQueryParams): LiveData { val liveRooms = monarchy.findAllManagedWithChanges { roomSummariesQuery(it, queryParams) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt index e4afe7aa49..6659f7f8d9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt @@ -366,24 +366,20 @@ internal class RoomSummaryUpdater @Inject constructor( .forEach { entry -> val parent = RoomSummaryEntity.where(realm, entry.key.roomId).findFirst() if (parent != null) { -// Timber.v("## SPACES: check hierarchy of ${parent.name} id ${parent.roomId}") -// Timber.v("## SPACES: flat known parents of ${parent.name} are ${flattenSpaceParents[parent.roomId]}") val flattenParentsIds = (flattenSpaceParents[parent.roomId] ?: emptyList()) + listOf(parent.roomId) -// Timber.v("## SPACES: flatten known parents of children of ${parent.name} are ${flattenParentsIds}") + entry.value.forEach { child -> RoomSummaryEntity.where(realm, child.roomId).findFirst()?.let { childSum -> + childSum.directParentName = parent.displayName() -// Timber.w("## SPACES: ${childSum.name} is ${childSum.roomId} fc: ${childSum.flattenParentIds}") -// var allParents = childSum.flattenParentIds ?: "" - if (childSum.flattenParentIds == null) childSum.flattenParentIds = "" + if (childSum.flattenParentIds == null) { + childSum.flattenParentIds = "" + } flattenParentsIds.forEach { if (childSum.flattenParentIds?.contains(it) != true) { childSum.flattenParentIds += "|$it" } } -// childSum.flattenParentIds = "$allParents|" - -// Timber.v("## SPACES: flatten of ${childSum.name} is ${childSum.flattenParentIds}") } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt index a8a30349c7..8f7ab46191 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt @@ -71,7 +71,7 @@ class RoomListSectionBuilderGroup( }, { qpm -> val name = stringProvider.getString(R.string.bottom_action_rooms) - val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(qpm, getFlattenParents = true) + val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(qpm) onUpdatable(updatableFilterLivePageResult) val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt index 47a1df3ed0..6b426a3c50 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt @@ -332,7 +332,7 @@ class RoomListSectionBuilderSpace( }, { queryParams -> val name = stringProvider.getString(R.string.bottom_action_rooms) - val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(queryParams, getFlattenParents = true) + val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(queryParams) onUpdatable(updatableFilterLivePageResult) val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index f50cec5149..8941547ac5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -206,10 +206,10 @@ class RoomSummaryItemFactory @Inject constructor( .itemClickListener { onClick?.invoke(roomSummary) } private fun getSearchResultSubtitle(roomSummary: RoomSummary): String { - val userId = roomSummary.directUserId - val spaceName = roomSummary.flattenParents.lastOrNull()?.name + val userId = roomSummary.directParentName + val directParent = roomSummary.directParentName val canonicalAlias = roomSummary.canonicalAlias - return (userId ?: spaceName ?: canonicalAlias).orEmpty() + return (userId ?: directParent ?: canonicalAlias).orEmpty() } } From d40c2f8c78da8fdc63ed9ccc2d6693615d574ad7 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 15 Jun 2022 14:42:08 +0200 Subject: [PATCH 02/24] Fixes migration error --- .../android/sdk/internal/database/RealmSessionStoreMigration.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt index 4021efb4d5..6a8589bc5e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt @@ -62,7 +62,7 @@ internal class RealmSessionStoreMigration @Inject constructor( override fun equals(other: Any?) = other is RealmSessionStoreMigration override fun hashCode() = 1000 - val schemaVersion = 29L + val schemaVersion = 30L override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) { Timber.d("Migrating Realm Session from $oldVersion to $newVersion") From 7f3325e8dfae1b03df44be3e066ef2acae7abce1 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 15 Jun 2022 14:47:26 +0200 Subject: [PATCH 03/24] Fixes wrong user id in search room summary item --- .../sdk/internal/database/migration/MigrateSessionTo030.kt | 2 +- .../app/features/home/room/list/RoomSummaryItemFactory.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt index 9a28cf34c7..87c367e0c9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt @@ -25,6 +25,6 @@ internal class MigrateSessionTo030(realm: DynamicRealm) : RealmMigrator(realm, 3 override fun doMigrate(realm: DynamicRealm) { realm.schema.get("RoomSummaryEntity") ?.addField(RoomSummaryEntityFields.DIRECT_PARENT_NAME, String::class.java) - ?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAME, "") } // TODO: make this get the direct parent name + ?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAME, "") } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index 8941547ac5..6d330952ed 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -206,7 +206,7 @@ class RoomSummaryItemFactory @Inject constructor( .itemClickListener { onClick?.invoke(roomSummary) } private fun getSearchResultSubtitle(roomSummary: RoomSummary): String { - val userId = roomSummary.directParentName + val userId = roomSummary.directUserId val directParent = roomSummary.directParentName val canonicalAlias = roomSummary.canonicalAlias From b5fc0b502c84fc0fe1f50bc9a76012b89bceb5cc Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 15 Jun 2022 15:03:28 +0200 Subject: [PATCH 04/24] Adds changelog file --- changelog.d/6314.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6314.misc diff --git a/changelog.d/6314.misc b/changelog.d/6314.misc new file mode 100644 index 0000000000..865d965d33 --- /dev/null +++ b/changelog.d/6314.misc @@ -0,0 +1 @@ +Improves performance on search screen by replacing flattenParents with directParentName in RoomSummary From 9766b625394de852c16d2aee6fd9c7bb338f0b72 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 15 Jun 2022 16:00:00 +0200 Subject: [PATCH 05/24] Fixes lint error --- .../matrix/android/sdk/api/session/room/model/RoomSummary.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt index 04c90cdc83..60be5d3eb6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt @@ -164,7 +164,7 @@ data class RoomSummary( */ val spaceChildren: List? = null, /** - * The name of the room's direct space parent if any + * The name of the room's direct space parent if any. */ val directParentName: String? = null, /** From cb400b660da1b8cbe11c1baeade57d0d2730ca61 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 29 Jun 2022 17:07:37 +0200 Subject: [PATCH 06/24] Fixes post merge error --- .../database/RealmSessionStoreMigration.kt | 4 ++- .../database/migration/MigrateSessionTo032.kt | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032.kt diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt index 665567bf2a..9be1717f32 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt @@ -49,6 +49,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo028 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo029 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo030 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo031 +import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo032 import org.matrix.android.sdk.internal.util.Normalizer import timber.log.Timber import javax.inject.Inject @@ -63,7 +64,7 @@ internal class RealmSessionStoreMigration @Inject constructor( override fun equals(other: Any?) = other is RealmSessionStoreMigration override fun hashCode() = 1000 - val schemaVersion = 31L + val schemaVersion = 32L override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) { Timber.d("Migrating Realm Session from $oldVersion to $newVersion") @@ -99,5 +100,6 @@ internal class RealmSessionStoreMigration @Inject constructor( if (oldVersion < 29) MigrateSessionTo029(realm).perform() if (oldVersion < 30) MigrateSessionTo030(realm).perform() if (oldVersion < 31) MigrateSessionTo031(realm).perform() + if (oldVersion < 32) MigrateSessionTo032(realm).perform() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032.kt new file mode 100644 index 0000000000..ff8c4cf001 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 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 org.matrix.android.sdk.internal.database.migration + +import io.realm.DynamicRealm +import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields +import org.matrix.android.sdk.internal.util.database.RealmMigrator + +internal class MigrateSessionTo032(realm: DynamicRealm) : RealmMigrator(realm, 32) { + + override fun doMigrate(realm: DynamicRealm) { + realm.schema.get("RoomSummaryEntity") + ?.addField(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java) + ?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, "") } + } +} From ed3a201f0ba5d78906c04d87bbf4bcc284efd45f Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Fri, 1 Jul 2022 13:34:55 +0100 Subject: [PATCH 07/24] Changes directParentName to a list --- .../android/sdk/api/session/room/model/RoomSummary.kt | 4 ++-- .../sdk/internal/database/mapper/RoomSummaryMapper.kt | 2 +- .../sdk/internal/database/model/RoomSummaryEntity.kt | 5 +---- .../internal/session/room/summary/RoomSummaryUpdater.kt | 8 +------- .../app/features/home/room/list/RoomSummaryItemFactory.kt | 2 +- 5 files changed, 6 insertions(+), 15 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt index 60be5d3eb6..ff4977491f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt @@ -164,9 +164,9 @@ data class RoomSummary( */ val spaceChildren: List? = null, /** - * The name of the room's direct space parent if any. + * The names of the room's direct space parents if any. */ - val directParentName: String? = null, + val directParentNames: List = emptyList(), /** * List of all the space parent Ids. */ diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt index 2697a44395..72b0f7a043 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/RoomSummaryMapper.kt @@ -106,7 +106,7 @@ internal class RoomSummaryMapper @Inject constructor( worldReadable = it.childSummaryEntity?.joinRules == RoomJoinRules.PUBLIC ) }, - directParentName = roomSummaryEntity.directParentName, + directParentNames = roomSummaryEntity.directParentNames.toList(), flattenParentIds = roomSummaryEntity.flattenParentIds?.split("|") ?: emptyList(), roomEncryptionAlgorithm = when (val alg = roomSummaryEntity.e2eAlgorithm) { // I should probably use #hasEncryptorClassForAlgorithm but it says it supports diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt index 1bdc2d92d3..47764f0c9a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt @@ -235,10 +235,7 @@ internal open class RoomSummaryEntity( if (value != field) field = value } - var directParentName: String? = null - set(value) { - if (value != field) field = value - } + var directParentNames: RealmList = RealmList() var flattenParentIds: String? = null set(value) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt index 6659f7f8d9..66e2185dae 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt @@ -351,15 +351,9 @@ internal class RoomSummaryUpdater @Inject constructor( } val acyclicGraph = graph.withoutEdges(backEdges) -// Timber.v("## SPACES: acyclicGraph $acyclicGraph") val flattenSpaceParents = acyclicGraph.flattenDestination().map { it.key.name to it.value.map { it.name } }.toMap() -// Timber.v("## SPACES: flattenSpaceParents ${flattenSpaceParents.map { it.key.name to it.value.map { it.name } }.joinToString("\n") { -// it.first + ": [" + it.second.joinToString(",") + "]" -// }}") - -// Timber.v("## SPACES: lookup map ${lookupMap.map { it.key.name to it.value.map { it.name } }.toMap()}") lookupMap.entries .filter { it.key.roomType == RoomType.SPACE && it.key.membership == Membership.JOIN } @@ -370,7 +364,7 @@ internal class RoomSummaryUpdater @Inject constructor( entry.value.forEach { child -> RoomSummaryEntity.where(realm, child.roomId).findFirst()?.let { childSum -> - childSum.directParentName = parent.displayName() + childSum.directParentNames.add(parent.displayName()) if (childSum.flattenParentIds == null) { childSum.flattenParentIds = "" diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index 6d330952ed..f2042e216e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -207,7 +207,7 @@ class RoomSummaryItemFactory @Inject constructor( private fun getSearchResultSubtitle(roomSummary: RoomSummary): String { val userId = roomSummary.directUserId - val directParent = roomSummary.directParentName + val directParent = roomSummary.directParentNames.lastOrNull() val canonicalAlias = roomSummary.canonicalAlias return (userId ?: directParent ?: canonicalAlias).orEmpty() From e003bc973aa6ed3c8c1689d2059de67e30341b43 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 4 Jul 2022 09:37:36 +0100 Subject: [PATCH 08/24] Adds clearing to directParentNames --- .../sdk/internal/session/room/summary/RoomSummaryUpdater.kt | 1 + .../app/features/home/room/list/RoomSummaryItemFactory.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt index 66e2185dae..4a89d97b0c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt @@ -224,6 +224,7 @@ internal class RoomSummaryUpdater @Inject constructor( .sort(RoomSummaryEntityFields.ROOM_ID) .findAll().map { it.flattenParentIds = null + it.directParentNames.clear() it to emptyList().toMutableSet() } .toMap() diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index f2042e216e..79c6fe3209 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -207,7 +207,7 @@ class RoomSummaryItemFactory @Inject constructor( private fun getSearchResultSubtitle(roomSummary: RoomSummary): String { val userId = roomSummary.directUserId - val directParent = roomSummary.directParentNames.lastOrNull() + val directParent = roomSummary.directParentNames.takeIf { it.isNotEmpty() }?.joinToString() val canonicalAlias = roomSummary.canonicalAlias return (userId ?: directParent ?: canonicalAlias).orEmpty() From 98d195c010578d48332a29963375032ac00af084 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Tue, 5 Jul 2022 09:35:05 +0100 Subject: [PATCH 09/24] Changes migration to be realm list field --- .../sdk/internal/database/migration/MigrateSessionTo032.kt | 2 +- .../android/sdk/internal/database/model/RoomSummaryEntity.kt | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032.kt index ff8c4cf001..2a3e497f21 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032.kt @@ -24,7 +24,7 @@ internal class MigrateSessionTo032(realm: DynamicRealm) : RealmMigrator(realm, 3 override fun doMigrate(realm: DynamicRealm) { realm.schema.get("RoomSummaryEntity") - ?.addField(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java) + ?.addRealmListField(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java) ?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, "") } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt index 47764f0c9a..2cdde9884c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt @@ -34,7 +34,8 @@ internal open class RoomSummaryEntity( @PrimaryKey var roomId: String = "", var roomType: String? = null, var parents: RealmList = RealmList(), - var children: RealmList = RealmList() + var children: RealmList = RealmList(), + var directParentNames: RealmList = RealmList(), ) : RealmObject() { private var displayName: String? = "" @@ -235,8 +236,6 @@ internal open class RoomSummaryEntity( if (value != field) field = value } - var directParentNames: RealmList = RealmList() - var flattenParentIds: String? = null set(value) { if (value != field) field = value From c6728dde3886ef5f66172fdb51dfa281ce499575 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 6 Jul 2022 13:36:17 +0100 Subject: [PATCH 10/24] Changes string format of space parents to maintain parity with web --- .../features/home/room/list/RoomSummaryItemFactory.kt | 11 ++++++++++- vector/src/main/res/values/strings.xml | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index 79c6fe3209..60ee1eda83 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -207,9 +207,18 @@ class RoomSummaryItemFactory @Inject constructor( private fun getSearchResultSubtitle(roomSummary: RoomSummary): String { val userId = roomSummary.directUserId - val directParent = roomSummary.directParentNames.takeIf { it.isNotEmpty() }?.joinToString() + val directParent = joinParentNames(roomSummary) val canonicalAlias = roomSummary.canonicalAlias return (userId ?: directParent ?: canonicalAlias).orEmpty() } + + private fun joinParentNames(roomSummary: RoomSummary) = with(roomSummary) { + when (directParentNames.size) { + 0 -> null + 1 -> directParentNames.first() + 2 -> stringProvider.getString(R.string.search_space_two_parents, directParentNames[0], directParentNames[1]) + else -> stringProvider.getString(R.string.search_space_multiple_parents, directParentNames.first(), directParentNames.size - 1) + } + } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 933f3f0602..f0597405d8 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -762,6 +762,8 @@ Filter room members Filter banned users No results + %1$s and %2$s + %1$s and %2$d others All messages From 051f925f0ebaf9eb615ed37a8e38ad826921d56d Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 7 Jul 2022 13:03:58 +0100 Subject: [PATCH 11/24] Adds MigrateSessionTo032Test --- .../migration/MigrateSessionTo032Test.kt | 36 +++++++++++++++ .../sdk/test/fakes/FakeDynamicRealm.kt | 30 +++++++++++++ .../sdk/test/fakes/FakeDynamicRealmObject.kt | 33 ++++++++++++++ .../sdk/test/fakes/FakeRealmObjectSchema.kt | 45 +++++++++++++++++++ .../android/sdk/test/fakes/FakeRealmSchema.kt | 36 +++++++++++++++ 5 files changed, 180 insertions(+) create mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032Test.kt create mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt create mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt create mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt create mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032Test.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032Test.kt new file mode 100644 index 0000000000..f66ccd9cf2 --- /dev/null +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032Test.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 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 org.matrix.android.sdk.internal.database.migration + +import org.junit.Test +import org.matrix.android.sdk.test.fakes.FakeDynamicRealm +import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields + +internal class MigrateSessionTo032Test { + + private val fakeDynamicRealm = FakeDynamicRealm() + private val migrator = MigrateSessionTo032(fakeDynamicRealm.instance) + + @Test + fun `when doMigrate, then directParentNames added`() { + migrator.doMigrate(fakeDynamicRealm.instance) + + fakeDynamicRealm.fakeRealmSchema.withObjectSchema("RoomSummaryEntity") + .verifyListFieldAdded(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java) + .verifyStringTransformation(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, "") + } +} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt new file mode 100644 index 0000000000..939b3be0c1 --- /dev/null +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 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 org.matrix.android.sdk.test.fakes + +import io.mockk.every +import io.mockk.mockk +import io.realm.DynamicRealm + +class FakeDynamicRealm( + val fakeRealmSchema: FakeRealmSchema = FakeRealmSchema() +) { + + val instance: DynamicRealm = mockk { + every { schema } returns fakeRealmSchema.instance + } +} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt new file mode 100644 index 0000000000..1e0e1808b0 --- /dev/null +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2022 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 org.matrix.android.sdk.test.fakes + +import io.mockk.justRun +import io.mockk.mockk +import io.mockk.verify +import io.realm.DynamicRealmObject + +class FakeDynamicRealmObject { + + val instance: DynamicRealmObject = mockk { + justRun { setString(any(), any()) } + } + + fun verifySetString(fieldName: String, value: String) { + verify { instance.setString(fieldName, value) } + } +} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt new file mode 100644 index 0000000000..91f05b9604 --- /dev/null +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 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 org.matrix.android.sdk.test.fakes + +import io.mockk.every +import io.mockk.mockk +import io.mockk.slot +import io.mockk.verify +import io.realm.RealmObjectSchema +import io.realm.RealmObjectSchema.Function + +class FakeRealmObjectSchema( + private val fakeDynamicRealmObject: FakeDynamicRealmObject = FakeDynamicRealmObject() +) { + + val instance: RealmObjectSchema = mockk { + every { addRealmListField(any(), any>()) } returns this + every { transform(any()) } returns this + } + + fun verifyListFieldAdded(fieldName: String, type: Class<*>) = apply { + verify { instance.addRealmListField(fieldName, type) } + } + + fun verifyStringTransformation(fieldName: String, transformedInto: String) = apply { + val transformationSlot = slot() + verify { instance.transform(capture(transformationSlot)) } + transformationSlot.captured.apply(fakeDynamicRealmObject.instance) + fakeDynamicRealmObject.verifySetString(fieldName, transformedInto) + } +} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt new file mode 100644 index 0000000000..519654b883 --- /dev/null +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 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 org.matrix.android.sdk.test.fakes + +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import io.realm.RealmSchema + +class FakeRealmSchema( + private val fakeRealmObjectSchema: FakeRealmObjectSchema = FakeRealmObjectSchema() +) { + + val instance: RealmSchema = mockk { + every { this@mockk.get(any()) } returns fakeRealmObjectSchema.instance + } + + fun withObjectSchema(className: String): FakeRealmObjectSchema { + verify { instance.get(className) } + return fakeRealmObjectSchema + } +} From 13b9b5b5d64f64fc26031cd98549012421934514 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 18 Jul 2022 14:47:09 +0200 Subject: [PATCH 12/24] Changes string into plural --- .../app/features/home/room/list/RoomSummaryItemFactory.kt | 6 +++--- vector/src/main/res/values/strings.xml | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index 60ee1eda83..a78c3d2fdc 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -214,11 +214,11 @@ class RoomSummaryItemFactory @Inject constructor( } private fun joinParentNames(roomSummary: RoomSummary) = with(roomSummary) { - when (directParentNames.size) { + when (val size = directParentNames.size) { 0 -> null 1 -> directParentNames.first() - 2 -> stringProvider.getString(R.string.search_space_two_parents, directParentNames[0], directParentNames[1]) - else -> stringProvider.getString(R.string.search_space_multiple_parents, directParentNames.first(), directParentNames.size - 1) + 2 -> stringProvider.getQuantityString(R.plurals.search_space_parents, 1, directParentNames[0], directParentNames[1]) + else -> stringProvider.getQuantityString(R.plurals.search_space_parents, size - 1, directParentNames[0], directParentNames.size - 1) } } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index f0597405d8..533fbe5bcd 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -762,8 +762,10 @@ Filter room members Filter banned users No results - %1$s and %2$s - %1$s and %2$d others + + %1$s and %2$s + %1$s and %2$d others + All messages From 1ae59656325ded1274b121c1c72630e1e4b39bfb Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 18 Jul 2022 14:48:10 +0200 Subject: [PATCH 13/24] Fixes import order --- .../sdk/internal/database/migration/MigrateSessionTo032Test.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032Test.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032Test.kt index f66ccd9cf2..195b0ae1e3 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032Test.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032Test.kt @@ -17,8 +17,8 @@ package org.matrix.android.sdk.internal.database.migration import org.junit.Test -import org.matrix.android.sdk.test.fakes.FakeDynamicRealm import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields +import org.matrix.android.sdk.test.fakes.FakeDynamicRealm internal class MigrateSessionTo032Test { From 7d29fbc68c1179b6901f77a9f13499b92c32320a Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 18 Jul 2022 15:06:25 +0200 Subject: [PATCH 14/24] Fixes post merge errors --- .../database/RealmSessionStoreMigration.kt | 4 ++- .../database/migration/MigrateSessionTo033.kt | 30 +++++++++++++++++++ ...o032Test.kt => MigrateSessionTo033Test.kt} | 4 +-- .../home/room/list/RoomListSectionBuilder.kt | 2 +- 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033.kt rename matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/{MigrateSessionTo032Test.kt => MigrateSessionTo033Test.kt} (92%) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt index 9be1717f32..b0f2ef34a7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt @@ -50,6 +50,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo029 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo030 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo031 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo032 +import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo033 import org.matrix.android.sdk.internal.util.Normalizer import timber.log.Timber import javax.inject.Inject @@ -64,7 +65,7 @@ internal class RealmSessionStoreMigration @Inject constructor( override fun equals(other: Any?) = other is RealmSessionStoreMigration override fun hashCode() = 1000 - val schemaVersion = 32L + val schemaVersion = 33L override fun migrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) { Timber.d("Migrating Realm Session from $oldVersion to $newVersion") @@ -101,5 +102,6 @@ internal class RealmSessionStoreMigration @Inject constructor( if (oldVersion < 30) MigrateSessionTo030(realm).perform() if (oldVersion < 31) MigrateSessionTo031(realm).perform() if (oldVersion < 32) MigrateSessionTo032(realm).perform() + if (oldVersion < 33) MigrateSessionTo033(realm).perform() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033.kt new file mode 100644 index 0000000000..b356bc6278 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 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 org.matrix.android.sdk.internal.database.migration + +import io.realm.DynamicRealm +import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields +import org.matrix.android.sdk.internal.util.database.RealmMigrator + +internal class MigrateSessionTo033(realm: DynamicRealm) : RealmMigrator(realm, 33) { + + override fun doMigrate(realm: DynamicRealm) { + realm.schema.get("RoomSummaryEntity") + ?.addRealmListField(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java) + ?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, "") } + } +} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032Test.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033Test.kt similarity index 92% rename from matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032Test.kt rename to matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033Test.kt index 195b0ae1e3..a4ff995c44 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032Test.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033Test.kt @@ -20,10 +20,10 @@ import org.junit.Test import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields import org.matrix.android.sdk.test.fakes.FakeDynamicRealm -internal class MigrateSessionTo032Test { +internal class MigrateSessionTo033Test { private val fakeDynamicRealm = FakeDynamicRealm() - private val migrator = MigrateSessionTo032(fakeDynamicRealm.instance) + private val migrator = MigrateSessionTo033(fakeDynamicRealm.instance) @Test fun `when doMigrate, then directParentNames added`() { diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt index 42634c237a..f929366a5e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt @@ -331,7 +331,7 @@ class RoomListSectionBuilder( }, { queryParams -> val name = stringProvider.getString(R.string.bottom_action_rooms) - val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(queryParams, getFlattenParents = true) + val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(queryParams) onUpdatable(updatableFilterLivePageResult) val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() From 7bb7a085a83d8b4dc4fce3961191605ac84f12da Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 18 Jul 2022 15:38:03 +0200 Subject: [PATCH 15/24] Fixes copyright lint error --- .../java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt | 2 +- .../matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt | 2 +- .../org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt | 3 ++- .../java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt index 939b3be0c1..9292d6466e 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright 2022 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt index 1e0e1808b0..50bbe8c71d 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright 2022 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt index 91f05b9604..da93d88041 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt @@ -1,5 +1,6 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright 2022 The Matrix.org Foundation C.I.C. + * Copyright 2022 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt index 519654b883..84ccd61857 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright 2022 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From e6475a3f8369fa4b6b92efd6a5073c05dd9e17e4 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 18 Jul 2022 15:47:19 +0200 Subject: [PATCH 16/24] Fixes copyright lint error --- .../sdk/internal/database/migration/MigrateSessionTo033Test.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033Test.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033Test.kt index a4ff995c44..5e994b2209 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033Test.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033Test.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2022 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From bc5c53b70dee92e965b12f9d51c17c5c898812b0 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 18 Jul 2022 15:53:51 +0200 Subject: [PATCH 17/24] Fixes copyright lint error --- .../sdk/internal/database/migration/MigrateSessionTo033.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033.kt index b356bc6278..a00855e262 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 New Vector Ltd + * Copyright (c) 2022 The Matrix.org Foundation C.I.C. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 6f9b5c010df77812a0acff6c28c9bfaa86f3e118 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Tue, 19 Jul 2022 13:49:21 +0200 Subject: [PATCH 18/24] Deletes migration test --- .../migration/MigrateSessionTo033Test.kt | 36 --------------- .../sdk/test/fakes/FakeDynamicRealm.kt | 30 ------------ .../sdk/test/fakes/FakeDynamicRealmObject.kt | 33 ------------- .../sdk/test/fakes/FakeRealmObjectSchema.kt | 46 ------------------- .../android/sdk/test/fakes/FakeRealmSchema.kt | 36 --------------- 5 files changed, 181 deletions(-) delete mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033Test.kt delete mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt delete mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt delete mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt delete mode 100644 matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033Test.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033Test.kt deleted file mode 100644 index 5e994b2209..0000000000 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033Test.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2022 The Matrix.org Foundation C.I.C. - * - * 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 org.matrix.android.sdk.internal.database.migration - -import org.junit.Test -import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields -import org.matrix.android.sdk.test.fakes.FakeDynamicRealm - -internal class MigrateSessionTo033Test { - - private val fakeDynamicRealm = FakeDynamicRealm() - private val migrator = MigrateSessionTo033(fakeDynamicRealm.instance) - - @Test - fun `when doMigrate, then directParentNames added`() { - migrator.doMigrate(fakeDynamicRealm.instance) - - fakeDynamicRealm.fakeRealmSchema.withObjectSchema("RoomSummaryEntity") - .verifyListFieldAdded(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java) - .verifyStringTransformation(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, "") - } -} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt deleted file mode 100644 index 9292d6466e..0000000000 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealm.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2022 The Matrix.org Foundation C.I.C. - * - * 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 org.matrix.android.sdk.test.fakes - -import io.mockk.every -import io.mockk.mockk -import io.realm.DynamicRealm - -class FakeDynamicRealm( - val fakeRealmSchema: FakeRealmSchema = FakeRealmSchema() -) { - - val instance: DynamicRealm = mockk { - every { schema } returns fakeRealmSchema.instance - } -} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt deleted file mode 100644 index 50bbe8c71d..0000000000 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeDynamicRealmObject.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2022 The Matrix.org Foundation C.I.C. - * - * 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 org.matrix.android.sdk.test.fakes - -import io.mockk.justRun -import io.mockk.mockk -import io.mockk.verify -import io.realm.DynamicRealmObject - -class FakeDynamicRealmObject { - - val instance: DynamicRealmObject = mockk { - justRun { setString(any(), any()) } - } - - fun verifySetString(fieldName: String, value: String) { - verify { instance.setString(fieldName, value) } - } -} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt deleted file mode 100644 index da93d88041..0000000000 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmObjectSchema.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2022 The Matrix.org Foundation C.I.C. - * Copyright 2022 The Matrix.org Foundation C.I.C. - * - * 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 org.matrix.android.sdk.test.fakes - -import io.mockk.every -import io.mockk.mockk -import io.mockk.slot -import io.mockk.verify -import io.realm.RealmObjectSchema -import io.realm.RealmObjectSchema.Function - -class FakeRealmObjectSchema( - private val fakeDynamicRealmObject: FakeDynamicRealmObject = FakeDynamicRealmObject() -) { - - val instance: RealmObjectSchema = mockk { - every { addRealmListField(any(), any>()) } returns this - every { transform(any()) } returns this - } - - fun verifyListFieldAdded(fieldName: String, type: Class<*>) = apply { - verify { instance.addRealmListField(fieldName, type) } - } - - fun verifyStringTransformation(fieldName: String, transformedInto: String) = apply { - val transformationSlot = slot() - verify { instance.transform(capture(transformationSlot)) } - transformationSlot.captured.apply(fakeDynamicRealmObject.instance) - fakeDynamicRealmObject.verifySetString(fieldName, transformedInto) - } -} diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt deleted file mode 100644 index 84ccd61857..0000000000 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/test/fakes/FakeRealmSchema.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2022 The Matrix.org Foundation C.I.C. - * - * 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 org.matrix.android.sdk.test.fakes - -import io.mockk.every -import io.mockk.mockk -import io.mockk.verify -import io.realm.RealmSchema - -class FakeRealmSchema( - private val fakeRealmObjectSchema: FakeRealmObjectSchema = FakeRealmObjectSchema() -) { - - val instance: RealmSchema = mockk { - every { this@mockk.get(any()) } returns fakeRealmObjectSchema.instance - } - - fun withObjectSchema(className: String): FakeRealmObjectSchema { - verify { instance.get(className) } - return fakeRealmObjectSchema - } -} From f9580e6cd5c757f1ea92fbe66a3db2dd2a9b75b5 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Tue, 19 Jul 2022 14:12:56 +0200 Subject: [PATCH 19/24] Fixes error in RealmSessionStoreMigration --- .../android/sdk/internal/database/RealmSessionStoreMigration.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt index 96fdfb96d2..9784412761 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt @@ -67,7 +67,7 @@ internal class RealmSessionStoreMigration @Inject constructor( override fun equals(other: Any?) = other is RealmSessionStoreMigration override fun hashCode() = 1000 - override fun doMigrate(realm: DynamicRealm, oldVersion: Long, newVersion: Long) { + override fun doMigrate(realm: DynamicRealm, oldVersion: Long) { if (oldVersion < 1) MigrateSessionTo001(realm).perform() if (oldVersion < 2) MigrateSessionTo002(realm).perform() if (oldVersion < 3) MigrateSessionTo003(realm).perform() From 5f6f16d94b83f2ce92b2342c2b1aea36dfb0b9f8 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 20 Jul 2022 11:22:42 +0200 Subject: [PATCH 20/24] Adds migrate session to 034 --- .../database/RealmSessionStoreMigration.kt | 4 ++- .../database/migration/MigrateSessionTo034.kt | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo034.kt diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt index 9784412761..64e69bb3e9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt @@ -50,6 +50,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo030 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo031 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo032 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo033 +import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo034 import org.matrix.android.sdk.internal.util.Normalizer import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration import javax.inject.Inject @@ -58,7 +59,7 @@ internal class RealmSessionStoreMigration @Inject constructor( private val normalizer: Normalizer ) : MatrixRealmMigration( dbName = "Session", - schemaVersion = 33L, + schemaVersion = 34L, ) { /** * Forces all RealmSessionStoreMigration instances to be equal. @@ -101,5 +102,6 @@ internal class RealmSessionStoreMigration @Inject constructor( if (oldVersion < 31) MigrateSessionTo031(realm).perform() if (oldVersion < 32) MigrateSessionTo032(realm).perform() if (oldVersion < 33) MigrateSessionTo033(realm).perform() + if (oldVersion < 34) MigrateSessionTo034(realm).perform() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo034.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo034.kt new file mode 100644 index 0000000000..f7c50477e5 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo034.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 The Matrix.org Foundation C.I.C. + * + * 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 org.matrix.android.sdk.internal.database.migration + +import io.realm.DynamicRealm +import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields +import org.matrix.android.sdk.internal.util.database.RealmMigrator + +internal class MigrateSessionTo034(realm: DynamicRealm) : RealmMigrator(realm, 34) { + + override fun doMigrate(realm: DynamicRealm) { + realm.schema.get("RoomSummaryEntity") + ?.addRealmListField(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java) + ?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, "") } + } +} From 10b1443fda17b9b64884b077cbd4e44eeee12514 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 20 Jul 2022 12:12:32 +0200 Subject: [PATCH 21/24] add quick test for direct parent name --- .../sdk/session/space/SpaceHierarchyTest.kt | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt index 80020665f8..18645fd6d9 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceHierarchyTest.kt @@ -610,4 +610,82 @@ class SpaceHierarchyTest : InstrumentedTest { } } } + + @Test + fun testDirectParentNames() = runSessionTest(context()) { commonTestHelper -> + val aliceSession = commonTestHelper.createAccount("Alice", SessionTestParams(true)) + + val spaceAInfo = createPublicSpace( + commonTestHelper, + aliceSession, "SpaceA", + listOf( + Triple("A1", true /*auto-join*/, true/*canonical*/), + Triple("A2", true, true) + ) + ) + + val spaceBInfo = createPublicSpace( + commonTestHelper, + aliceSession, "SpaceB", + listOf( + Triple("B1", true /*auto-join*/, true/*canonical*/), + Triple("B2", true, true), + Triple("B3", true, true) + ) + ) + + // also add B1 in space A + + val B1roomId = spaceBInfo.roomIds.first() + val viaServers = listOf(aliceSession.sessionParams.homeServerHost ?: "") + + val spaceA = aliceSession.spaceService().getSpace(spaceAInfo.spaceId) + val spaceB = aliceSession.spaceService().getSpace(spaceBInfo.spaceId) + commonTestHelper.runBlockingTest { + spaceA!!.addChildren(B1roomId, viaServers, null, true) + } + + commonTestHelper.waitWithLatch { latch -> + commonTestHelper.retryPeriodicallyWithLatch(latch) { + val roomSummary = aliceSession.getRoomSummary(B1roomId) + roomSummary != null && + roomSummary.directParentNames.size == 2 && + roomSummary.directParentNames.contains(spaceA!!.spaceSummary()!!.name) && + roomSummary.directParentNames.contains(spaceB!!.spaceSummary()!!.name) + } + } + + commonTestHelper.waitWithLatch { latch -> + commonTestHelper.retryPeriodicallyWithLatch(latch) { + val roomSummary = aliceSession.getRoomSummary(spaceAInfo.roomIds.first()) + roomSummary != null && + roomSummary.directParentNames.size == 1 && + roomSummary.directParentNames.contains(spaceA!!.spaceSummary()!!.name) + } + } + + val newAName = "FooBar" + commonTestHelper.runBlockingTest { + spaceA!!.asRoom().stateService().updateName(newAName) + } + + commonTestHelper.waitWithLatch { latch -> + commonTestHelper.retryPeriodicallyWithLatch(latch) { + val roomSummary = aliceSession.getRoomSummary(B1roomId) + roomSummary != null && + roomSummary.directParentNames.size == 2 && + roomSummary.directParentNames.contains(newAName) && + roomSummary.directParentNames.contains(spaceB!!.spaceSummary()!!.name) + } + } + + commonTestHelper.waitWithLatch { latch -> + commonTestHelper.retryPeriodicallyWithLatch(latch) { + val roomSummary = aliceSession.getRoomSummary(spaceAInfo.roomIds.first()) + roomSummary != null && + roomSummary.directParentNames.size == 1 && + roomSummary.directParentNames.contains(newAName) + } + } + } } From 0ad2051dd369d7b1910ead6ff78856155b2b6ead Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 20 Jul 2022 14:48:38 +0200 Subject: [PATCH 22/24] Improves plural used in strings --- .../app/features/home/room/list/RoomSummaryItemFactory.kt | 4 ++-- vector/src/main/res/values/strings.xml | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index a78c3d2fdc..85879e6807 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -217,8 +217,8 @@ class RoomSummaryItemFactory @Inject constructor( when (val size = directParentNames.size) { 0 -> null 1 -> directParentNames.first() - 2 -> stringProvider.getQuantityString(R.plurals.search_space_parents, 1, directParentNames[0], directParentNames[1]) - else -> stringProvider.getQuantityString(R.plurals.search_space_parents, size - 1, directParentNames[0], directParentNames.size - 1) + 2 -> stringProvider.getString(R.string.search_space_two_parents, directParentNames[0], directParentNames[1]) + else -> stringProvider.getQuantityString(R.plurals.search_space_multiple_parents, size - 1, directParentNames[0], size - 1) } } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 5243e1bd20..333a626179 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -764,8 +764,9 @@ Filter room members Filter banned users No results - - %1$s and %2$s + %1$s and %2$s + + %1$s and %2$d other %1$s and %2$d others From b89df0b520e70177d680f9c902598ff92ac40281 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 20 Jul 2022 16:45:35 +0200 Subject: [PATCH 23/24] Adds MigrateSessionTo035 --- .../database/RealmSessionStoreMigration.kt | 4 ++- .../database/migration/MigrateSessionTo035.kt | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo035.kt diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt index 64e69bb3e9..b733aa6fc0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt @@ -51,6 +51,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo031 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo032 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo033 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo034 +import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo035 import org.matrix.android.sdk.internal.util.Normalizer import org.matrix.android.sdk.internal.util.database.MatrixRealmMigration import javax.inject.Inject @@ -59,7 +60,7 @@ internal class RealmSessionStoreMigration @Inject constructor( private val normalizer: Normalizer ) : MatrixRealmMigration( dbName = "Session", - schemaVersion = 34L, + schemaVersion = 35L, ) { /** * Forces all RealmSessionStoreMigration instances to be equal. @@ -103,5 +104,6 @@ internal class RealmSessionStoreMigration @Inject constructor( if (oldVersion < 32) MigrateSessionTo032(realm).perform() if (oldVersion < 33) MigrateSessionTo033(realm).perform() if (oldVersion < 34) MigrateSessionTo034(realm).perform() + if (oldVersion < 35) MigrateSessionTo035(realm).perform() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo035.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo035.kt new file mode 100644 index 0000000000..f0d78786ed --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo035.kt @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 The Matrix.org Foundation C.I.C. + * + * 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 org.matrix.android.sdk.internal.database.migration + +import io.realm.DynamicRealm +import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields +import org.matrix.android.sdk.internal.util.database.RealmMigrator + +internal class MigrateSessionTo035(realm: DynamicRealm) : RealmMigrator(realm, 35) { + + override fun doMigrate(realm: DynamicRealm) { + realm.schema.get("RoomSummaryEntity") + ?.addRealmListField(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java) + ?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, "") } + } +} From 3f637ea41a2b7abf49970fa6c4ae1efcb12dcfb5 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Wed, 20 Jul 2022 17:50:59 +0200 Subject: [PATCH 24/24] Fixes migration crash --- .../sdk/internal/database/migration/MigrateSessionTo035.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo035.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo035.kt index f0d78786ed..5b3c95b4a2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo035.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo035.kt @@ -17,6 +17,7 @@ package org.matrix.android.sdk.internal.database.migration import io.realm.DynamicRealm +import io.realm.RealmList import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields import org.matrix.android.sdk.internal.util.database.RealmMigrator @@ -25,6 +26,6 @@ internal class MigrateSessionTo035(realm: DynamicRealm) : RealmMigrator(realm, 3 override fun doMigrate(realm: DynamicRealm) { realm.schema.get("RoomSummaryEntity") ?.addRealmListField(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java) - ?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, "") } + ?.transform { it.setList(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, RealmList("")) } } }