From d758d5c270101fe3a7a5ec044a522996136eb190 Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 8 Sep 2021 16:44:29 +0200 Subject: [PATCH] Fix / Kick user dialog for spaces talks about rooms --- changelog.d/3956.bugfix | 1 + .../RoomMemberProfileController.kt | 32 ++++++++++-------- .../RoomMemberProfileFragment.kt | 33 ++++++++++--------- .../RoomMemberProfileViewModel.kt | 4 ++- .../RoomMemberProfileViewState.kt | 1 + vector/src/main/res/values/strings.xml | 3 ++ 6 files changed, 44 insertions(+), 30 deletions(-) create mode 100644 changelog.d/3956.bugfix diff --git a/changelog.d/3956.bugfix b/changelog.d/3956.bugfix new file mode 100644 index 0000000000..adaeb0c684 --- /dev/null +++ b/changelog.d/3956.bugfix @@ -0,0 +1 @@ + Kick user dialog for spaces talks about rooms \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileController.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileController.kt index 9ea9f69383..08eab292a8 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileController.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileController.kt @@ -45,8 +45,8 @@ class RoomMemberProfileController @Inject constructor( fun onJumpToReadReceiptClicked() fun onMentionClicked() fun onEditPowerLevel(currentRole: Role) - fun onKickClicked() - fun onBanClicked(isUserBanned: Boolean) + fun onKickClicked(isSpace: Boolean) + fun onBanClicked(isSpace: Boolean, isUserBanned: Boolean) fun onCancelInviteClicked() fun onInviteClicked() } @@ -85,7 +85,9 @@ class RoomMemberProfileController @Inject constructor( } private fun buildRoomMemberActions(state: RoomMemberProfileViewState) { - buildSecuritySection(state) + if (!state.isSpace) { + buildSecuritySection(state) + } buildMoreSection(state) buildAdminSection(state) } @@ -181,7 +183,7 @@ class RoomMemberProfileController @Inject constructor( action = { callback?.onOpenDmClicked() } ) - if (state.hasReadReceipt) { + if (!state.isSpace && state.hasReadReceipt) { buildProfileAction( id = "read_receipt", editable = false, @@ -191,16 +193,18 @@ class RoomMemberProfileController @Inject constructor( } val ignoreActionTitle = state.buildIgnoreActionTitle() - - buildProfileAction( - id = "mention", - title = stringProvider.getString(R.string.room_participants_action_mention), - editable = false, - divider = ignoreActionTitle != null, - action = { callback?.onMentionClicked() } - ) + if (!state.isSpace) { + buildProfileAction( + id = "mention", + title = stringProvider.getString(R.string.room_participants_action_mention), + editable = false, + divider = ignoreActionTitle != null, + action = { callback?.onMentionClicked() } + ) + } val canInvite = state.actionPermissions.canInvite + if (canInvite && (membership == Membership.LEAVE || membership == Membership.KNOCK)) { buildProfileAction( id = "invite", @@ -261,7 +265,7 @@ class RoomMemberProfileController @Inject constructor( divider = canBan, destructive = true, title = stringProvider.getString(R.string.room_participants_action_kick), - action = { callback?.onKickClicked() } + action = { callback?.onKickClicked(state.isSpace) } ) } Membership.INVITE -> { @@ -288,7 +292,7 @@ class RoomMemberProfileController @Inject constructor( editable = false, destructive = true, title = banActionTitle, - action = { callback?.onBanClicked(membership == Membership.BAN) } + action = { callback?.onBanClicked(state.isSpace, membership == Membership.BAN) } ) } } diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt index 0adc1531c9..d8b4f249da 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileFragment.kt @@ -305,16 +305,16 @@ class RoomMemberProfileFragment @Inject constructor( val views = DialogShareQrCodeBinding.bind(view) views.itemShareQrCodeImage.setData(permalink) MaterialAlertDialogBuilder(requireContext()) - .setView(view) - .setNeutralButton(R.string.ok, null) - .setPositiveButton(R.string.share_by_text) { _, _ -> - startSharePlainTextIntent( - fragment = this, - activityResultLauncher = null, - chooserTitle = null, - text = permalink - ) - }.show() + .setView(view) + .setNeutralButton(R.string.ok, null) + .setPositiveButton(R.string.share_by_text) { _, _ -> + startSharePlainTextIntent( + fragment = this, + activityResultLauncher = null, + chooserTitle = null, + text = permalink + ) + }.show() } private fun onAvatarClicked(view: View, userMatrixItem: MatrixItem) { @@ -327,12 +327,13 @@ class RoomMemberProfileFragment @Inject constructor( } } - override fun onKickClicked() { + override fun onKickClicked(isSpace: Boolean) { ConfirmationDialogBuilder .show( activity = requireActivity(), askForReason = true, - confirmationRes = R.string.room_participants_kick_prompt_msg, + confirmationRes = if (isSpace) R.string.space_participants_kick_prompt_msg + else R.string.room_participants_kick_prompt_msg, positiveRes = R.string.room_participants_action_kick, reasonHintRes = R.string.room_participants_kick_reason, titleRes = R.string.room_participants_kick_title @@ -341,16 +342,18 @@ class RoomMemberProfileFragment @Inject constructor( } } - override fun onBanClicked(isUserBanned: Boolean) { + override fun onBanClicked(isSpace: Boolean, isUserBanned: Boolean) { val titleRes: Int val positiveButtonRes: Int val confirmationRes: Int if (isUserBanned) { - confirmationRes = R.string.room_participants_unban_prompt_msg + confirmationRes = if (isSpace) R.string.space_participants_unban_prompt_msg + else R.string.room_participants_unban_prompt_msg titleRes = R.string.room_participants_unban_title positiveButtonRes = R.string.room_participants_action_unban } else { - confirmationRes = R.string.room_participants_ban_prompt_msg + confirmationRes = if (isSpace) R.string.space_participants_ban_prompt_msg + else R.string.room_participants_ban_prompt_msg titleRes = R.string.room_participants_ban_title positiveButtonRes = R.string.room_participants_action_ban } diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt index 6978a24747..4b57bdc6aa 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt @@ -48,6 +48,7 @@ import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.PowerLevelsContent import org.matrix.android.sdk.api.session.room.model.RoomSummary +import org.matrix.android.sdk.api.session.room.model.RoomType import org.matrix.android.sdk.api.session.room.powerlevels.PowerLevelsHelper import org.matrix.android.sdk.api.session.room.powerlevels.Role import org.matrix.android.sdk.api.util.MatrixItem @@ -86,7 +87,8 @@ class RoomMemberProfileViewModel @AssistedInject constructor(@Assisted private v copy( isMine = session.myUserId == this.userId, userMatrixItem = room?.getRoomMember(initialState.userId)?.toMatrixItem()?.let { Success(it) } ?: Uninitialized, - hasReadReceipt = room?.getUserReadReceipt(initialState.userId) != null + hasReadReceipt = room?.getUserReadReceipt(initialState.userId) != null, + isSpace = room?.roomSummary()?.roomType == RoomType.SPACE ) } observeIgnoredState() diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewState.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewState.kt index f943a5cf08..5c2751f0dc 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewState.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewState.kt @@ -28,6 +28,7 @@ import org.matrix.android.sdk.api.util.MatrixItem data class RoomMemberProfileViewState( val userId: String, val roomId: String?, + val isSpace: Boolean = false, val showAsMember: Boolean = false, val isMine: Boolean = false, val isIgnored: Async = Uninitialized, diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 9eb51b507f..5f735a3a32 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -903,11 +903,14 @@ Kick user Reason to kick kicking user will remove them from this room.\n\nTo prevent them from joining again, you should ban them instead. + kicking user will remove them from this space.\n\nTo prevent them from joining again, you should ban them instead. Ban user Reason to ban Unban user Banning user will kick them from this room and prevent them from joining again. + Banning user will kick them from this space and prevent them from joining again. Unbanning user will allow them to join the room again. + Unbanning user will allow them to join the space again. Reason