diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt index cac0d715f5..d488fdfc2a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt @@ -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}") } diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomFragment.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomFragment.kt index 203098d32b..37a1a4f4d1 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomFragment.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomFragment.kt @@ -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(), 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 } diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsState.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsState.kt index 6ce3468fe1..2d9113ae68 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsState.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsState.kt @@ -26,7 +26,8 @@ data class SpaceAddRoomsState( val currentFilter: String = "", val spaceName: String = "", val ignoreRooms: List = emptyList(), - val isSaving: Async> = Uninitialized + val isSaving: Async> = Uninitialized, + val shouldShowDMs : Boolean = false // val selectionList: Map = emptyMap() ) : MvRxState { constructor(args: SpaceManageArgs) : this( diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt index 55e65eb171..35c415b087 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceAddRoomsViewModel.kt @@ -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() val selectionListLiveData = MutableLiveData>() @@ -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 ) } }