From 65bb1a7ddc124ca925d6f409eb687c4d656e2849 Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 10 Jun 2022 11:35:19 +0200 Subject: [PATCH 1/4] Fix space orphan filtering --- changelog.d/6272.bugfix | 1 + .../java/im/vector/app/features/home/HomeDetailViewModel.kt | 4 ++-- .../features/home/room/list/RoomListSectionBuilderSpace.kt | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 changelog.d/6272.bugfix diff --git a/changelog.d/6272.bugfix b/changelog.d/6272.bugfix new file mode 100644 index 0000000000..beea9e0b23 --- /dev/null +++ b/changelog.d/6272.bugfix @@ -0,0 +1 @@ +Fix: All rooms are shown in Home regardless of the switch state. diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt index 30bff45cbd..b8a9e5744d 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt @@ -289,7 +289,7 @@ class HomeDetailViewModel @AssistedInject constructor( .launchIn(viewModelScope) } - private fun RoomGroupingMethod.BySpace.toActiveSpaceOrOrphanRooms(): SpaceFilter? { - return spaceSummary?.roomId?.toActiveSpaceOrOrphanRooms() + private fun RoomGroupingMethod.BySpace.toActiveSpaceOrOrphanRooms(): SpaceFilter { + return spaceSummary?.roomId.toActiveSpaceOrOrphanRooms() } } 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 adc1206993..445ae7d4f5 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 @@ -371,7 +371,7 @@ class RoomListSectionBuilderSpace( activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater { override fun updateForSpaceId(roomId: String?) { filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy( - spaceFilter = roomId?.toActiveSpaceOrOrphanRooms() + spaceFilter = roomId.toActiveSpaceOrOrphanRooms() ) liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams } } @@ -437,7 +437,7 @@ class RoomListSectionBuilderSpace( return when (spaceFilter) { RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> { copy( - spaceFilter = currentSpace?.toActiveSpaceOrOrphanRooms() + spaceFilter = currentSpace.toActiveSpaceOrOrphanRooms() ) } RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> { From c384a3de8d154c1742c61738f44356184244ea78 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 10 Jun 2022 12:10:59 +0200 Subject: [PATCH 2/4] Fix EventInsertLiveObserver gets blocked by reverting and adding lock instead --- changelog.d/6278.bugfix | 1 + .../database/EventInsertLiveObserver.kt | 100 ++++++++---------- 2 files changed, 47 insertions(+), 54 deletions(-) create mode 100644 changelog.d/6278.bugfix diff --git a/changelog.d/6278.bugfix b/changelog.d/6278.bugfix new file mode 100644 index 0000000000..2ee06eebac --- /dev/null +++ b/changelog.d/6278.bugfix @@ -0,0 +1 @@ +Fix regression on EventInsertLiveObserver getting blocked so there is no event being processed anymore. diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/EventInsertLiveObserver.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/EventInsertLiveObserver.kt index 751992fa7f..38d80c3436 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/EventInsertLiveObserver.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/EventInsertLiveObserver.kt @@ -19,10 +19,9 @@ package org.matrix.android.sdk.internal.database import com.zhuinden.monarchy.Monarchy import io.realm.RealmConfiguration import io.realm.RealmResults -import kotlinx.coroutines.flow.MutableSharedFlow -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock import org.matrix.android.sdk.internal.database.mapper.asDomain import org.matrix.android.sdk.internal.database.model.EventEntity import org.matrix.android.sdk.internal.database.model.EventInsertEntity @@ -37,65 +36,58 @@ internal class EventInsertLiveObserver @Inject constructor(@SessionDatabase real private val processors: Set<@JvmSuppressWildcards EventInsertLiveProcessor>) : RealmLiveEntityObserver(realmConfiguration) { + private val lock = Mutex() + override val query = Monarchy.Query { it.where(EventInsertEntity::class.java).equalTo(EventInsertEntityFields.CAN_BE_PROCESSED, true) } - private val onResultsChangedFlow = MutableSharedFlow>() - - init { - onResultsChangedFlow - .onEach { handleChange(it) } - .launchIn(observerScope) - } - override fun onChange(results: RealmResults) { - if (!results.isLoaded || results.isEmpty()) { - return - } - observerScope.launch { onResultsChangedFlow.emit(results) } - } - - private suspend fun handleChange(results: RealmResults) { - val idsToDeleteAfterProcess = ArrayList() - val filteredEvents = ArrayList(results.size) - Timber.v("EventInsertEntity updated with ${results.size} results in db") - results.forEach { - if (shouldProcess(it)) { - // don't use copy from realm over there - val copiedEvent = EventInsertEntity( - eventId = it.eventId, - eventType = it.eventType - ).apply { - insertType = it.insertType + observerScope.launch { + lock.withLock { + if (!results.isLoaded || results.isEmpty()) { + return@launch } - filteredEvents.add(copiedEvent) + val idsToDeleteAfterProcess = ArrayList() + val filteredEvents = ArrayList(results.size) + Timber.v("EventInsertEntity updated with ${results.size} results in db") + results.forEach { + if (shouldProcess(it)) { + // don't use copy from realm over there + val copiedEvent = EventInsertEntity( + eventId = it.eventId, + eventType = it.eventType + ).apply { + insertType = it.insertType + } + filteredEvents.add(copiedEvent) + } + idsToDeleteAfterProcess.add(it.eventId) + } + awaitTransaction(realmConfiguration) { realm -> + Timber.v("##Transaction: There are ${filteredEvents.size} events to process ") + filteredEvents.forEach { eventInsert -> + val eventId = eventInsert.eventId + val event = EventEntity.where(realm, eventId).findFirst() + if (event == null) { + Timber.v("Event $eventId not found") + return@forEach + } + val domainEvent = event.asDomain() + processors.filter { + it.shouldProcess(eventId, domainEvent.getClearType(), eventInsert.insertType) + }.forEach { + it.process(realm, domainEvent) + } + } + realm.where(EventInsertEntity::class.java) + .`in`(EventInsertEntityFields.EVENT_ID, idsToDeleteAfterProcess.toTypedArray()) + .findAll() + .deleteAllFromRealm() + } + processors.forEach { it.onPostProcess() } } - idsToDeleteAfterProcess.add(it.eventId) } - - awaitTransaction(realmConfiguration) { realm -> - Timber.v("##Transaction: There are ${filteredEvents.size} events to process ") - filteredEvents.forEach { eventInsert -> - val eventId = eventInsert.eventId - val event = EventEntity.where(realm, eventId).findFirst() - if (event == null) { - Timber.v("Event $eventId not found") - return@forEach - } - val domainEvent = event.asDomain() - processors.filter { - it.shouldProcess(eventId, domainEvent.getClearType(), eventInsert.insertType) - }.forEach { - it.process(realm, domainEvent) - } - } - realm.where(EventInsertEntity::class.java) - .`in`(EventInsertEntityFields.EVENT_ID, idsToDeleteAfterProcess.toTypedArray()) - .findAll() - .deleteAllFromRealm() - } - processors.forEach { it.onPostProcess() } } private fun shouldProcess(eventInsertEntity: EventInsertEntity): Boolean { From 2a9ac539e438bf2e0ee7f48cb3e61af0f6399507 Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 13 Jun 2022 11:11:26 +0200 Subject: [PATCH 3/4] Change after PR review --- .../android/sdk/internal/database/EventInsertLiveObserver.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/EventInsertLiveObserver.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/EventInsertLiveObserver.kt index 38d80c3436..6ccd4ae03e 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/EventInsertLiveObserver.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/EventInsertLiveObserver.kt @@ -46,7 +46,7 @@ internal class EventInsertLiveObserver @Inject constructor(@SessionDatabase real observerScope.launch { lock.withLock { if (!results.isLoaded || results.isEmpty()) { - return@launch + return@withLock } val idsToDeleteAfterProcess = ArrayList() val filteredEvents = ArrayList(results.size) From 4fa8e70276c2eba7d92391a356de157aa4c904cd Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 13 Jun 2022 12:37:39 +0200 Subject: [PATCH 4/4] Prepare hotfix 1.4.20 --- CHANGES.md | 9 +++++++++ changelog.d/6272.bugfix | 1 - changelog.d/6278.bugfix | 1 - fastlane/metadata/android/en-US/changelogs/40104200.txt | 2 ++ matrix-sdk-android/build.gradle | 2 +- vector/build.gradle | 2 +- 6 files changed, 13 insertions(+), 4 deletions(-) delete mode 100644 changelog.d/6272.bugfix delete mode 100644 changelog.d/6278.bugfix create mode 100644 fastlane/metadata/android/en-US/changelogs/40104200.txt diff --git a/CHANGES.md b/CHANGES.md index 166453dfad..60497402e9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,12 @@ +Changes in Element 1.4.20 (2022-06-13) +====================================== + +Bugfixes 🐛 +---------- + - Fix: All rooms are shown in Home regardless of the switch state. ([#6272](https://github.com/vector-im/element-android/issues/6272)) + - Fix regression on EventInsertLiveObserver getting blocked so there is no event being processed anymore. ([#6278](https://github.com/vector-im/element-android/issues/6278)) + + Changes in Element 1.4.19 (2022-06-07) ====================================== diff --git a/changelog.d/6272.bugfix b/changelog.d/6272.bugfix deleted file mode 100644 index beea9e0b23..0000000000 --- a/changelog.d/6272.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix: All rooms are shown in Home regardless of the switch state. diff --git a/changelog.d/6278.bugfix b/changelog.d/6278.bugfix deleted file mode 100644 index 2ee06eebac..0000000000 --- a/changelog.d/6278.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix regression on EventInsertLiveObserver getting blocked so there is no event being processed anymore. diff --git a/fastlane/metadata/android/en-US/changelogs/40104200.txt b/fastlane/metadata/android/en-US/changelogs/40104200.txt new file mode 100644 index 0000000000..61db61727a --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/40104200.txt @@ -0,0 +1,2 @@ +Main changes in this version: Various bug fixes and stability improvements. +Full changelog: https://github.com/vector-im/element-android/releases diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 276c5ac810..3829063836 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -56,7 +56,7 @@ android { // that the app's state is completely cleared between tests. testInstrumentationRunnerArguments clearPackageData: 'true' - buildConfigField "String", "SDK_VERSION", "\"1.4.19\"" + buildConfigField "String", "SDK_VERSION", "\"1.4.20\"" buildConfigField "String", "GIT_SDK_REVISION", "\"${gitRevision()}\"" buildConfigField "String", "GIT_SDK_REVISION_UNIX_DATE", "\"${gitRevisionUnixDate()}\"" diff --git a/vector/build.gradle b/vector/build.gradle index dbf8cfc33d..dea95b607a 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -31,7 +31,7 @@ ext.versionMinor = 4 // Note: even values are reserved for regular release, odd values for hotfix release. // When creating a hotfix, you should decrease the value, since the current value // is the value for the next regular release. -ext.versionPatch = 19 +ext.versionPatch = 20 static def getGitTimestamp() { def cmd = 'git show -s --format=%ct'