Avoid showing debug notice format for event preview

This commit is contained in:
Valere 2020-09-03 14:42:33 +02:00 committed by Benoit Marty
parent c895f87e26
commit a544ae264b
2 changed files with 44 additions and 6 deletions

View file

@ -20,15 +20,17 @@ import im.vector.app.EmojiCompatWrapper
import im.vector.app.R
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.resources.StringProvider
import me.gujun.android.span.span
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.message.MessageOptionsContent
import org.matrix.android.sdk.api.session.room.model.message.MessageType
import org.matrix.android.sdk.api.session.room.model.message.OPTION_TYPE_BUTTONS
import org.matrix.android.sdk.api.session.room.model.relation.ReactionContent
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
import org.matrix.android.sdk.api.session.room.timeline.getTextEditableContent
import org.matrix.android.sdk.api.session.room.timeline.isReply
import me.gujun.android.span.span
import javax.inject.Inject
class DisplayableEventFormatter @Inject constructor(
@ -51,16 +53,16 @@ class DisplayableEventFormatter @Inject constructor(
val senderName = timelineEvent.senderInfo.disambiguatedDisplayName
when (timelineEvent.root.getClearType()) {
EventType.STICKER -> {
EventType.STICKER -> {
return simpleFormat(senderName, stringProvider.getString(R.string.send_a_sticker), appendAuthor)
}
EventType.REACTION -> {
EventType.REACTION -> {
timelineEvent.root.getClearContent().toModel<ReactionContent>()?.relatesTo?.let {
val emojiSpanned = emojiCompatWrapper.safeEmojiSpanify(it.key)
val emojiSpanned = emojiCompatWrapper.safeEmojiSpanify(stringProvider.getString(R.string.sent_a_reaction, it.key))
return simpleFormat(senderName, emojiSpanned, appendAuthor)
}
}
EventType.MESSAGE -> {
EventType.MESSAGE -> {
timelineEvent.getLastMessageContent()?.let { messageContent ->
when (messageContent.msgType) {
MessageType.MSGTYPE_VERIFICATION_REQUEST -> {
@ -88,13 +90,45 @@ class DisplayableEventFormatter @Inject constructor(
simpleFormat(senderName, messageContent.body, appendAuthor)
}
}
MessageType.MSGTYPE_RESPONSE -> {
// do not show that?
return span { }
}
MessageType.MSGTYPE_OPTIONS -> {
return when (messageContent) {
is MessageOptionsContent -> {
val previewText = if (messageContent.optionType == OPTION_TYPE_BUTTONS) {
stringProvider.getString(R.string.sent_a_bot_buttons)
} else {
stringProvider.getString(R.string.sent_a_poll)
}
simpleFormat(senderName, previewText, appendAuthor)
}
else -> {
span { }
}
}
}
else -> {
return simpleFormat(senderName, messageContent.body, appendAuthor)
}
}
}
}
else -> {
EventType.KEY_VERIFICATION_CANCEL,
EventType.KEY_VERIFICATION_DONE -> {
// cancel and done can appear in timeline, so should have representation
return simpleFormat(senderName, stringProvider.getString(R.string.sent_verification_conclusion), appendAuthor)
}
EventType.KEY_VERIFICATION_START,
EventType.KEY_VERIFICATION_ACCEPT,
EventType.KEY_VERIFICATION_MAC,
EventType.KEY_VERIFICATION_KEY,
EventType.KEY_VERIFICATION_READY,
EventType.CALL_CANDIDATES -> {
return span { }
}
else -> {
return span {
text = noticeEventFormatter.format(timelineEvent) ?: ""
textStyle = "italic"

View file

@ -2067,6 +2067,10 @@
<string name="sent_an_audio_file">Audio</string>
<string name="sent_a_file">File</string>
<string name="send_a_sticker">Sticker</string>
<string name="sent_a_poll">Poll</string>
<string name="sent_a_bot_buttons">Bot Buttons</string>
<string name="sent_a_reaction">Reacted with: %s</string>
<string name="sent_verification_conclusion">Verification Conclusion</string>
<string name="verification_request_waiting">Waiting…</string>
<string name="verification_request_other_cancelled">%s cancelled</string>