Skip to content

Commit

Permalink
Implement respecting the markdown rendering flag
Browse files Browse the repository at this point in the history
...and fixing the reply ellipsizing for any reply messages

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
  • Loading branch information
AndyScherzinger committed Jul 28, 2023
1 parent 5d5b476 commit 378ec90
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)

Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand All @@ -201,6 +200,5 @@ class OutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessageViewH

companion object {
const val TEXT_SIZE_MULTIPLIER = 2.5
const val MAX_REPLY_LENGTH = 250
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand Down Expand Up @@ -139,5 +151,6 @@ class MessageUtils(val context: Context) {

companion object {
private const val TAG = "MessageUtils"
const val MAX_REPLY_LENGTH = 250
}
}

0 comments on commit 378ec90

Please sign in to comment.