Spaces | Personal spaces add DM - Web Parity #3271

This commit is contained in:
Valere 2021-05-19 11:19:13 +02:00
parent abf7e275a7
commit ae5a5ec92b
4 changed files with 47 additions and 6 deletions

View file

@ -344,10 +344,9 @@ internal class RoomSummaryUpdater @Inject constructor(
if (it != null) addAll(it)
}
}.distinct()
if (flattenRelated.isEmpty()) {
dmRoom.flattenParentIds = null
} else {
dmRoom.flattenParentIds = "|${flattenRelated.joinToString("|")}|"
if (flattenRelated.isNotEmpty()) {
// we keep real m.child/m.parent relations and add the one for common memberships
dmRoom.flattenParentIds += "|${flattenRelated.joinToString("|")}|"
}
// Timber.v("## SPACES: flatten of ${dmRoom.otherMemberIds.joinToString(",")} is ${dmRoom.flattenParentIds}")
}

View file

@ -28,6 +28,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.jakewharton.rxbinding3.appcompat.queryTextChanges
import im.vector.app.R
import im.vector.app.core.extensions.cleanup
@ -42,6 +43,7 @@ import javax.inject.Inject
class SpaceAddRoomFragment @Inject constructor(
private val spaceEpoxyController: AddRoomListController,
private val roomEpoxyController: AddRoomListController,
private val dmEpoxyController: AddRoomListController,
private val viewModelFactory: SpaceAddRoomsViewModel.Factory
) : VectorBaseFragment<FragmentSpaceAddRoomsBinding>(),
OnBackPressed, AddRoomListController.Listener, SpaceAddRoomsViewModel.Factory {
@ -84,6 +86,7 @@ class SpaceAddRoomFragment @Inject constructor(
viewModel.selectionListLiveData.observe(viewLifecycleOwner) {
spaceEpoxyController.selectedItems = it
roomEpoxyController.selectedItems = it
dmEpoxyController.selectedItems = it
saveNeeded = it.values.any { it }
invalidateOptionsMenu()
}
@ -95,6 +98,7 @@ class SpaceAddRoomFragment @Inject constructor(
viewModel.selectSubscribe(this, SpaceAddRoomsState::ignoreRooms) {
spaceEpoxyController.ignoreRooms = it
roomEpoxyController.ignoreRooms = it
dmEpoxyController.ignoreRooms = it
}.disposeOnDestroyView()
viewModel.selectSubscribe(this, SpaceAddRoomsState::isSaving) {
@ -149,6 +153,7 @@ class SpaceAddRoomFragment @Inject constructor(
views.roomList.cleanup()
spaceEpoxyController.listener = null
roomEpoxyController.listener = null
dmEpoxyController.listener = null
super.onDestroyView()
}
@ -181,6 +186,21 @@ class SpaceAddRoomFragment @Inject constructor(
concatAdapter.addAdapter(roomEpoxyController.adapter)
concatAdapter.addAdapter(spaceEpoxyController.adapter)
val shouldShowDm = withState(viewModel) { it.shouldShowDMs }
if (shouldShowDm) {
viewModel.updatableDMLivePageResult.liveBoundaries.observe(viewLifecycleOwner) {
dmEpoxyController.boundaryChange(it)
}
viewModel.updatableDMLivePageResult.livePagedList.observe(viewLifecycleOwner) {
dmEpoxyController.totalSize = it.size
dmEpoxyController.submitList(it)
}
dmEpoxyController.sectionName = getString(R.string.direct_chats_header)
dmEpoxyController.listener = this
concatAdapter.addAdapter(dmEpoxyController.adapter)
}
views.roomList.adapter = concatAdapter
}

View file

@ -26,7 +26,8 @@ data class SpaceAddRoomsState(
val currentFilter: String = "",
val spaceName: String = "",
val ignoreRooms: List<String> = emptyList(),
val isSaving: Async<List<String>> = Uninitialized
val isSaving: Async<List<String>> = Uninitialized,
val shouldShowDMs : Boolean = false
// val selectionList: Map<String, Boolean> = emptyMap()
) : MvRxState {
constructor(args: SpaceManageArgs) : this(

View file

@ -98,6 +98,26 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
)
}
val updatableDMLivePageResult: UpdatableLivePageResult by lazy {
session.getFilteredPagedRoomSummariesLive(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.excludeType = listOf(RoomType.SPACE)
this.includeType = null
this.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
this.activeSpaceFilter = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
},
pagedListConfig = PagedList.Config.Builder()
.setPageSize(10)
.setInitialLoadSizeHint(20)
.setEnablePlaceholders(true)
.setPrefetchDistance(10)
.build(),
sortOrder = RoomSortOrder.NAME
)
}
private val selectionList = mutableMapOf<String, Boolean>()
val selectionListLiveData = MutableLiveData<Map<String, Boolean>>()
@ -106,7 +126,8 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
setState {
copy(
spaceName = spaceSummary?.displayName ?: "",
ignoreRooms = (spaceSummary?.flattenParentIds ?: emptyList()) + listOf(initialState.spaceId)
ignoreRooms = (spaceSummary?.flattenParentIds ?: emptyList()) + listOf(initialState.spaceId),
shouldShowDMs = spaceSummary?.isPublic == false
)
}
}