Simple code
This commit is contained in:
parent
a6fcc7dca6
commit
f17564d743
|
@ -130,7 +130,7 @@ class PublicRoomsFragment @Inject constructor(
|
|||
|
||||
override fun onPublicRoomJoin(publicRoom: PublicRoom) {
|
||||
Timber.v("PublicRoomJoinClicked: $publicRoom")
|
||||
viewModel.handle(RoomDirectoryActions.JoinRoom(publicRoom))
|
||||
viewModel.handle(RoomDirectoryActions.JoinRoom(publicRoom.roomId))
|
||||
}
|
||||
|
||||
override fun loadMore() {
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
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.riotx.core.platform.VectorViewModelAction
|
||||
|
||||
|
@ -24,5 +23,5 @@ sealed class RoomDirectoryActions : VectorViewModelAction {
|
|||
data class SetRoomDirectoryData(val roomDirectoryData: RoomDirectoryData) : RoomDirectoryActions()
|
||||
data class FilterWith(val filter: String) : RoomDirectoryActions()
|
||||
object LoadMore : RoomDirectoryActions()
|
||||
data class JoinRoom(val publicRoom: PublicRoom) : RoomDirectoryActions()
|
||||
data class JoinRoom(val roomId: String) : RoomDirectoryActions()
|
||||
}
|
||||
|
|
|
@ -202,9 +202,7 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
}
|
||||
|
||||
private fun joinRoom(action: RoomDirectoryActions.JoinRoom) = withState { state ->
|
||||
val roomId = action.publicRoom.roomId
|
||||
|
||||
if (state.joiningRoomsIds.contains(roomId)) {
|
||||
if (state.joiningRoomsIds.contains(action.roomId)) {
|
||||
// Request already sent, should not happen
|
||||
Timber.w("Try to join an already joining room. Should not happen")
|
||||
return@withState
|
||||
|
@ -212,11 +210,11 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
|
||||
setState {
|
||||
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) {
|
||||
// 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
|
||||
|
@ -228,8 +226,8 @@ class RoomDirectoryViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
|
||||
setState {
|
||||
copy(
|
||||
joiningRoomsIds = joiningRoomsIds.toMutableSet().apply { remove(roomId) },
|
||||
joiningErrorRoomsIds = joiningErrorRoomsIds.toMutableSet().apply { add(roomId) }
|
||||
joiningRoomsIds = joiningRoomsIds.toMutableSet().apply { remove(action.roomId) },
|
||||
joiningErrorRoomsIds = joiningErrorRoomsIds.toMutableSet().apply { add(action.roomId) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue