From 14d2aec506793794a39566b1b2c62c363914a34e Mon Sep 17 00:00:00 2001 From: Florian Renaud Date: Fri, 16 Sep 2022 09:44:23 +0200 Subject: [PATCH] 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