From 92e3a02389ffd03c8ace35e15aa5d6db864a88c6 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 10 Jul 2019 10:34:32 +0200 Subject: [PATCH] Create data class instead of Pair --- .../room/send/LocalEchoEventFactory.kt | 18 ++++++------ .../internal/session/room/send/TextContent.kt | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/TextContent.kt 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 655cafbb..1550dba8 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 @@ -265,13 +265,13 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials stringProvider.getString(R.string.message_reply_to_prefix), userLink, userId, - body.second ?: body.first, + body.takeFormatted(), replyText ) // // > <@alice:example.org> This is the original body // - val lines = body.first.split("\n") + val lines = body.text.split("\n") val replyFallback = StringBuffer("><$userId>") lines.forEachIndexed { index, s -> if (index == 0) { @@ -297,7 +297,7 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials * Returns a pair of used for the fallback event representation * in a reply message. */ - private fun bodyForReply(content: MessageContent?): Pair { + private fun bodyForReply(content: MessageContent?): TextContent { when (content?.type) { MessageType.MSGTYPE_EMOTE, MessageType.MSGTYPE_TEXT, @@ -309,13 +309,13 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials formattedText = content.formattedBody } } - return content.body to formattedText + return TextContent(content.body, formattedText) } - MessageType.MSGTYPE_FILE -> return stringProvider.getString(R.string.reply_to_a_file) to null - MessageType.MSGTYPE_AUDIO -> return stringProvider.getString(R.string.reply_to_an_audio_file) to null - MessageType.MSGTYPE_IMAGE -> return stringProvider.getString(R.string.reply_to_an_image) to null - MessageType.MSGTYPE_VIDEO -> return stringProvider.getString(R.string.reply_to_a_video) to null - else -> return (content?.body ?: "") to null + MessageType.MSGTYPE_FILE -> return TextContent(stringProvider.getString(R.string.reply_to_a_file)) + MessageType.MSGTYPE_AUDIO -> return TextContent(stringProvider.getString(R.string.reply_to_an_audio_file)) + MessageType.MSGTYPE_IMAGE -> return TextContent(stringProvider.getString(R.string.reply_to_an_image)) + MessageType.MSGTYPE_VIDEO -> return TextContent(stringProvider.getString(R.string.reply_to_a_video)) + else -> return TextContent(content?.body ?: "") } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/TextContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/TextContent.kt new file mode 100644 index 00000000..554d84b3 --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/send/TextContent.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2019 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.matrix.android.internal.session.room.send + +/** + * Contains a text and eventually a formatted text + */ +data class TextContent( + val text: String, + + val formattedText: String? = null +) { + fun takeFormatted() = formattedText ?: text +}