From 9d0c50907c983fb1a686fb73a4b9c1e445af144b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 4 Jul 2019 12:39:59 +0200 Subject: [PATCH 1/2] Fix issue when quoting event in e2e rooms (Fixes #295) --- .../api/session/room/send/SendService.kt | 2 +- .../session/room/send/DefaultSendService.kt | 32 +++++++++---------- .../home/room/detail/RoomDetailViewModel.kt | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/send/SendService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/send/SendService.kt index 875ac75b64..94abd5d31d 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/send/SendService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/send/SendService.kt @@ -42,7 +42,7 @@ interface SendService { * @param formattedText The formatted body using MessageType#FORMAT_MATRIX_HTML * @return a [Cancelable] */ - fun sendFormattedTextMessage(text: String,formattedText: String): Cancelable + fun sendFormattedTextMessage(text: String, formattedText: String): Cancelable /** * Method to send a media asynchronously. diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt index 27e9c62e00..fc4bf8c468 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/DefaultSendService.kt @@ -54,6 +54,19 @@ internal class DefaultSendService @Inject constructor(private val context: Conte val event = localEchoEventFactory.createTextEvent(roomId, msgType, text, autoMarkdown).also { saveLocalEcho(it) } + + return sendEvent(event) + } + + override fun sendFormattedTextMessage(text: String, formattedText: String): Cancelable { + val event = localEchoEventFactory.createFormattedTextEvent(roomId, text, formattedText).also { + saveLocalEcho(it) + } + + return sendEvent(event) + } + + private fun sendEvent(event: Event): Cancelable { // Encrypted room handling return if (cryptoService.isRoomEncrypted(roomId)) { Timber.v("Send event in encrypted room") @@ -62,25 +75,12 @@ internal class DefaultSendService @Inject constructor(private val context: Conte TimelineSendEventWorkCommon.postSequentialWorks(context, roomId, encryptWork, sendWork) CancelableWork(context, encryptWork.id) } else { - sendEvent(event) + val sendWork = createSendEventWork(event) + TimelineSendEventWorkCommon.postWork(context, roomId, sendWork) + CancelableWork(context, sendWork.id) } } - private fun sendEvent(event: Event): Cancelable { - val sendWork = createSendEventWork(event) - TimelineSendEventWorkCommon.postWork(context, roomId, sendWork) - return CancelableWork(context, sendWork.id) - } - - override fun sendFormattedTextMessage(text: String, formattedText: String): Cancelable { - val event = localEchoEventFactory.createFormattedTextEvent(roomId, text, formattedText).also { - saveLocalEcho(it) - } - val sendWork = createSendEventWork(event) - TimelineSendEventWorkCommon.postWork(context, roomId, sendWork) - return CancelableWork(context, sendWork.id) - } - override fun sendMedias(attachments: List): Cancelable { val cancelableBag = CancelableBag() attachments.forEach { diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index 60428713c9..96c2a7cf37 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -233,7 +233,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro SendMode.QUOTE -> { val messageContent: MessageContent? = state.selectedEvent?.annotations?.editSummary?.aggregatedContent?.toModel() - ?: state.selectedEvent?.root?.content.toModel() + ?: state.selectedEvent?.root?.getClearContent().toModel() val textMsg = messageContent?.body val finalText = legacyRiotQuoteText(textMsg, action.text) From 8fa5e63b07d0772c5d7d167881bfd5d7ca4f35d2 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 4 Jul 2019 12:52:43 +0200 Subject: [PATCH 2/2] Fix issue: reply to e2e event does not contain the base message --- .../android/internal/session/room/send/LocalEchoEventFactory.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt index ce2d6e4cd2..4e7e8eed77 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/LocalEchoEventFactory.kt @@ -254,7 +254,7 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials // // // This is where the reply goes. - val body = bodyForReply(eventReplied.content.toModel()) + val body = bodyForReply(eventReplied.getClearContent().toModel()) val replyFallbackTemplateFormatted = """
${stringProvider.getString(R.string.message_reply_to_prefix)}%s
%s
%s """.trimIndent().format(permalink, userLink, userId, body.second ?: body.first, replyText)