Code review fixes.
This commit is contained in:
parent
fd135e1eeb
commit
030d6824e3
@ -157,6 +157,11 @@ data class Event(
|
|||||||
*/
|
*/
|
||||||
fun isRedacted() = unsignedData?.redactedEvent != null
|
fun isRedacted() = unsignedData?.redactedEvent != null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells if the event is redacted by the user himself.
|
||||||
|
*/
|
||||||
|
fun isRedactedBySameUser() = senderId == unsignedData?.redactedEvent?.senderId
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (javaClass != other?.javaClass) return false
|
if (javaClass != other?.javaClass) return false
|
||||||
|
@ -788,14 +788,14 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun promptConfirmationToRedactEvent(eventId: String, askForReason: Boolean) {
|
private fun promptConfirmationToRedactEvent(action: EventSharedAction.Redact) {
|
||||||
val layout = requireActivity().layoutInflater.inflate(R.layout.dialog_delete_event, null)
|
val layout = requireActivity().layoutInflater.inflate(R.layout.dialog_delete_event, null)
|
||||||
val reasonCheckBox = layout.findViewById<MaterialCheckBox>(R.id.deleteEventReasonCheck)
|
val reasonCheckBox = layout.findViewById<MaterialCheckBox>(R.id.deleteEventReasonCheck)
|
||||||
val reasonTextInputLayout = layout.findViewById<TextInputLayout>(R.id.deleteEventReasonTextInputLayout)
|
val reasonTextInputLayout = layout.findViewById<TextInputLayout>(R.id.deleteEventReasonTextInputLayout)
|
||||||
val reasonInput = layout.findViewById<TextInputEditText>(R.id.deleteEventReasonInput)
|
val reasonInput = layout.findViewById<TextInputEditText>(R.id.deleteEventReasonInput)
|
||||||
|
|
||||||
reasonCheckBox.isVisible = askForReason
|
reasonCheckBox.isVisible = action.askForReason
|
||||||
reasonTextInputLayout.isVisible = askForReason
|
reasonTextInputLayout.isVisible = action.askForReason
|
||||||
|
|
||||||
reasonCheckBox.setOnCheckedChangeListener { _, isChecked -> reasonTextInputLayout.isEnabled = isChecked }
|
reasonCheckBox.setOnCheckedChangeListener { _, isChecked -> reasonTextInputLayout.isEnabled = isChecked }
|
||||||
|
|
||||||
@ -804,10 +804,10 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
.setView(layout)
|
.setView(layout)
|
||||||
.setPositiveButton(R.string.remove) { _, _ ->
|
.setPositiveButton(R.string.remove) { _, _ ->
|
||||||
val reason = reasonInput.text.toString()
|
val reason = reasonInput.text.toString()
|
||||||
.takeIf { askForReason }
|
.takeIf { action.askForReason }
|
||||||
?.takeIf { reasonCheckBox.isChecked }
|
?.takeIf { reasonCheckBox.isChecked }
|
||||||
?.takeIf { it.isNotBlank() }
|
?.takeIf { it.isNotBlank() }
|
||||||
roomDetailViewModel.handle(RoomDetailAction.RedactAction(eventId, reason))
|
roomDetailViewModel.handle(RoomDetailAction.RedactAction(action.eventId, reason))
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
@ -1125,7 +1125,7 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
showSnackWithMessage(getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
|
showSnackWithMessage(getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
|
||||||
}
|
}
|
||||||
is EventSharedAction.Redact -> {
|
is EventSharedAction.Redact -> {
|
||||||
promptConfirmationToRedactEvent(action.eventId, action.askForReason)
|
promptConfirmationToRedactEvent(action)
|
||||||
}
|
}
|
||||||
is EventSharedAction.Share -> {
|
is EventSharedAction.Share -> {
|
||||||
// TODO current data communication is too limited
|
// TODO current data communication is too limited
|
||||||
|
@ -168,27 +168,25 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun computeMessageBody(timelineEvent: TimelineEvent): CharSequence {
|
private fun computeMessageBody(timelineEvent: TimelineEvent): CharSequence {
|
||||||
|
if (timelineEvent.root.isRedacted()) {
|
||||||
|
return getRedactionReason(timelineEvent)
|
||||||
|
}
|
||||||
|
|
||||||
return when (timelineEvent.root.getClearType()) {
|
return when (timelineEvent.root.getClearType()) {
|
||||||
EventType.MESSAGE,
|
EventType.MESSAGE,
|
||||||
EventType.ENCRYPTED,
|
|
||||||
EventType.STICKER -> {
|
EventType.STICKER -> {
|
||||||
when (timelineEvent.root.isRedacted()) {
|
val messageContent: MessageContent? = timelineEvent.getLastMessageContent()
|
||||||
true -> getRedactionReason(timelineEvent)
|
if (messageContent is MessageTextContent && messageContent.format == MessageFormat.FORMAT_MATRIX_HTML) {
|
||||||
false -> {
|
val html = messageContent.formattedBody
|
||||||
val messageContent: MessageContent? = timelineEvent.getLastMessageContent()
|
?.takeIf { it.isNotBlank() }
|
||||||
if (messageContent is MessageTextContent && messageContent.format == MessageFormat.FORMAT_MATRIX_HTML) {
|
?.let { htmlCompressor.compress(it) }
|
||||||
val html = messageContent.formattedBody
|
?: messageContent.body
|
||||||
?.takeIf { it.isNotBlank() }
|
|
||||||
?.let { htmlCompressor.compress(it) }
|
|
||||||
?: messageContent.body
|
|
||||||
|
|
||||||
eventHtmlRenderer.get().render(html)
|
eventHtmlRenderer.get().render(html)
|
||||||
} else if (messageContent is MessageVerificationRequestContent) {
|
} else if (messageContent is MessageVerificationRequestContent) {
|
||||||
stringProvider.getString(R.string.verification_request)
|
stringProvider.getString(R.string.verification_request)
|
||||||
} else {
|
} else {
|
||||||
messageContent?.body
|
messageContent?.body
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EventType.STATE_ROOM_NAME,
|
EventType.STATE_ROOM_NAME,
|
||||||
@ -206,26 +204,30 @@ class MessageActionsViewModel @AssistedInject constructor(@Assisted
|
|||||||
} ?: ""
|
} ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getRedactionReason(timelineEvent: TimelineEvent) =
|
private fun getRedactionReason(timelineEvent: TimelineEvent): String {
|
||||||
(timelineEvent
|
return (timelineEvent
|
||||||
.root
|
.root
|
||||||
.unsignedData
|
.unsignedData
|
||||||
?.redactedEvent
|
?.redactedEvent
|
||||||
?.content
|
?.content
|
||||||
?.get("reason") as? String)
|
?.get("reason") as? String)
|
||||||
?.takeIf { it.isNotBlank() }
|
?.takeIf { it.isNotBlank() }
|
||||||
?.let { reason ->
|
.let { reason ->
|
||||||
when (timelineEvent.root.senderId == timelineEvent.root.unsignedData?.redactedEvent?.senderId) {
|
if (reason == null) {
|
||||||
true -> stringProvider.getString(R.string.event_redacted_by_user_reason_with_reason, reason)
|
if (timelineEvent.root.isRedactedBySameUser()) {
|
||||||
false -> stringProvider.getString(R.string.event_redacted_by_admin_reason_with_reason, reason)
|
stringProvider.getString(R.string.event_redacted_by_user_reason)
|
||||||
}
|
} else {
|
||||||
}
|
stringProvider.getString(R.string.event_redacted_by_admin_reason)
|
||||||
?: run {
|
}
|
||||||
when (timelineEvent.root.senderId == timelineEvent.root.unsignedData?.redactedEvent?.senderId) {
|
} else {
|
||||||
true -> stringProvider.getString(R.string.event_redacted_by_user_reason)
|
if (timelineEvent.root.isRedactedBySameUser()) {
|
||||||
false -> stringProvider.getString(R.string.event_redacted_by_admin_reason)
|
stringProvider.getString(R.string.event_redacted_by_user_reason_with_reason, reason)
|
||||||
|
} else {
|
||||||
|
stringProvider.getString(R.string.event_redacted_by_admin_reason_with_reason, reason)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun actionsForEvent(timelineEvent: TimelineEvent): List<EventSharedAction> {
|
private fun actionsForEvent(timelineEvent: TimelineEvent): List<EventSharedAction> {
|
||||||
val messageContent: MessageContent? = timelineEvent.annotations?.editSummary?.aggregatedContent.toModel()
|
val messageContent: MessageContent? = timelineEvent.annotations?.editSummary?.aggregatedContent.toModel()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user