From 3c68222fd70c47b9f544707b7db9834a0cee2cb2 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Fri, 16 Sep 2022 09:23:14 +0200 Subject: [PATCH 1/7] Do not save local room into recent rooms --- .../internal/session/user/accountdata/UpdateBreadcrumbsTask.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateBreadcrumbsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateBreadcrumbsTask.kt index c4ea029cbb..a66a8540e7 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateBreadcrumbsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateBreadcrumbsTask.kt @@ -17,6 +17,7 @@ package org.matrix.android.sdk.internal.session.user.accountdata import com.zhuinden.monarchy.Monarchy +import org.matrix.android.sdk.api.session.room.model.localecho.RoomLocalEcho import org.matrix.android.sdk.internal.database.model.BreadcrumbsEntity import org.matrix.android.sdk.internal.database.query.get import org.matrix.android.sdk.internal.di.SessionDatabase @@ -41,6 +42,8 @@ internal class DefaultUpdateBreadcrumbsTask @Inject constructor( ) : UpdateBreadcrumbsTask { override suspend fun execute(params: UpdateBreadcrumbsTask.Params) { + // Do not add local rooms to the recent rooms list as they should not be known by the server + if (RoomLocalEcho.isLocalEchoId(params.newTopRoomId)) return val newBreadcrumbs = // Get the breadcrumbs entity, if any monarchy.fetchCopied { BreadcrumbsEntity.get(it) } From 14d2aec506793794a39566b1b2c62c363914a34e Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Fri, 16 Sep 2022 09:44:23 +0200 Subject: [PATCH 2/7] Start DM - Handle the local rooms within the new AppLayout --- .../room/list/home/HomeRoomListFragment.kt | 6 ++++++ .../room/list/home/HomeRoomListViewModel.kt | 21 +++++++++++++++++++ .../room/list/home/HomeRoomListViewState.kt | 3 ++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt index 88bbc6986f..debcc101cf 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt @@ -40,6 +40,7 @@ import im.vector.app.databinding.FragmentRoomListBinding import im.vector.app.features.analytics.plan.ViewRoom import im.vector.app.features.home.room.list.RoomListAnimator import im.vector.app.features.home.room.list.RoomListListener +import im.vector.app.features.home.room.list.RoomListViewState import im.vector.app.features.home.room.list.actions.RoomListQuickActionsBottomSheet import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedAction import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel @@ -98,6 +99,11 @@ class HomeRoomListFragment : is HomeRoomListViewEvents.Done -> Unit } } + + roomListViewModel.onEach(HomeRoomListViewState::localRoomIds) { + // Local rooms should not exist anymore when the room list is shown + roomListViewModel.deleteLocalRooms(it) + } } private fun handleQuickActions(quickAction: RoomListQuickActionsSharedAction) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt index e06815b5fd..c26783ab6c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt @@ -49,6 +49,7 @@ import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.launch import org.matrix.android.sdk.api.extensions.orFalse +import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomTagQueryFilter import org.matrix.android.sdk.api.query.toActiveSpaceOrNoFilter @@ -60,6 +61,7 @@ import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams import org.matrix.android.sdk.api.session.room.UpdatableLivePageResult import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomSummary +import org.matrix.android.sdk.api.session.room.model.localecho.RoomLocalEcho import org.matrix.android.sdk.api.session.room.model.tag.RoomTag import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams import org.matrix.android.sdk.api.session.room.state.isPublic @@ -103,6 +105,7 @@ class HomeRoomListViewModel @AssistedInject constructor( observeRecents() observeFilterTabs() observeRooms() + observeLocalRooms() } private fun observeInvites() { @@ -261,6 +264,16 @@ class HomeRoomListViewModel @AssistedInject constructor( }.launchIn(viewModelScope) } + private fun observeLocalRooms() { + session + .flow() + .liveRoomSummaries(roomSummaryQueryParams { + roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX) + }) + .map { page -> page.map { it.roomId } } + .setOnEach { copy(localRoomIds = it) } + } + private fun emitEmptyState() { viewModelScope.launch { val emptyState = getEmptyStateData(currentFilter, spaceStateHandler.getCurrentSpace()) @@ -349,6 +362,14 @@ class HomeRoomListViewModel @AssistedInject constructor( return session.getRoom(roomId)?.stateService()?.isPublic().orFalse() } + fun deleteLocalRooms(roomsIds: Iterable) { + viewModelScope.launch { + roomsIds.forEach { + session.roomService().deleteLocalRoom(it) + } + } + } + private fun handleSelectRoom(action: HomeRoomListAction.SelectRoom) = withState { _viewEvents.post(HomeRoomListViewEvents.SelectRoom(action.roomSummary, false)) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt index 8647054f3d..2c0b6a63be 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt @@ -26,5 +26,6 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary data class HomeRoomListViewState( val state: StateView.State = StateView.State.Content, val headersData: RoomsHeadersData = RoomsHeadersData(), - val roomsLivePagedList: LiveData>? = null + val roomsLivePagedList: LiveData>? = null, + val localRoomIds: List = emptyList() ) : MavericksState From c28271dd8b9118c6624a75c7ec24b33ca6270cf1 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Fri, 16 Sep 2022 10:06:07 +0200 Subject: [PATCH 3/7] Add changelog --- changelog.d/7153.wip | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7153.wip diff --git a/changelog.d/7153.wip b/changelog.d/7153.wip new file mode 100644 index 0000000000..fd12a4197b --- /dev/null +++ b/changelog.d/7153.wip @@ -0,0 +1 @@ +Create DM room only on first message - Handle the local rooms within the new AppLayout From df3fd6f69175982ed6f3bcb54b605c5f776d099e Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Fri, 16 Sep 2022 10:08:16 +0200 Subject: [PATCH 4/7] Remove unused import --- .../app/features/home/room/list/home/HomeRoomListFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt index debcc101cf..1826b58e26 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt @@ -40,7 +40,6 @@ import im.vector.app.databinding.FragmentRoomListBinding import im.vector.app.features.analytics.plan.ViewRoom import im.vector.app.features.home.room.list.RoomListAnimator import im.vector.app.features.home.room.list.RoomListListener -import im.vector.app.features.home.room.list.RoomListViewState import im.vector.app.features.home.room.list.actions.RoomListQuickActionsBottomSheet import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedAction import im.vector.app.features.home.room.list.actions.RoomListQuickActionsSharedActionViewModel From 8999b40c1af5f6a9e11868f2b1169c487007697c Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Mon, 19 Sep 2022 09:58:00 +0200 Subject: [PATCH 5/7] Add action for local rooms deletion --- .../features/home/room/list/RoomListAction.kt | 1 + .../home/room/list/RoomListFragment.kt | 11 ++++--- .../home/room/list/RoomListViewModel.kt | 32 ++++++++----------- .../home/room/list/RoomListViewState.kt | 1 - .../home/room/list/home/HomeRoomListAction.kt | 1 + .../room/list/home/HomeRoomListFragment.kt | 12 ++++--- .../room/list/home/HomeRoomListViewModel.kt | 32 ++++++++----------- .../room/list/home/HomeRoomListViewState.kt | 1 - 8 files changed, 42 insertions(+), 49 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListAction.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListAction.kt index e6b6b34503..aa982741f7 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListAction.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListAction.kt @@ -31,4 +31,5 @@ sealed class RoomListAction : VectorViewModelAction { data class LeaveRoom(val roomId: String) : RoomListAction() data class JoinSuggestedRoom(val roomId: String, val viaServers: List?) : RoomListAction() data class ShowRoomDetails(val roomId: String, val viaServers: List?) : RoomListAction() + object DeleteAllLocalRoom : RoomListAction() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt index 2c876273ea..9591048725 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListFragment.kt @@ -149,10 +149,13 @@ class RoomListFragment : (it.contentEpoxyController as? RoomSummaryPagedController)?.roomChangeMembershipStates = ms } } - roomListViewModel.onEach(RoomListViewState::localRoomIds) { - // Local rooms should not exist anymore when the room list is shown - roomListViewModel.deleteLocalRooms(it) - } + } + + override fun onStart() { + super.onStart() + + // Local rooms should not exist anymore when the room list is shown + roomListViewModel.handle(RoomListAction.DeleteAllLocalRoom) } private fun refreshCollapseStates() { diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt index 8283447a4d..74b55d435d 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewModel.kt @@ -97,7 +97,6 @@ class RoomListViewModel @AssistedInject constructor( init { observeMembershipChanges() - observeLocalRooms() spaceStateHandler.getSelectedSpaceFlow() .distinctUntilChanged() @@ -125,16 +124,6 @@ class RoomListViewModel @AssistedInject constructor( } } - private fun observeLocalRooms() { - session - .flow() - .liveRoomSummaries(roomSummaryQueryParams { - roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX) - }) - .map { page -> page.map { it.roomId } } - .setOnEach { copy(localRoomIds = it) } - } - companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() private val roomListSectionBuilder = RoomListSectionBuilder( @@ -166,6 +155,7 @@ class RoomListViewModel @AssistedInject constructor( is RoomListAction.ToggleSection -> handleToggleSection(action.section) is RoomListAction.JoinSuggestedRoom -> handleJoinSuggestedRoom(action) is RoomListAction.ShowRoomDetails -> handleShowRoomDetails(action) + RoomListAction.DeleteAllLocalRoom -> handleDeleteLocalRooms() } } @@ -173,14 +163,6 @@ class RoomListViewModel @AssistedInject constructor( return session.getRoom(roomId)?.stateService()?.isPublic().orFalse() } - fun deleteLocalRooms(roomsIds: Iterable) { - viewModelScope.launch { - roomsIds.forEach { - session.roomService().deleteLocalRoom(it) - } - } - } - // PRIVATE METHODS ***************************************************************************** private fun handleSelectRoom(action: RoomListAction.SelectRoom) = withState { @@ -338,4 +320,16 @@ class RoomListViewModel @AssistedInject constructor( _viewEvents.post(value) } } + + private fun handleDeleteLocalRooms() { + val localRoomIds = session.roomService() + .getRoomSummaries(roomSummaryQueryParams { roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX) }) + .map { it.roomId } + + viewModelScope.launch { + localRoomIds.forEach { + session.roomService().deleteLocalRoom(it) + } + } + } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewState.kt index 5f62cba948..d897225fd6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListViewState.kt @@ -31,7 +31,6 @@ data class RoomListViewState( val asyncSuggestedRooms: Async> = Uninitialized, val currentUserName: String? = null, val asyncSelectedSpace: Async = Uninitialized, - val localRoomIds: List = emptyList() ) : MavericksState { constructor(args: RoomListParams) : this(displayMode = args.displayMode) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListAction.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListAction.kt index b7ade559da..5760874812 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListAction.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListAction.kt @@ -27,4 +27,5 @@ sealed class HomeRoomListAction : VectorViewModelAction { data class ToggleTag(val roomId: String, val tag: String) : HomeRoomListAction() data class LeaveRoom(val roomId: String) : HomeRoomListAction() data class ChangeRoomFilter(val filter: HomeRoomFilter) : HomeRoomListAction() + object DeleteAllLocalRoom : HomeRoomListAction() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt index 1826b58e26..829634259a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListFragment.kt @@ -83,6 +83,13 @@ class HomeRoomListFragment : setupRecyclerView() } + override fun onStart() { + super.onStart() + + // Local rooms should not exist anymore when the room list is shown + roomListViewModel.handle(HomeRoomListAction.DeleteAllLocalRoom) + } + private fun setupObservers() { sharedQuickActionsViewModel = activityViewModelProvider[RoomListQuickActionsSharedActionViewModel::class.java] sharedQuickActionsViewModel @@ -98,11 +105,6 @@ class HomeRoomListFragment : is HomeRoomListViewEvents.Done -> Unit } } - - roomListViewModel.onEach(HomeRoomListViewState::localRoomIds) { - // Local rooms should not exist anymore when the room list is shown - roomListViewModel.deleteLocalRooms(it) - } } private fun handleQuickActions(quickAction: RoomListQuickActionsSharedAction) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt index c26783ab6c..35b2f02917 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt @@ -105,7 +105,6 @@ class HomeRoomListViewModel @AssistedInject constructor( observeRecents() observeFilterTabs() observeRooms() - observeLocalRooms() } private fun observeInvites() { @@ -264,16 +263,6 @@ class HomeRoomListViewModel @AssistedInject constructor( }.launchIn(viewModelScope) } - private fun observeLocalRooms() { - session - .flow() - .liveRoomSummaries(roomSummaryQueryParams { - roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX) - }) - .map { page -> page.map { it.roomId } } - .setOnEach { copy(localRoomIds = it) } - } - private fun emitEmptyState() { viewModelScope.launch { val emptyState = getEmptyStateData(currentFilter, spaceStateHandler.getCurrentSpace()) @@ -342,6 +331,7 @@ class HomeRoomListViewModel @AssistedInject constructor( is HomeRoomListAction.ChangeRoomNotificationState -> handleChangeNotificationMode(action) is HomeRoomListAction.ToggleTag -> handleToggleTag(action) is HomeRoomListAction.ChangeRoomFilter -> handleChangeRoomFilter(action.filter) + HomeRoomListAction.DeleteAllLocalRoom -> handleDeleteLocalRooms() } } @@ -362,14 +352,6 @@ class HomeRoomListViewModel @AssistedInject constructor( return session.getRoom(roomId)?.stateService()?.isPublic().orFalse() } - fun deleteLocalRooms(roomsIds: Iterable) { - viewModelScope.launch { - roomsIds.forEach { - session.roomService().deleteLocalRoom(it) - } - } - } - private fun handleSelectRoom(action: HomeRoomListAction.SelectRoom) = withState { _viewEvents.post(HomeRoomListViewEvents.SelectRoom(action.roomSummary, false)) } @@ -420,6 +402,18 @@ class HomeRoomListViewModel @AssistedInject constructor( } } + private fun handleDeleteLocalRooms() = withState { + val localRoomIds = session.roomService() + .getRoomSummaries(roomSummaryQueryParams { roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX) }) + .map { it.roomId } + + viewModelScope.launch { + localRoomIds.forEach { + session.roomService().deleteLocalRoom(it) + } + } + } + private fun String.otherTag(): String? { return when (this) { RoomTag.ROOM_TAG_FAVOURITE -> RoomTag.ROOM_TAG_LOW_PRIORITY diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt index 2c0b6a63be..95625bc4b9 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewState.kt @@ -27,5 +27,4 @@ data class HomeRoomListViewState( val state: StateView.State = StateView.State.Content, val headersData: RoomsHeadersData = RoomsHeadersData(), val roomsLivePagedList: LiveData>? = null, - val localRoomIds: List = emptyList() ) : MavericksState From 648498e2de4e8af16b8a576c576c3f6737771812 Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Mon, 19 Sep 2022 15:22:17 +0200 Subject: [PATCH 6/7] Move local room check from UpdateBreadcrumbsTask to RoomService --- .../android/sdk/internal/session/room/DefaultRoomService.kt | 6 +++++- .../session/user/accountdata/UpdateBreadcrumbsTask.kt | 3 --- 2 files changed, 5 insertions(+), 4 deletions(-) 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 989bcaee44..dd945716a1 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 @@ -33,6 +33,7 @@ import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.create.CreateRoomParams +import org.matrix.android.sdk.api.session.room.model.localecho.RoomLocalEcho import org.matrix.android.sdk.api.session.room.peeking.PeekResult import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams import org.matrix.android.sdk.api.session.room.summary.RoomAggregateNotificationCount @@ -173,7 +174,10 @@ internal class DefaultRoomService @Inject constructor( } override suspend fun onRoomDisplayed(roomId: String) { - updateBreadcrumbsTask.execute(UpdateBreadcrumbsTask.Params(roomId)) + // Do not add local rooms to the recent rooms list as they should not be known by the server + if (!RoomLocalEcho.isLocalEchoId(roomId)) { + updateBreadcrumbsTask.execute(UpdateBreadcrumbsTask.Params(roomId)) + } } override suspend fun joinRoom(roomIdOrAlias: String, reason: String?, viaServers: List) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateBreadcrumbsTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateBreadcrumbsTask.kt index a66a8540e7..c4ea029cbb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateBreadcrumbsTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/user/accountdata/UpdateBreadcrumbsTask.kt @@ -17,7 +17,6 @@ package org.matrix.android.sdk.internal.session.user.accountdata import com.zhuinden.monarchy.Monarchy -import org.matrix.android.sdk.api.session.room.model.localecho.RoomLocalEcho import org.matrix.android.sdk.internal.database.model.BreadcrumbsEntity import org.matrix.android.sdk.internal.database.query.get import org.matrix.android.sdk.internal.di.SessionDatabase @@ -42,8 +41,6 @@ internal class DefaultUpdateBreadcrumbsTask @Inject constructor( ) : UpdateBreadcrumbsTask { override suspend fun execute(params: UpdateBreadcrumbsTask.Params) { - // Do not add local rooms to the recent rooms list as they should not be known by the server - if (RoomLocalEcho.isLocalEchoId(params.newTopRoomId)) return val newBreadcrumbs = // Get the breadcrumbs entity, if any monarchy.fetchCopied { BreadcrumbsEntity.get(it) } From 5e504942cad4e8182ce3cd23e277e43692c9a36b Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Mon, 19 Sep 2022 15:49:44 +0200 Subject: [PATCH 7/7] Delete the local read receipts when deleting the local rooms --- .../internal/database/query/ReadReceiptEntityQueries.kt | 5 +++++ .../internal/session/room/delete/DeleteLocalRoomTask.kt | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadReceiptEntityQueries.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadReceiptEntityQueries.kt index b180c06e2c..170814d3f2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadReceiptEntityQueries.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/query/ReadReceiptEntityQueries.kt @@ -33,6 +33,11 @@ internal fun ReadReceiptEntity.Companion.whereUserId(realm: Realm, userId: Strin .equalTo(ReadReceiptEntityFields.USER_ID, userId) } +internal fun ReadReceiptEntity.Companion.whereRoomId(realm: Realm, roomId: String): RealmQuery { + return realm.where() + .equalTo(ReadReceiptEntityFields.ROOM_ID, roomId) +} + internal fun ReadReceiptEntity.Companion.createUnmanaged(roomId: String, eventId: String, userId: String, originServerTs: Double): ReadReceiptEntity { return ReadReceiptEntity().apply { this.primaryKey = "${roomId}_$userId" diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/delete/DeleteLocalRoomTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/delete/DeleteLocalRoomTask.kt index 49951d2da0..a60c7e6a27 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/delete/DeleteLocalRoomTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/delete/DeleteLocalRoomTask.kt @@ -22,12 +22,15 @@ import org.matrix.android.sdk.internal.database.model.ChunkEntity import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity import org.matrix.android.sdk.internal.database.model.EventEntity import org.matrix.android.sdk.internal.database.model.LocalRoomSummaryEntity +import org.matrix.android.sdk.internal.database.model.ReadReceiptEntity +import org.matrix.android.sdk.internal.database.model.ReadReceiptsSummaryEntity import org.matrix.android.sdk.internal.database.model.RoomEntity import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity import org.matrix.android.sdk.internal.database.model.TimelineEventEntity import org.matrix.android.sdk.internal.database.model.deleteOnCascade import org.matrix.android.sdk.internal.database.query.where +import org.matrix.android.sdk.internal.database.query.whereInRoom import org.matrix.android.sdk.internal.database.query.whereRoomId import org.matrix.android.sdk.internal.di.SessionDatabase import org.matrix.android.sdk.internal.session.room.delete.DeleteLocalRoomTask.Params @@ -50,6 +53,12 @@ internal class DefaultDeleteLocalRoomTask @Inject constructor( if (RoomLocalEcho.isLocalEchoId(roomId)) { monarchy.awaitTransaction { realm -> Timber.i("## DeleteLocalRoomTask - delete local room id $roomId") + ReadReceiptsSummaryEntity.whereInRoom(realm, roomId = roomId).findAll() + ?.also { Timber.i("## DeleteLocalRoomTask - ReadReceiptsSummaryEntity - delete ${it.size} entries") } + ?.deleteAllFromRealm() + ReadReceiptEntity.whereRoomId(realm, roomId = roomId).findAll() + ?.also { Timber.i("## DeleteLocalRoomTask - ReadReceiptEntity - delete ${it.size} entries") } + ?.deleteAllFromRealm() RoomMemberSummaryEntity.where(realm, roomId = roomId).findAll() ?.also { Timber.i("## DeleteLocalRoomTask - RoomMemberSummaryEntity - delete ${it.size} entries") } ?.deleteAllFromRealm()