Add action for local rooms deletion
This commit is contained in:
parent
df3fd6f691
commit
8999b40c1a
@ -31,4 +31,5 @@ sealed class RoomListAction : VectorViewModelAction {
|
||||
data class LeaveRoom(val roomId: String) : RoomListAction()
|
||||
data class JoinSuggestedRoom(val roomId: String, val viaServers: List<String>?) : RoomListAction()
|
||||
data class ShowRoomDetails(val roomId: String, val viaServers: List<String>?) : RoomListAction()
|
||||
object DeleteAllLocalRoom : RoomListAction()
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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<RoomListViewModel, RoomListViewState> 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<String>) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ data class RoomListViewState(
|
||||
val asyncSuggestedRooms: Async<List<SpaceChildInfo>> = Uninitialized,
|
||||
val currentUserName: String? = null,
|
||||
val asyncSelectedSpace: Async<RoomSummary?> = Uninitialized,
|
||||
val localRoomIds: List<String> = emptyList()
|
||||
) : MavericksState {
|
||||
|
||||
constructor(args: RoomListParams) : this(displayMode = args.displayMode)
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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<String>) {
|
||||
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
|
||||
|
@ -27,5 +27,4 @@ data class HomeRoomListViewState(
|
||||
val state: StateView.State = StateView.State.Content,
|
||||
val headersData: RoomsHeadersData = RoomsHeadersData(),
|
||||
val roomsLivePagedList: LiveData<PagedList<RoomSummary>>? = null,
|
||||
val localRoomIds: List<String> = emptyList()
|
||||
) : MavericksState
|
||||
|
Loading…
x
Reference in New Issue
Block a user