Simple code

This commit is contained in:
Benoit Marty 2019-11-08 15:08:50 +01:00
parent a6fcc7dca6
commit f17564d743
3 changed files with 7 additions and 10 deletions

View File

@ -130,7 +130,7 @@ class PublicRoomsFragment @Inject constructor(
override fun onPublicRoomJoin(publicRoom: PublicRoom) { override fun onPublicRoomJoin(publicRoom: PublicRoom) {
Timber.v("PublicRoomJoinClicked: $publicRoom") Timber.v("PublicRoomJoinClicked: $publicRoom")
viewModel.handle(RoomDirectoryActions.JoinRoom(publicRoom)) viewModel.handle(RoomDirectoryActions.JoinRoom(publicRoom.roomId))
} }
override fun loadMore() { override fun loadMore() {

View File

@ -16,7 +16,6 @@
package im.vector.riotx.features.roomdirectory package im.vector.riotx.features.roomdirectory
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
import im.vector.matrix.android.api.session.room.model.thirdparty.RoomDirectoryData import im.vector.matrix.android.api.session.room.model.thirdparty.RoomDirectoryData
import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.platform.VectorViewModelAction
@ -24,5 +23,5 @@ sealed class RoomDirectoryActions : VectorViewModelAction {
data class SetRoomDirectoryData(val roomDirectoryData: RoomDirectoryData) : RoomDirectoryActions() data class SetRoomDirectoryData(val roomDirectoryData: RoomDirectoryData) : RoomDirectoryActions()
data class FilterWith(val filter: String) : RoomDirectoryActions() data class FilterWith(val filter: String) : RoomDirectoryActions()
object LoadMore : RoomDirectoryActions() object LoadMore : RoomDirectoryActions()
data class JoinRoom(val publicRoom: PublicRoom) : RoomDirectoryActions() data class JoinRoom(val roomId: String) : RoomDirectoryActions()
} }

View File

@ -202,9 +202,7 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
} }
private fun joinRoom(action: RoomDirectoryActions.JoinRoom) = withState { state -> private fun joinRoom(action: RoomDirectoryActions.JoinRoom) = withState { state ->
val roomId = action.publicRoom.roomId if (state.joiningRoomsIds.contains(action.roomId)) {
if (state.joiningRoomsIds.contains(roomId)) {
// Request already sent, should not happen // Request already sent, should not happen
Timber.w("Try to join an already joining room. Should not happen") Timber.w("Try to join an already joining room. Should not happen")
return@withState return@withState
@ -212,11 +210,11 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
setState { setState {
copy( copy(
joiningRoomsIds = joiningRoomsIds.toMutableSet().apply { add(roomId) } joiningRoomsIds = joiningRoomsIds.toMutableSet().apply { add(action.roomId) }
) )
} }
session.joinRoom(roomId, emptyList(), object : MatrixCallback<Unit> { session.joinRoom(action.roomId, emptyList(), object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) { override fun onSuccess(data: Unit) {
// We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data. // We do not update the joiningRoomsIds here, because, the room is not joined yet regarding the sync data.
// Instead, we wait for the room to be joined // Instead, we wait for the room to be joined
@ -228,8 +226,8 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
setState { setState {
copy( copy(
joiningRoomsIds = joiningRoomsIds.toMutableSet().apply { remove(roomId) }, joiningRoomsIds = joiningRoomsIds.toMutableSet().apply { remove(action.roomId) },
joiningErrorRoomsIds = joiningErrorRoomsIds.toMutableSet().apply { add(roomId) } joiningErrorRoomsIds = joiningErrorRoomsIds.toMutableSet().apply { add(action.roomId) }
) )
} }
} }