From 378ec9072e6e7eb00d8fbedc0a402b1adbbdcc2e Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Thu, 27 Jul 2023 23:30:35 +0200 Subject: [PATCH] Implement respecting the markdown rendering flag ...and fixing the reply ellipsizing for any reply messages Signed-off-by: Andy Scherzinger --- .../IncomingLinkPreviewMessageViewHolder.kt | 4 ++-- .../messages/IncomingLocationMessageViewHolder.kt | 4 ++-- .../messages/IncomingPollMessageViewHolder.kt | 4 ++-- .../messages/IncomingTextMessageViewHolder.kt | 7 +++---- .../messages/IncomingVoiceMessageViewHolder.kt | 4 ++-- .../OutcomingLinkPreviewMessageViewHolder.kt | 4 ++-- .../OutcomingLocationMessageViewHolder.kt | 4 ++-- .../messages/OutcomingPollMessageViewHolder.kt | 4 ++-- .../messages/OutcomingTextMessageViewHolder.kt | 6 ++---- .../messages/OutcomingVoiceMessageViewHolder.kt | 4 ++-- .../talk/models/json/chat/ChatMessage.kt | 3 +++ .../nextcloud/talk/utils/message/MessageUtils.kt | 15 ++++++++++++++- 12 files changed, 38 insertions(+), 25 deletions(-) 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..e4ffaba7308 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 @@ -44,7 +44,6 @@ import com.nextcloud.talk.models.json.chat.ChatMessage import com.nextcloud.talk.ui.theme.ViewThemeUtils import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.DateUtils -import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.TextMatchers import com.nextcloud.talk.utils.message.MessageUtils import com.nextcloud.talk.utils.preferences.AppPreferences @@ -202,10 +201,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 +240,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..3931f810a4f 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 @@ -41,7 +41,6 @@ import com.nextcloud.talk.models.json.chat.ReadStatus import com.nextcloud.talk.ui.theme.ViewThemeUtils import com.nextcloud.talk.utils.ApiUtils import com.nextcloud.talk.utils.DateUtils -import com.nextcloud.talk.utils.DisplayUtils import com.nextcloud.talk.utils.TextMatchers import com.nextcloud.talk.utils.message.MessageUtils import com.stfalcon.chatkit.messages.MessageHolders.OutcomingTextMessageViewHolder @@ -175,9 +174,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 +200,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..19df5622506 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,6 +23,7 @@ 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 @@ -39,16 +40,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 +151,6 @@ class MessageUtils(val context: Context) { companion object { private const val TAG = "MessageUtils" + const val MAX_REPLY_LENGTH = 250 } }