Limit the text length in the 'in reply to' preview (#4491)

* Limit the text length in the 'in reply to' preview

Otherwise, very long texts with no line breaks can cause a Compose crash
This commit is contained in:
Jorge Martin Espinosa 2025-03-27 14:37:38 +01:00 committed by GitHub
parent 338267d4e3
commit f59b26eb10
3 changed files with 28 additions and 8 deletions

View file

@ -31,6 +31,7 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import io.element.android.compound.theme.ElementTheme
import io.element.android.libraries.core.extensions.toSafeLength
import io.element.android.libraries.designsystem.atomic.atoms.PlaceholderAtom
import io.element.android.libraries.designsystem.icons.CompoundDrawables
import io.element.android.libraries.designsystem.preview.ElementPreview
@ -152,8 +153,10 @@ private fun ReplyToContentText(metadata: InReplyToMetadata?) {
val text = when (metadata) {
InReplyToMetadata.Redacted -> stringResource(id = CommonStrings.common_message_removed)
InReplyToMetadata.UnableToDecrypt -> stringResource(id = CommonStrings.common_waiting_for_decryption_key)
is InReplyToMetadata.Text -> metadata.text
is InReplyToMetadata.Thumbnail -> metadata.text
// Add a limit to the text length to avoid a crash in Compose
is InReplyToMetadata.Text -> metadata.text.toSafeLength()
// Add a limit to the text length to avoid a crash in Compose
is InReplyToMetadata.Thumbnail -> metadata.text.toSafeLength()
null -> ""
}
val iconResourceId = when (metadata) {