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 56eb3db236..f580a7f354 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 @@ -263,8 +263,8 @@ internal class RoomSummaryUpdater @Inject constructor( val graph = Graph() lookupMap - // focus only on spaces, as room are just leaf - .filter { it.key.roomType == RoomType.SPACE } + // focus only on joined spaces, as room are just leaf + .filter { it.key.roomType == RoomType.SPACE && it.key.membership == Membership.JOIN } .forEach { (sum, children) -> graph.getOrCreateNode(sum.roomId) children.forEach { @@ -294,7 +294,7 @@ internal class RoomSummaryUpdater @Inject constructor( // Timber.v("## SPACES: lookup map ${lookupMap.map { it.key.name to it.value.map { it.name } }.toMap()}") lookupMap.entries - .filter { it.key.roomType == RoomType.SPACE } + .filter { it.key.roomType == RoomType.SPACE && it.key.membership == Membership.JOIN } .forEach { entry -> val parent = RoomSummaryEntity.where(realm, entry.key.roomId).findFirst() if (parent != null) { diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceListAction.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListAction.kt index 8adfbae3bd..58812bd77e 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceListAction.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListAction.kt @@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary sealed class SpaceListAction : VectorViewModelAction { data class SelectSpace(val spaceSummary: RoomSummary) : SpaceListAction() + data class OpenSpaceInvite(val spaceSummary: RoomSummary) : SpaceListAction() data class LeaveSpace(val spaceSummary: RoomSummary) : SpaceListAction() data class ToggleExpand(val spaceSummary: RoomSummary) : SpaceListAction() object AddSpace : SpaceListAction() diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceListFragment.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListFragment.kt index bc7be74442..6455b18d13 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListFragment.kt @@ -80,6 +80,9 @@ class SpaceListFragment @Inject constructor( viewModel.handle(SpaceListAction.SelectSpace(spaceSummary)) } + override fun onSpaceInviteSelected(spaceSummary: RoomSummary) { + viewModel.handle(SpaceListAction.OpenSpaceInvite(spaceSummary)) + } override fun onSpaceSettings(spaceSummary: RoomSummary) { sharedActionViewModel.post(HomeActivitySharedAction.ShowSpaceSettings(spaceSummary.roomId)) } diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt index 14be8cd408..8b30687a12 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceSummaryController.kt @@ -82,8 +82,7 @@ class SpaceSummaryController @Inject constructor( id(it.roomId) matrixItem(it.toMatrixItem()) selected(false) - listener { callback?.onSpaceSelected(it) } -// lea { callback?.onSpaceSelected(it) } + listener { callback?.onSpaceInviteSelected(it) } } } genericFooterItem { @@ -173,6 +172,7 @@ class SpaceSummaryController @Inject constructor( interface Callback { fun onSpaceSelected(spaceSummary: RoomSummary) + fun onSpaceInviteSelected(spaceSummary: RoomSummary) fun onSpaceSettings(spaceSummary: RoomSummary) fun onToggleExpand(spaceSummary: RoomSummary) fun onAddSpaceSelected() diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpacesListViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/SpacesListViewModel.kt index 690e7970f1..1671be5ffb 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpacesListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpacesListViewModel.kt @@ -129,33 +129,23 @@ class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: Sp is SpaceListAction.LeaveSpace -> handleLeaveSpace(action) SpaceListAction.AddSpace -> handleAddSpace() is SpaceListAction.ToggleExpand -> handleToggleExpand(action) + is SpaceListAction.OpenSpaceInvite -> handleSelectSpaceInvite(action) } } // PRIVATE METHODS ***************************************************************************** private fun handleSelectSpace(action: SpaceListAction.SelectSpace) = withState { state -> - // get uptodate version of the space - val summary = session.spaceService().getSpaceSummaries(roomSummaryQueryParams { roomId = QueryStringValue.Equals(action.spaceSummary.roomId) }) - .firstOrNull() - if (summary?.membership == Membership.INVITE) { - _viewEvents.post(SpaceListViewEvents.OpenSpaceSummary(summary.roomId)) -// viewModelScope.launch(Dispatchers.IO) { -// tryOrNull { session.spaceService().peekSpace(action.spaceSummary.spaceId) }.let { -// Timber.d("PEEK RESULT/ $it") -// } -// } - } else { - if (state.selectedSpace?.roomId != action.spaceSummary.roomId) { -// state.selectedSpace?.let { -// selectedSpaceDataSource.post(Option.just(state.selectedSpace)) -// } - setState { copy(selectedSpace = action.spaceSummary) } - uiStateRepository.storeSelectedSpace(action.spaceSummary.roomId, session.sessionId) - } + if (state.selectedSpace?.roomId != action.spaceSummary.roomId) { + setState { copy(selectedSpace = action.spaceSummary) } + uiStateRepository.storeSelectedSpace(action.spaceSummary.roomId, session.sessionId) } } + private fun handleSelectSpaceInvite(action: SpaceListAction.OpenSpaceInvite) { + _viewEvents.post(SpaceListViewEvents.OpenSpaceSummary(action.spaceSummary.roomId)) + } + private fun handleToggleExpand(action: SpaceListAction.ToggleExpand) = withState { state -> val updatedToggleStates = state.expandedStates.toMutableMap().apply { this[action.spaceSummary.roomId] = !(this[action.spaceSummary.roomId] ?: false)