Fix crashes for extremely long messages with no line breaks (#2163)
This commit is contained in:
parent
24a3c2baf7
commit
936127c682
3 changed files with 48 additions and 36 deletions
1
changelog.d/2105.bugfix
Normal file
1
changelog.d/2105.bugfix
Normal file
|
|
@ -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.
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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? {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue