From f17564d743819e6c87b743dd92d9f23407ededa2 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 8 Nov 2019 15:08:50 +0100 Subject: [PATCH] Simple code --- .../features/roomdirectory/PublicRoomsFragment.kt | 2 +- .../features/roomdirectory/RoomDirectoryActions.kt | 3 +-- .../features/roomdirectory/RoomDirectoryViewModel.kt | 12 +++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/PublicRoomsFragment.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/PublicRoomsFragment.kt index b0198b39c4..ea46671e12 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomdirectory/PublicRoomsFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/PublicRoomsFragment.kt @@ -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() { diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryActions.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryActions.kt index 198426bc1d..0bb6658f2b 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryActions.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryActions.kt @@ -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() } diff --git a/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryViewModel.kt b/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryViewModel.kt index d092453ba8..085d5dfe5f 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomdirectory/RoomDirectoryViewModel.kt @@ -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 { + session.joinRoom(action.roomId, emptyList(), object : MatrixCallback { 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) } ) } }