Create data class instead of Pair

This commit is contained in:
Benoit Marty 2019-07-10 10:34:32 +02:00
parent 0a54801fcc
commit 92e3a02389
2 changed files with 37 additions and 9 deletions

View File

@ -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 <Plain Text, Formatted Text?> used for the fallback event representation
* in a reply message.
*/
private fun bodyForReply(content: MessageContent?): Pair<String, String?> {
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 ?: "")
}
}


View File

@ -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
}