Fix invited spaced filters rooms out of home + invite not working

This commit is contained in:
Valere 2021-04-20 14:30:51 +02:00
parent 19bb4c6162
commit aa74646ddf
5 changed files with 17 additions and 23 deletions

View File

@ -263,8 +263,8 @@ internal class RoomSummaryUpdater @Inject constructor(
val graph = Graph() val graph = Graph()
lookupMap lookupMap
// focus only on spaces, as room are just leaf // focus only on joined spaces, as room are just leaf
.filter { it.key.roomType == RoomType.SPACE } .filter { it.key.roomType == RoomType.SPACE && it.key.membership == Membership.JOIN }
.forEach { (sum, children) -> .forEach { (sum, children) ->
graph.getOrCreateNode(sum.roomId) graph.getOrCreateNode(sum.roomId)
children.forEach { 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()}") // Timber.v("## SPACES: lookup map ${lookupMap.map { it.key.name to it.value.map { it.name } }.toMap()}")
lookupMap.entries lookupMap.entries
.filter { it.key.roomType == RoomType.SPACE } .filter { it.key.roomType == RoomType.SPACE && it.key.membership == Membership.JOIN }
.forEach { entry -> .forEach { entry ->
val parent = RoomSummaryEntity.where(realm, entry.key.roomId).findFirst() val parent = RoomSummaryEntity.where(realm, entry.key.roomId).findFirst()
if (parent != null) { if (parent != null) {

View File

@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
sealed class SpaceListAction : VectorViewModelAction { sealed class SpaceListAction : VectorViewModelAction {
data class SelectSpace(val spaceSummary: RoomSummary) : SpaceListAction() data class SelectSpace(val spaceSummary: RoomSummary) : SpaceListAction()
data class OpenSpaceInvite(val spaceSummary: RoomSummary) : SpaceListAction()
data class LeaveSpace(val spaceSummary: RoomSummary) : SpaceListAction() data class LeaveSpace(val spaceSummary: RoomSummary) : SpaceListAction()
data class ToggleExpand(val spaceSummary: RoomSummary) : SpaceListAction() data class ToggleExpand(val spaceSummary: RoomSummary) : SpaceListAction()
object AddSpace : SpaceListAction() object AddSpace : SpaceListAction()

View File

@ -80,6 +80,9 @@ class SpaceListFragment @Inject constructor(
viewModel.handle(SpaceListAction.SelectSpace(spaceSummary)) viewModel.handle(SpaceListAction.SelectSpace(spaceSummary))
} }
override fun onSpaceInviteSelected(spaceSummary: RoomSummary) {
viewModel.handle(SpaceListAction.OpenSpaceInvite(spaceSummary))
}
override fun onSpaceSettings(spaceSummary: RoomSummary) { override fun onSpaceSettings(spaceSummary: RoomSummary) {
sharedActionViewModel.post(HomeActivitySharedAction.ShowSpaceSettings(spaceSummary.roomId)) sharedActionViewModel.post(HomeActivitySharedAction.ShowSpaceSettings(spaceSummary.roomId))
} }

View File

@ -82,8 +82,7 @@ class SpaceSummaryController @Inject constructor(
id(it.roomId) id(it.roomId)
matrixItem(it.toMatrixItem()) matrixItem(it.toMatrixItem())
selected(false) selected(false)
listener { callback?.onSpaceSelected(it) } listener { callback?.onSpaceInviteSelected(it) }
// lea { callback?.onSpaceSelected(it) }
} }
} }
genericFooterItem { genericFooterItem {
@ -173,6 +172,7 @@ class SpaceSummaryController @Inject constructor(
interface Callback { interface Callback {
fun onSpaceSelected(spaceSummary: RoomSummary) fun onSpaceSelected(spaceSummary: RoomSummary)
fun onSpaceInviteSelected(spaceSummary: RoomSummary)
fun onSpaceSettings(spaceSummary: RoomSummary) fun onSpaceSettings(spaceSummary: RoomSummary)
fun onToggleExpand(spaceSummary: RoomSummary) fun onToggleExpand(spaceSummary: RoomSummary)
fun onAddSpaceSelected() fun onAddSpaceSelected()

View File

@ -129,31 +129,21 @@ class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: Sp
is SpaceListAction.LeaveSpace -> handleLeaveSpace(action) is SpaceListAction.LeaveSpace -> handleLeaveSpace(action)
SpaceListAction.AddSpace -> handleAddSpace() SpaceListAction.AddSpace -> handleAddSpace()
is SpaceListAction.ToggleExpand -> handleToggleExpand(action) is SpaceListAction.ToggleExpand -> handleToggleExpand(action)
is SpaceListAction.OpenSpaceInvite -> handleSelectSpaceInvite(action)
} }
} }
// PRIVATE METHODS ***************************************************************************** // PRIVATE METHODS *****************************************************************************
private fun handleSelectSpace(action: SpaceListAction.SelectSpace) = withState { state -> 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) { if (state.selectedSpace?.roomId != action.spaceSummary.roomId) {
// state.selectedSpace?.let {
// selectedSpaceDataSource.post(Option.just(state.selectedSpace))
// }
setState { copy(selectedSpace = action.spaceSummary) } setState { copy(selectedSpace = action.spaceSummary) }
uiStateRepository.storeSelectedSpace(action.spaceSummary.roomId, session.sessionId) 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 -> private fun handleToggleExpand(action: SpaceListAction.ToggleExpand) = withState { state ->