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()
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) {

View File

@ -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()

View File

@ -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))
}

View File

@ -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()

View File

@ -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)