From 4ba465fd04f135cf7c500d14229a825415cf0c5a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 15 Jan 2026 17:07:25 +0100 Subject: [PATCH 1/2] Ensure that room with long names renders correctly in the room list. --- .../android/features/home/impl/components/RoomSummaryRow.kt | 5 +++-- .../android/libraries/core/extensions/BasicExtensions.kt | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomSummaryRow.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomSummaryRow.kt index 50b9559e94..d8426b5321 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomSummaryRow.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/components/RoomSummaryRow.kt @@ -46,6 +46,7 @@ import io.element.android.features.home.impl.model.RoomListRoomSummaryProvider import io.element.android.features.home.impl.model.RoomSummaryDisplayType import io.element.android.features.home.impl.roomlist.RoomListEvents import io.element.android.libraries.core.extensions.orEmpty +import io.element.android.libraries.core.extensions.toSafeLength import io.element.android.libraries.designsystem.atomic.atoms.UnreadIndicatorAtom import io.element.android.libraries.designsystem.atomic.molecules.InviteButtonsRowMolecule import io.element.android.libraries.designsystem.components.avatar.Avatar @@ -227,7 +228,7 @@ private fun NameAndTimestampRow( // Name Text( style = ElementTheme.typography.fontBodyLgMedium, - text = name ?: stringResource(id = CommonStrings.common_no_room_name), + text = name?.toSafeLength(ellipsize = true) ?: stringResource(id = CommonStrings.common_no_room_name), fontStyle = FontStyle.Italic.takeIf { name == null }, color = ElementTheme.colors.roomListRoomName, maxLines = 1, @@ -380,7 +381,7 @@ private fun InviteNameAndIndicatorRow( Text( modifier = Modifier.weight(1f), style = ElementTheme.typography.fontBodyLgMedium, - text = name ?: stringResource(id = CommonStrings.common_no_room_name), + text = name?.toSafeLength(ellipsize = true) ?: stringResource(id = CommonStrings.common_no_room_name), fontStyle = FontStyle.Italic.takeIf { name == null }, color = ElementTheme.colors.roomListRoomName, maxLines = 1, diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/extensions/BasicExtensions.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/extensions/BasicExtensions.kt index d3a2805df1..d13777842d 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/extensions/BasicExtensions.kt +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/extensions/BasicExtensions.kt @@ -100,6 +100,8 @@ fun String.containsRtLOverride() = contains(RTL_OVERRIDE_CHAR) fun String.filterDirectionOverrides() = filterNot { it == RTL_OVERRIDE_CHAR || it == LTR_OVERRIDE_CHAR } +const val DEFAULT_SAFE_LENGTH = 500 + /** * This works around https://github.com/element-hq/element-x-android/issues/2105. * @param maxLength Max characters to retrieve. Defaults to `500`. @@ -107,7 +109,7 @@ fun String.filterDirectionOverrides() = filterNot { it == RTL_OVERRIDE_CHAR || i * @return The string truncated to [maxLength] characters, with an optional ellipsis if larger. */ fun String.toSafeLength( - maxLength: Int = 500, + maxLength: Int = DEFAULT_SAFE_LENGTH, ellipsize: Boolean = false, ): String { return if (ellipsize) { From 9e52fc067d97133fcf290a4c5a6e7c7814f3e535 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 15 Jan 2026 17:07:53 +0100 Subject: [PATCH 2/2] Avoid creating a new constant for the same goal. --- .../impl/DefaultRoomLatestEventFormatter.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libraries/eventformatter/impl/src/main/kotlin/io/element/android/libraries/eventformatter/impl/DefaultRoomLatestEventFormatter.kt b/libraries/eventformatter/impl/src/main/kotlin/io/element/android/libraries/eventformatter/impl/DefaultRoomLatestEventFormatter.kt index 7e1ffc3ee6..009547f9eb 100644 --- a/libraries/eventformatter/impl/src/main/kotlin/io/element/android/libraries/eventformatter/impl/DefaultRoomLatestEventFormatter.kt +++ b/libraries/eventformatter/impl/src/main/kotlin/io/element/android/libraries/eventformatter/impl/DefaultRoomLatestEventFormatter.kt @@ -9,6 +9,7 @@ package io.element.android.libraries.eventformatter.impl import dev.zacsweers.metro.ContributesBinding +import io.element.android.libraries.core.extensions.DEFAULT_SAFE_LENGTH import io.element.android.libraries.di.SessionScope import io.element.android.libraries.eventformatter.api.RoomLatestEventFormatter import io.element.android.libraries.eventformatter.impl.mode.RenderingMode @@ -54,11 +55,6 @@ class DefaultRoomLatestEventFormatter( private val stateContentFormatter: StateContentFormatter, private val permalinkParser: PermalinkParser, ) : RoomLatestEventFormatter { - 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( latestEvent: LatestEventValue.Local, isDmRoom: Boolean, @@ -121,7 +117,7 @@ class DefaultRoomLatestEventFormatter( } is LegacyCallInviteContent -> sp.getString(CommonStrings.common_unsupported_call) is CallNotifyContent -> sp.getString(CommonStrings.common_call_started) - }?.take(MAX_SAFE_LENGTH) + }?.take(DEFAULT_SAFE_LENGTH) } private fun MessageContent.process(