diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt index 512a96bf61..5ad74f8663 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/RoomProfileViewModel.kt @@ -19,7 +19,6 @@ package im.vector.riotx.features.roomprofile import com.airbnb.mvrx.FragmentViewModelContext import com.airbnb.mvrx.MvRxViewModelFactory -import com.airbnb.mvrx.Success import com.airbnb.mvrx.ViewModelContext import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject @@ -77,20 +76,17 @@ class RoomProfileViewModel @AssistedInject constructor(@Assisted private val ini .subscribe { val powerLevelsHelper = PowerLevelsHelper(it) setState { - copy(canChangeAvatar = powerLevelsHelper.isUserAllowedToSend(session.myUserId, true, EventType.STATE_ROOM_AVATAR)) + copy(canChangeAvatar = powerLevelsHelper.isUserAllowedToSend(session.myUserId, true, EventType.STATE_ROOM_AVATAR)) } } .disposeOnClear() rxRoom.liveRoomMembers(roomMemberQueryParams { memberships = listOf(Membership.BAN) }) - .subscribe { - setState { - copy( - bannedMembership = Success(it) - ) - } + .execute { + copy( + bannedMembership = it + ) } - .disposeOnClear() } override fun handle(action: RoomProfileAction) = when (action) { diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedListMemberAction.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedListMemberAction.kt new file mode 100644 index 0000000000..081af556d7 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedListMemberAction.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.roomprofile.banned + +import im.vector.matrix.android.api.session.room.model.RoomMemberSummary +import im.vector.riotx.core.platform.VectorViewModelAction + +sealed class RoomBannedListMemberAction : VectorViewModelAction { + data class QueryInfo(val roomMemberSummary: RoomMemberSummary) : RoomBannedListMemberAction() + data class UnBanUser(val roomMemberSummary: RoomMemberSummary) : RoomBannedListMemberAction() +} diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedMemberListViewState.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedMemberListViewState.kt new file mode 100644 index 0000000000..5b3d4e0826 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedMemberListViewState.kt @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.roomprofile.banned + +import com.airbnb.mvrx.Async +import com.airbnb.mvrx.MvRxState +import com.airbnb.mvrx.Uninitialized +import im.vector.matrix.android.api.session.room.model.RoomMemberSummary +import im.vector.matrix.android.api.session.room.model.RoomSummary +import im.vector.riotx.features.roomprofile.RoomProfileArgs + +data class RoomBannedMemberListViewState( + val roomId: String, + val roomSummary: Async = Uninitialized, + val bannedMemberSummaries: Async> = Uninitialized, + val onGoingModerationAction: List = emptyList(), + val canUserBan: Boolean = false +) : MvRxState { + + constructor(args: RoomProfileArgs) : this(roomId = args.roomId) +} diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedMemberViewModel.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedMemberViewModel.kt index a4e21f8eed..35f5589e9f 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedMemberViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedMemberViewModel.kt @@ -17,11 +17,8 @@ package im.vector.riotx.features.roomprofile.banned import androidx.lifecycle.viewModelScope -import com.airbnb.mvrx.Async import com.airbnb.mvrx.FragmentViewModelContext -import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.MvRxViewModelFactory -import com.airbnb.mvrx.Uninitialized import com.airbnb.mvrx.ViewModelContext import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject @@ -33,42 +30,17 @@ import im.vector.matrix.android.api.session.room.members.roomMemberQueryParams import im.vector.matrix.android.api.session.room.model.Membership import im.vector.matrix.android.api.session.room.model.RoomMemberContent import im.vector.matrix.android.api.session.room.model.RoomMemberSummary -import im.vector.matrix.android.api.session.room.model.RoomSummary import im.vector.matrix.android.api.session.room.powerlevels.PowerLevelsHelper import im.vector.matrix.android.internal.util.awaitCallback import im.vector.matrix.rx.rx import im.vector.matrix.rx.unwrap import im.vector.riotx.R -import im.vector.riotx.core.platform.VectorViewEvents import im.vector.riotx.core.platform.VectorViewModel -import im.vector.riotx.core.platform.VectorViewModelAction import im.vector.riotx.core.resources.StringProvider import im.vector.riotx.features.powerlevel.PowerLevelsObservableFactory -import im.vector.riotx.features.roomprofile.RoomProfileArgs import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -data class RoomBannedMemberListViewState( - val roomId: String, - val roomSummary: Async = Uninitialized, - val bannedMemberSummaries: Async> = Uninitialized, - val onGoingModerationAction: List = emptyList(), - val canUserBan: Boolean = false -) : MvRxState { - - constructor(args: RoomProfileArgs) : this(roomId = args.roomId) -} - -sealed class RoomBannedListMemberAction : VectorViewModelAction { - data class QueryInfo(val roomMemberSummary: RoomMemberSummary) : RoomBannedListMemberAction() - data class UnBanUser(val roomMemberSummary: RoomMemberSummary) : RoomBannedListMemberAction() -} - -sealed class RoomBannedViewEvents : VectorViewEvents { - data class ShowBannedInfo(val bannedByUserId: String, val banReason: String, val roomMemberSummary: RoomMemberSummary) : RoomBannedViewEvents() - data class ToastError(val info: String) : RoomBannedViewEvents() -} - class RoomBannedListMemberViewModel @AssistedInject constructor(@Assisted initialState: RoomBannedMemberListViewState, private val stringProvider: StringProvider, private val session: Session) diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedViewEvents.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedViewEvents.kt new file mode 100644 index 0000000000..69e422b022 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/banned/RoomBannedViewEvents.kt @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.roomprofile.banned + +import im.vector.matrix.android.api.session.room.model.RoomMemberSummary +import im.vector.riotx.core.platform.VectorViewEvents + +sealed class RoomBannedViewEvents : VectorViewEvents { + data class ShowBannedInfo(val bannedByUserId: String, val banReason: String, val roomMemberSummary: RoomMemberSummary) : RoomBannedViewEvents() + data class ToastError(val info: String) : RoomBannedViewEvents() +}