mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Fix crashes for extremely long messages with no line breaks (#2163)
This commit is contained in:
committed by
GitHub
parent
49487481ec
commit
4776fc5452
@@ -0,0 +1 @@
|
|||||||
|
Fix crashes in room list when the last message for a room was an extremely long one (several thousands of characters) with no line breaks.
|
||||||
+7
-1
@@ -42,6 +42,12 @@ import javax.inject.Inject
|
|||||||
class MessageSummaryFormatterImpl @Inject constructor(
|
class MessageSummaryFormatterImpl @Inject constructor(
|
||||||
@ApplicationContext private val context: Context,
|
@ApplicationContext private val context: Context,
|
||||||
) : MessageSummaryFormatter {
|
) : MessageSummaryFormatter {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
// Max characters to display in the summary message. This works around https://github.com/element-hq/element-x-android/issues/2105
|
||||||
|
private const val MAX_SAFE_LENGTH = 500
|
||||||
|
}
|
||||||
|
|
||||||
override fun format(event: TimelineItem.Event): String {
|
override fun format(event: TimelineItem.Event): String {
|
||||||
return when (event.content) {
|
return when (event.content) {
|
||||||
is TimelineItemTextBasedContent -> event.content.plainText
|
is TimelineItemTextBasedContent -> event.content.plainText
|
||||||
@@ -58,6 +64,6 @@ class MessageSummaryFormatterImpl @Inject constructor(
|
|||||||
is TimelineItemVideoContent -> context.getString(CommonStrings.common_video)
|
is TimelineItemVideoContent -> context.getString(CommonStrings.common_video)
|
||||||
is TimelineItemFileContent -> context.getString(CommonStrings.common_file)
|
is TimelineItemFileContent -> context.getString(CommonStrings.common_file)
|
||||||
is TimelineItemAudioContent -> context.getString(CommonStrings.common_audio)
|
is TimelineItemAudioContent -> context.getString(CommonStrings.common_audio)
|
||||||
}
|
}.take(MAX_SAFE_LENGTH)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -63,6 +63,11 @@ class DefaultRoomLastMessageFormatter @Inject constructor(
|
|||||||
private val stateContentFormatter: StateContentFormatter,
|
private val stateContentFormatter: StateContentFormatter,
|
||||||
) : RoomLastMessageFormatter {
|
) : RoomLastMessageFormatter {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
// Max characters to display in the last message. This works around https://github.com/element-hq/element-x-android/issues/2105
|
||||||
|
private const val MAX_SAFE_LENGTH = 500
|
||||||
|
}
|
||||||
|
|
||||||
override fun format(event: EventTimelineItem, isDmRoom: Boolean): CharSequence? {
|
override fun format(event: EventTimelineItem, isDmRoom: Boolean): CharSequence? {
|
||||||
val isOutgoing = event.isOwn
|
val isOutgoing = event.isOwn
|
||||||
val senderDisplayName = (event.senderProfile as? ProfileTimelineDetails.Ready)?.displayName ?: event.sender.value
|
val senderDisplayName = (event.senderProfile as? ProfileTimelineDetails.Ready)?.displayName ?: event.sender.value
|
||||||
@@ -103,7 +108,7 @@ class DefaultRoomLastMessageFormatter @Inject constructor(
|
|||||||
is FailedToParseMessageLikeContent, is FailedToParseStateContent, is UnknownContent -> {
|
is FailedToParseMessageLikeContent, is FailedToParseStateContent, is UnknownContent -> {
|
||||||
prefixIfNeeded(sp.getString(CommonStrings.common_unsupported_event), senderDisplayName, isDmRoom)
|
prefixIfNeeded(sp.getString(CommonStrings.common_unsupported_event), senderDisplayName, isDmRoom)
|
||||||
}
|
}
|
||||||
}
|
}?.take(MAX_SAFE_LENGTH)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processMessageContents(messageContent: MessageContent, senderDisplayName: String, isDmRoom: Boolean): CharSequence? {
|
private fun processMessageContents(messageContent: MessageContent, senderDisplayName: String, isDmRoom: Boolean): CharSequence? {
|
||||||
|
|||||||
Reference in New Issue
Block a user