diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt index 34903ad7e27..2c4e4fba7a7 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLinkPreviewMessageViewHolder.kt @@ -195,9 +195,9 @@ class IncomingLinkPreviewMessageViewHolder(incomingView: View, payload: Any) : binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName ?: context.getText(R.string.nc_nick_guest) binding.messageQuote.quotedMessage.text = messageUtils - .enrichChatMessageText( + .enrichChatReplyMessageText( binding.messageQuote.quotedMessage.context, - parentChatMessage.text, + parentChatMessage, binding.messageQuote.quotedMessage.context.resources.getColor( R.color.nc_incoming_text_default ) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt index 1941c1790a5..6127b507237 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingLocationMessageViewHolder.kt @@ -180,9 +180,9 @@ class IncomingLocationMessageViewHolder(incomingView: View, payload: Any) : binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName ?: context!!.getText(R.string.nc_nick_guest) binding.messageQuote.quotedMessage.text = messageUtils - .enrichChatMessageText( + .enrichChatReplyMessageText( binding.messageQuote.quotedMessage.context, - parentChatMessage.text, + parentChatMessage, binding.messageQuote.quotedMessage.context.resources.getColor( R.color.nc_incoming_text_default ) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingPollMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingPollMessageViewHolder.kt index dea850d3b2f..bd7cf4cdf53 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingPollMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingPollMessageViewHolder.kt @@ -203,9 +203,9 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) : binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName ?: context.getText(R.string.nc_nick_guest) binding.messageQuote.quotedMessage.text = messageUtils - .enrichChatMessageText( + .enrichChatReplyMessageText( binding.messageQuote.quotedMessage.context, - parentChatMessage.text, + parentChatMessage, binding.messageQuote.quotedMessage.context.resources.getColor( R.color.nc_incoming_text_default ) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingTextMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingTextMessageViewHolder.kt index fbc3a6bb20d..a8d6c7fc22c 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingTextMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingTextMessageViewHolder.kt @@ -202,10 +202,11 @@ class IncomingTextMessageViewHolder(itemView: View, payload: Any) : } else { parentChatMessage.actorDisplayName } + binding.messageQuote.quotedMessage.text = messageUtils - .enrichChatMessageText( + .enrichChatReplyMessageText( binding.messageQuote.quotedMessage.context, - DisplayUtils.ellipsize(parentChatMessage.text, MAX_REPLY_LENGTH), + parentChatMessage, binding.messageQuote.quotedMessage.context.resources.getColor(R.color.nc_incoming_text_default) ) @@ -240,6 +241,5 @@ class IncomingTextMessageViewHolder(itemView: View, payload: Any) : companion object { const val TEXT_SIZE_MULTIPLIER = 2.5 - const val MAX_REPLY_LENGTH = 250 } } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt index 07db5eca825..0cab26b6d26 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/IncomingVoiceMessageViewHolder.kt @@ -296,9 +296,9 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) : binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName ?: context!!.getText(R.string.nc_nick_guest) binding.messageQuote.quotedMessage.text = messageUtils - .enrichChatMessageText( + .enrichChatReplyMessageText( binding.messageQuote.quotedMessage.context, - parentChatMessage.text, + parentChatMessage, binding.messageQuote.quotedMessage.context.resources.getColor( R.color.nc_incoming_text_default ) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLinkPreviewMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLinkPreviewMessageViewHolder.kt index e8bd206963e..4cfcebca086 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLinkPreviewMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLinkPreviewMessageViewHolder.kt @@ -173,9 +173,9 @@ class OutcomingLinkPreviewMessageViewHolder(outcomingView: View, payload: Any) : binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName ?: context.getText(R.string.nc_nick_guest) binding.messageQuote.quotedMessage.text = messageUtils - .enrichChatMessageText( + .enrichChatReplyMessageText( binding.messageQuote.quotedMessage.context, - parentChatMessage.text, + parentChatMessage, viewThemeUtils.getScheme(binding.messageQuote.quotedMessage.context).onSurfaceVariant ) viewThemeUtils.talk.colorOutgoingQuoteText(binding.messageQuote.quotedMessage) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt index dcc5d990ac9..ef7d71da033 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingLocationMessageViewHolder.kt @@ -226,9 +226,9 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName ?: context!!.getText(R.string.nc_nick_guest) binding.messageQuote.quotedMessage.text = messageUtils - .enrichChatMessageText( + .enrichChatReplyMessageText( binding.messageQuote.quotedMessage.context, - parentChatMessage.text, + parentChatMessage, viewThemeUtils.getScheme(binding.messageQuote.quotedMessage.context).onSurfaceVariant ) viewThemeUtils.talk.colorOutgoingQuoteText(binding.messageQuote.quotedMessage) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingPollMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingPollMessageViewHolder.kt index 05571152faa..7c12298aadc 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingPollMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingPollMessageViewHolder.kt @@ -188,9 +188,9 @@ class OutcomingPollMessageViewHolder(outcomingView: View, payload: Any) : binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName ?: context.getText(R.string.nc_nick_guest) binding.messageQuote.quotedMessage.text = messageUtils - .enrichChatMessageText( + .enrichChatReplyMessageText( binding.messageQuote.quotedMessage.context, - parentChatMessage.text, + parentChatMessage, viewThemeUtils.getScheme(binding.messageQuote.quotedMessage.context).onSurfaceVariant ) viewThemeUtils.talk.colorOutgoingQuoteText(binding.messageQuote.quotedMessage) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingTextMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingTextMessageViewHolder.kt index a0497d6aa4d..b8534923ebc 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingTextMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingTextMessageViewHolder.kt @@ -175,9 +175,9 @@ class OutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessageViewH binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName ?: context!!.getText(R.string.nc_nick_guest) binding.messageQuote.quotedMessage.text = messageUtils - .enrichChatMessageText( + .enrichChatReplyMessageText( binding.messageQuote.quotedMessage.context, - DisplayUtils.ellipsize(parentChatMessage.text, MAX_REPLY_LENGTH), + parentChatMessage, textColor ) @@ -201,6 +201,5 @@ class OutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessageViewH companion object { const val TEXT_SIZE_MULTIPLIER = 2.5 - const val MAX_REPLY_LENGTH = 250 } } diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingVoiceMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingVoiceMessageViewHolder.kt index 4da9a1cd99a..cf1ee2bbaa0 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingVoiceMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/OutcomingVoiceMessageViewHolder.kt @@ -283,9 +283,9 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName ?: context!!.getText(R.string.nc_nick_guest) binding.messageQuote.quotedMessage.text = messageUtils - .enrichChatMessageText( + .enrichChatReplyMessageText( binding.messageQuote.quotedMessage.context, - parentChatMessage.text, + parentChatMessage, viewThemeUtils.getScheme(binding.messageQuote.quotedMessage.context).onSurfaceVariant ) viewThemeUtils.talk.colorOutgoingQuoteText(binding.messageQuote.quotedMessage) diff --git a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.kt b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.kt index 5e8646981f4..c61a0c2781f 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.kt +++ b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.kt @@ -119,6 +119,9 @@ data class ChatMessage( @JsonField(name = ["expirationTimestamp"]) var expirationTimestamp: Int = 0, + @JsonField(name = ["markdown"]) + var renderMarkdown: Boolean? = null, + var isDownloadingVoiceMessage: Boolean = false, var resetVoiceMessage: Boolean = false, diff --git a/app/src/main/java/com/nextcloud/talk/utils/message/MessageUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/message/MessageUtils.kt index 8148a580f8b..c29f286bd99 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/message/MessageUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/message/MessageUtils.kt @@ -23,10 +23,12 @@ package com.nextcloud.talk.utils.message import android.content.Context import android.content.Intent import android.net.Uri +import android.text.SpannableString import android.text.Spanned import android.util.Log import android.view.View import com.nextcloud.talk.R +import com.nextcloud.talk.adapters.messages.IncomingTextMessageViewHolder import com.nextcloud.talk.models.json.chat.ChatMessage import com.nextcloud.talk.ui.theme.ViewThemeUtils import com.nextcloud.talk.utils.DisplayUtils @@ -39,16 +41,27 @@ import io.noties.markwon.ext.tasklist.TaskListDrawable import io.noties.markwon.ext.tasklist.TaskListPlugin class MessageUtils(val context: Context) { + fun enrichChatReplyMessageText(context: Context, message: ChatMessage, textColor: Int): Spanned? { + return if (message.message == null) { + null + } else if (message.renderMarkdown == false) { + SpannableString(DisplayUtils.ellipsize(message.message!!, MAX_REPLY_LENGTH)) + } else { + enrichChatMessageText(context, DisplayUtils.ellipsize(message.message!!, MAX_REPLY_LENGTH), textColor) + } + } fun enrichChatMessageText(context: Context, message: ChatMessage, textColor: Int): Spanned? { return if (message.message == null) { null + } else if (message.renderMarkdown == false) { + SpannableString(message.message) } else { enrichChatMessageText(context, message.message!!, textColor) } } - fun enrichChatMessageText(context: Context, message: String, textColor: Int): Spanned { + private fun enrichChatMessageText(context: Context, message: String, textColor: Int): Spanned { return getRenderedMarkdownText(context, message, textColor) } @@ -139,5 +152,6 @@ class MessageUtils(val context: Context) { companion object { private const val TAG = "MessageUtils" + const val MAX_REPLY_LENGTH = 250 } }