RoomListDeclineInviteMenu: limit room name
Improve preview. Closes #6659
This commit is contained in:
parent
9a2ad3928a
commit
bf57223d05
3 changed files with 66 additions and 9 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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 = {},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<RoomListState.DeclineInviteMenu.Shown> {
|
||||
override val values: Sequence<RoomListState.DeclineInviteMenu.Shown>
|
||||
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,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue