diff --git a/appconfig/src/main/kotlin/io/element/android/appconfig/ProtectionConfig.kt b/appconfig/src/main/kotlin/io/element/android/appconfig/ProtectionConfig.kt new file mode 100644 index 0000000000..f6ad71eeb1 --- /dev/null +++ b/appconfig/src/main/kotlin/io/element/android/appconfig/ProtectionConfig.kt @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2026 Element Creations Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.appconfig + +object ProtectionConfig { + /** + * The maximum length of a room name, to limit attack vectors in room invite. + */ + const val MAX_ROOM_NAME_LENGTH = 128 +} diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListDeclineInviteMenu.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListDeclineInviteMenu.kt index 523e677a57..d641a06063 100644 --- a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListDeclineInviteMenu.kt +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListDeclineInviteMenu.kt @@ -19,10 +19,13 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp +import io.element.android.appconfig.ProtectionConfig import io.element.android.compound.theme.ElementTheme import io.element.android.features.home.impl.R import io.element.android.features.home.impl.model.RoomListRoomSummary +import io.element.android.libraries.core.extensions.toSafeLength import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.theme.components.Button @@ -44,7 +47,11 @@ fun RoomListDeclineInviteMenu( onDismissRequest = { eventSink(RoomListEvent.HideDeclineInviteMenu) }, ) { RoomListDeclineInviteMenuContent( - roomName = menu.roomSummary.name ?: menu.roomSummary.roomId.value, + roomName = menu.roomSummary.name?.toSafeLength( + maxLength = ProtectionConfig.MAX_ROOM_NAME_LENGTH, + ellipsize = true, + ) + ?: menu.roomSummary.roomId.value, onDeclineClick = { eventSink(RoomListEvent.HideDeclineInviteMenu) eventSink(RoomListEvent.DeclineInvite(menu.roomSummary, false)) @@ -112,16 +119,15 @@ private fun RoomListDeclineInviteMenuContent( } } -// TODO This component should be seen in [RoomListView] @Preview but it doesn't show up. -// see: https://issuetracker.google.com/issues/283843380 -// Remove this preview when the issue is fixed. @PreviewsDayNight @Composable -internal fun RoomListDeclineInviteMenuContentPreview() = ElementPreview { - RoomListDeclineInviteMenuContent( - roomName = "Room name", - onCancelClick = {}, - onDeclineClick = {}, +internal fun RoomListDeclineInviteMenuContentPreview( + @PreviewParameter(RoomListStateDeclineInviteMenuShownProvider::class) menu: RoomListState.DeclineInviteMenu.Shown, +) = ElementPreview { + RoomListDeclineInviteMenu( + menu = menu, + canReportRoom = false, onDeclineAndBlockClick = {}, + eventSink = {}, ) } diff --git a/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListStateDeclineInviteMenuShownProvider.kt b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListStateDeclineInviteMenuShownProvider.kt new file mode 100644 index 0000000000..73d4785e96 --- /dev/null +++ b/features/home/impl/src/main/kotlin/io/element/android/features/home/impl/roomlist/RoomListStateDeclineInviteMenuShownProvider.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2026 Element Creations Ltd. + * + * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial. + * Please see LICENSE files in the repository root for full details. + */ + +package io.element.android.features.home.impl.roomlist + +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import androidx.compose.ui.tooling.preview.datasource.LoremIpsum +import io.element.android.features.home.impl.model.RoomListRoomSummary +import io.element.android.features.home.impl.model.aRoomListRoomSummary + +open class RoomListStateDeclineInviteMenuShownProvider : PreviewParameterProvider { + override val values: Sequence + get() = sequenceOf( + aDeclineInviteMenuShown(), + aDeclineInviteMenuShown( + aRoomListRoomSummary( + name = LoremIpsum(500).values.first(), + ) + ), + aDeclineInviteMenuShown( + aRoomListRoomSummary( + name = null, + ) + ), + ) +} + +internal fun aDeclineInviteMenuShown( + roomSummary: RoomListRoomSummary = aRoomListRoomSummary(), +) = RoomListState.DeclineInviteMenu.Shown( + roomSummary = roomSummary, +)