Start DM - Handle the local rooms within the new AppLayout

This commit is contained in:
Florian Renaud 2022-09-16 09:44:23 +02:00
parent 3c68222fd7
commit 14d2aec506
3 changed files with 29 additions and 1 deletions

View File

@ -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) {

View File

@ -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<String>) {
viewModelScope.launch {
roomsIds.forEach {
session.roomService().deleteLocalRoom(it)
}
}
}
private fun handleSelectRoom(action: HomeRoomListAction.SelectRoom) = withState {
_viewEvents.post(HomeRoomListViewEvents.SelectRoom(action.roomSummary, false))
}

View File

@ -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<PagedList<RoomSummary>>? = null
val roomsLivePagedList: LiveData<PagedList<RoomSummary>>? = null,
val localRoomIds: List<String> = emptyList()
) : MavericksState