From 8a3e93ae9641e3e225c12a7eb30a7c8bfbb888d5 Mon Sep 17 00:00:00 2001 From: onurays Date: Thu, 13 Feb 2020 14:59:41 +0300 Subject: [PATCH] Do not ask for a reason if user wants to delete his own message. Fixes (#1003) --- .../features/home/room/detail/RoomDetailFragment.kt | 10 +++++++--- .../room/detail/timeline/action/EventSharedAction.kt | 2 +- .../detail/timeline/action/MessageActionsViewModel.kt | 2 +- vector/src/main/res/layout/dialog_delete_event.xml | 3 +-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 2fa2243060..cbda6ab13e 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -788,12 +788,15 @@ class RoomDetailFragment @Inject constructor( .show() } - private fun promptReasonToRedactEvent(eventId: String) { + private fun promptConfirmationToRedactEvent(eventId: String, askForReason: Boolean) { val layout = requireActivity().layoutInflater.inflate(R.layout.dialog_delete_event, null) val reasonCheckBox = layout.findViewById(R.id.deleteEventReasonCheck) val reasonTextInputLayout = layout.findViewById(R.id.deleteEventReasonTextInputLayout) val reasonInput = layout.findViewById(R.id.deleteEventReasonInput) + reasonCheckBox.isVisible = askForReason + reasonTextInputLayout.isVisible = askForReason + reasonCheckBox.setOnCheckedChangeListener { _, isChecked -> reasonTextInputLayout.isEnabled = isChecked } AlertDialog.Builder(requireActivity()) @@ -801,7 +804,8 @@ class RoomDetailFragment @Inject constructor( .setView(layout) .setPositiveButton(R.string.remove) { _, _ -> val reason = reasonInput.text.toString() - .takeIf { reasonCheckBox.isChecked } + .takeIf { askForReason } + ?.takeIf { reasonCheckBox.isChecked } ?.takeIf { it.isNotBlank() } roomDetailViewModel.handle(RoomDetailAction.RedactAction(eventId, reason)) } @@ -1121,7 +1125,7 @@ class RoomDetailFragment @Inject constructor( showSnackWithMessage(getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT) } is EventSharedAction.Redact -> { - promptReasonToRedactEvent(action.eventId) + promptConfirmationToRedactEvent(action.eventId, action.askForReason) } is EventSharedAction.Share -> { // TODO current data communication is too limited diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/EventSharedAction.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/EventSharedAction.kt index 8a8766c3ef..cba89d8481 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/EventSharedAction.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/EventSharedAction.kt @@ -55,7 +55,7 @@ sealed class EventSharedAction(@StringRes val titleRes: Int, data class Remove(val eventId: String) : EventSharedAction(R.string.remove, R.drawable.ic_trash, true) - data class Redact(val eventId: String) : + data class Redact(val eventId: String, val askForReason: Boolean) : EventSharedAction(R.string.message_action_item_redact, R.drawable.ic_delete, true) data class Cancel(val eventId: String) : diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt index 4b130e2103..5a52907bfa 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsViewModel.kt @@ -227,7 +227,7 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted } if (canRedact(timelineEvent, session.myUserId)) { - add(EventSharedAction.Redact(eventId)) + add(EventSharedAction.Redact(eventId, askForReason = informationData.senderId != session.myUserId)) } if (canCopy(msgType)) { diff --git a/vector/src/main/res/layout/dialog_delete_event.xml b/vector/src/main/res/layout/dialog_delete_event.xml index 8ca7a25113..08b0131f6a 100644 --- a/vector/src/main/res/layout/dialog_delete_event.xml +++ b/vector/src/main/res/layout/dialog_delete_event.xml @@ -43,8 +43,7 @@ + android:layout_height="wrap_content" />