From 51c06b4becae8df102aa919d6e0c1f8baa855e94 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 17 Sep 2026 14:49:03 +0200 Subject: [PATCH 01/22] Timeline : initial multi-select state --- .../messages/impl/MessagesPresenter.kt | 4 + .../features/messages/impl/MessagesView.kt | 80 ++++++---- .../impl/actionlist/ActionListPresenter.kt | 9 ++ .../actionlist/model/TimelineItemAction.kt | 1 + .../model/TimelineItemActionComparator.kt | 1 + .../pinned/list/PinnedMessagesListView.kt | 2 + .../messages/impl/timeline/SelectionState.kt | 24 +++ .../messages/impl/timeline/TimelineEvent.kt | 4 + .../impl/timeline/TimelinePresenter.kt | 59 ++++++++ .../messages/impl/timeline/TimelineState.kt | 12 ++ .../impl/timeline/TimelineStateProvider.kt | 2 + .../messages/impl/timeline/TimelineView.kt | 60 +++++++- .../timeline/components/SelectionIndicator.kt | 54 +++++++ .../components/TimelineItemEventRow.kt | 10 +- .../TimelineItemGroupedEventsRow.kt | 1 + .../timeline/components/TimelineItemRow.kt | 142 ++++++++++++++++-- .../components/TimelineItemSelectionData.kt | 24 +++ .../timeline/model/TimelineItemSelection.kt | 34 +++++ .../impl/topbars/SelectionModeTopBar.kt | 59 ++++++++ .../impl/src/main/res/values/temporary.xml | 15 ++ .../actionlist/ActionListPresenterTest.kt | 38 +++++ .../impl/timeline/TimelinePresenterTest.kt | 77 ++++++++++ .../model/TimelineItemSelectionTest.kt | 47 ++++++ .../libraries/featureflag/api/FeatureFlags.kt | 7 + 24 files changed, 726 insertions(+), 40 deletions(-) create mode 100644 features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt create mode 100644 features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt create mode 100644 features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemSelectionData.kt create mode 100644 features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelection.kt create mode 100644 features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt create mode 100644 features/messages/impl/src/main/res/values/temporary.xml create mode 100644 features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionTest.kt diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt index 6a019d865b..bcbfc35255 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt @@ -402,6 +402,10 @@ class MessagesPresenter( TimelineItemAction.Unpin -> handleUnpinAction(targetEvent) TimelineItemAction.ViewInTimeline -> Unit TimelineItemAction.RetrySending -> handleRetrySending(targetEvent) + TimelineItemAction.Select -> { + val eventId = targetEvent.eventId ?: return@launch + timelineState.eventSink(TimelineEvent.EnterSelectionMode(eventId)) + } } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt index 16ca023d50..c4bcf552b5 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt @@ -10,6 +10,8 @@ package io.element.android.features.messages.impl import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.expandVertically +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut import androidx.compose.animation.shrinkVertically import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -89,12 +91,15 @@ import io.element.android.features.messages.impl.timeline.components.reactionsum import io.element.android.features.messages.impl.timeline.components.reactionsummary.ReactionSummaryView import io.element.android.features.messages.impl.timeline.components.receipt.bottomsheet.ReadReceiptBottomSheet import io.element.android.features.messages.impl.timeline.components.receipt.bottomsheet.ReadReceiptBottomSheetEvent +import io.element.android.features.messages.impl.timeline.isSelectionModeActive import io.element.android.features.messages.impl.timeline.model.TimelineItem import io.element.android.features.messages.impl.timeline.model.TimelineItemGroupPosition import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemStateEventContent import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemTextContent +import io.element.android.features.messages.impl.timeline.selectedCount import io.element.android.features.messages.impl.timeline.sendfailure.SendFailureDialogView import io.element.android.features.messages.impl.topbars.MessagesViewTopBar +import io.element.android.features.messages.impl.topbars.SelectionModeTopBar import io.element.android.features.messages.impl.topbars.ThreadTopBar import io.element.android.features.messages.impl.voicemessages.composer.VoiceMessagePermissionRationaleDialog import io.element.android.features.messages.impl.voicemessages.composer.VoiceMessageSendingFailedDialog @@ -177,6 +182,14 @@ fun MessagesView( block() } + // Entering selection mode collapses the composer, so dismiss the keyboard too. hideKeyboard + // triggers the IME hide animation, keeping it in sync with the composer collapse. + LaunchedEffect(state.timelineState.isSelectionModeActive) { + if (state.timelineState.isSelectionModeActive) { + localView.hideKeyboard() + } + } + fun onContentClick(event: TimelineItem.Event) { Timber.v("onMessageClick= ${event.id}") val eventId = event.eventId @@ -233,34 +246,45 @@ fun MessagesView( Scaffold( contentWindowInsets = scaffoldScrollableContentInsets, topBar = { - if (state.timelineState.timelineMode is Timeline.Mode.Thread) { - ThreadTopBar( - roomName = state.roomName, - roomAvatarData = state.roomAvatar, - heroes = state.heroes, - isTombstoned = state.isTombstoned, - onBackClick = onBackClick, - ) - } else { - MessagesViewTopBar( - roomName = state.roomName, - roomAvatar = state.roomAvatar, - isTombstoned = state.isTombstoned, - heroes = state.heroes, - dmUserIdentityState = state.dmUserVerificationState, - sharedHistoryIcon = state.topBarSharedHistoryIcon, - dmUserStatus = state.dmUserStatus, - onBackClick = { hidingKeyboard { onBackClick() } }, - onRoomDetailsClick = { hidingKeyboard { onRoomDetailsClick() } }, - menuActions = { - MessagesMenuActions( - displayThreads = state.timelineState.timelineMode !is Timeline.Mode.Thread && state.threads.hasThreads, - roomCallState = state.roomCallState, - onJoinCallClick = onJoinCallClick, - onThreadsListClick = onThreadsListClick - ) - } - ) + when { + state.timelineState.isSelectionModeActive -> { + SelectionModeTopBar( + selectedCount = state.timelineState.selectedCount, + onCancelClick = { + state.timelineState.eventSink(TimelineEvent.ExitSelectionMode) + }, + ) + } + state.timelineState.timelineMode is Timeline.Mode.Thread -> { + ThreadTopBar( + roomName = state.roomName, + roomAvatarData = state.roomAvatar, + heroes = state.heroes, + isTombstoned = state.isTombstoned, + onBackClick = onBackClick, + ) + } + else -> { + MessagesViewTopBar( + roomName = state.roomName, + roomAvatar = state.roomAvatar, + isTombstoned = state.isTombstoned, + heroes = state.heroes, + dmUserIdentityState = state.dmUserVerificationState, + sharedHistoryIcon = state.topBarSharedHistoryIcon, + dmUserStatus = state.dmUserStatus, + onBackClick = { hidingKeyboard { onBackClick() } }, + onRoomDetailsClick = { hidingKeyboard { onRoomDetailsClick() } }, + menuActions = { + MessagesMenuActions( + displayThreads = state.timelineState.timelineMode !is Timeline.Mode.Thread && state.threads.hasThreads, + roomCallState = state.roomCallState, + onJoinCallClick = onJoinCallClick, + onThreadsListClick = onThreadsListClick + ) + } + ) + } } }, content = { padding -> diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt index 8caa95f31d..66ed7dd757 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt @@ -27,6 +27,7 @@ import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUser import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUserSendFailureFactory import io.element.android.features.messages.impl.timeline.model.TimelineItem import io.element.android.features.messages.impl.timeline.model.TimelineItemThreadInfo +import io.element.android.features.messages.impl.timeline.model.canBeSelected import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAttachmentsContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContentWithAttachment @@ -109,6 +110,7 @@ class DefaultActionListPresenter( }.collectAsState(initial = persistentListOf()) val isThreadsEnabled = featureFlagService.isFeatureEnabledFlow(FeatureFlags.Threads).collectAsState(false) + val isMultiSelectEnabled = featureFlagService.isFeatureEnabledFlow(FeatureFlags.MessageMultiSelect).collectAsState(false) fun handleEvent(event: ActionListEvent) { when (event) { @@ -120,6 +122,7 @@ class DefaultActionListPresenter( pinnedEventIds = pinnedEventIds, target = target, isThreadsEnabled = isThreadsEnabled.value, + isMultiSelectEnabled = isMultiSelectEnabled.value, ) } } @@ -137,6 +140,7 @@ class DefaultActionListPresenter( pinnedEventIds: ImmutableList, target: MutableState, isThreadsEnabled: Boolean, + isMultiSelectEnabled: Boolean, ) = launch { target.value = ActionListState.Target.Loading(timelineItem) @@ -146,6 +150,7 @@ class DefaultActionListPresenter( isDeveloperModeEnabled = isDeveloperModeEnabled, isEventPinned = pinnedEventIds.contains(timelineItem.eventId), isThreadsEnabled = isThreadsEnabled, + isMultiSelectEnabled = isMultiSelectEnabled, ) val verifiedUserSendFailure = userSendFailureFactory.create(timelineItem.localSendState) @@ -179,6 +184,7 @@ class DefaultActionListPresenter( isDeveloperModeEnabled: Boolean, isEventPinned: Boolean, isThreadsEnabled: Boolean, + isMultiSelectEnabled: Boolean, ): List { val canRedact = timelineItem.isMine && usersEventPermissions.canRedactOwn || !timelineItem.isMine && usersEventPermissions.canRedactOther return buildSet { @@ -200,6 +206,9 @@ class DefaultActionListPresenter( if (timelineItem.isRemote && timelineItem.content.canBeForwarded()) { add(TimelineItemAction.Forward) } + if (isMultiSelectEnabled && timelineItem.canBeSelected()) { + add(TimelineItemAction.Select) + } if (timelineItem.isEditable && usersEventPermissions.canSendMessage) { if (timelineItem.content is TimelineItemEventContentWithAttachment || timelineItem.content is TimelineItemGalleryContent || diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemAction.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemAction.kt index 3c64223e59..c7ee198ebc 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemAction.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemAction.kt @@ -20,6 +20,7 @@ enum class TimelineItemAction( ) { ViewInTimeline(CommonStrings.action_view_in_timeline, CompoundDrawables.ic_compound_visibility_on), Forward(CommonStrings.action_forward, CompoundDrawables.ic_compound_forward), + Select(CommonStrings.action_select, CompoundDrawables.ic_compound_check), CopyText(CommonStrings.action_copy_text, CompoundDrawables.ic_compound_copy), CopyCaption(CommonStrings.action_copy_caption, CompoundDrawables.ic_compound_copy), CopyLink(CommonStrings.action_copy_link_to_message, CompoundDrawables.ic_compound_link), diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemActionComparator.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemActionComparator.kt index 2f6fa4e4e0..86b62794ba 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemActionComparator.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemActionComparator.kt @@ -19,6 +19,7 @@ class TimelineItemActionComparator : Comparator { TimelineItemAction.Reply, TimelineItemAction.ReplyInThread, TimelineItemAction.Forward, + TimelineItemAction.Select, TimelineItemAction.Edit, TimelineItemAction.EditPoll, TimelineItemAction.AddCaption, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/list/PinnedMessagesListView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/list/PinnedMessagesListView.kt index 5daec3e275..f751250c90 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/list/PinnedMessagesListView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/list/PinnedMessagesListView.kt @@ -33,6 +33,7 @@ import io.element.android.features.messages.impl.link.LinkEvent import io.element.android.features.messages.impl.link.LinkView import io.element.android.features.messages.impl.timeline.TimelineEvent import io.element.android.features.messages.impl.timeline.components.TimelineItemRow +import io.element.android.features.messages.impl.timeline.components.TimelineItemSelectionData import io.element.android.features.messages.impl.timeline.components.customreaction.CustomReactionBottomSheet import io.element.android.features.messages.impl.timeline.components.customreaction.CustomReactionEvent import io.element.android.features.messages.impl.timeline.components.event.TimelineItemEventContentView @@ -291,6 +292,7 @@ private fun PinnedMessagesListLoaded( onContentLayoutChange = onContentLayoutChange ) }, + selectionData = TimelineItemSelectionData(), ) } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt new file mode 100644 index 0000000000..91b0d2e73a --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2026 New Vector 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.messages.impl.timeline + +import androidx.compose.runtime.Immutable +import io.element.android.libraries.matrix.api.core.EventId +import kotlinx.collections.immutable.ImmutableSet + +/** Maximum number of messages that can be selected at once. */ +const val MAX_SELECTION_COUNT = 30 + +@Immutable +sealed interface SelectionState { + /** Selection mode is not active. */ + data object Disabled : SelectionState + + /** Selection mode is active with the given selection. */ + data class Active(val selectedEventIds: ImmutableSet) : SelectionState +} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineEvent.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineEvent.kt index 66807b74f2..f21bfe88aa 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineEvent.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineEvent.kt @@ -29,6 +29,10 @@ sealed interface TimelineEvent { data object MarkAllAsRead : TimelineEvent + data class EnterSelectionMode(val eventId: EventId) : TimelineEvent + data class ToggleSelection(val eventId: EventId) : TimelineEvent + data object ExitSelectionMode : TimelineEvent + /** * Events coming from a timeline item. */ diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt index 2fc4351cea..80812264fd 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt @@ -25,6 +25,7 @@ import dev.zacsweers.metro.AssistedFactory import dev.zacsweers.metro.AssistedInject import io.element.android.features.location.api.live.ActiveLiveLocationShareManager import io.element.android.features.messages.impl.MessagesNavigator +import io.element.android.features.messages.impl.R import io.element.android.features.messages.impl.UserEventPermissions import io.element.android.features.messages.impl.crypto.sendfailure.resolve.ResolveVerifiedUserSendFailureEvent import io.element.android.features.messages.impl.crypto.sendfailure.resolve.ResolveVerifiedUserSendFailureState @@ -33,6 +34,7 @@ import io.element.android.features.messages.impl.timeline.factories.TimelineItem import io.element.android.features.messages.impl.timeline.factories.TimelineItemsFactoryConfig import io.element.android.features.messages.impl.timeline.model.NewEventState import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.canBeSelected import io.element.android.features.messages.impl.timeline.model.virtual.TimelineItemReadMarkerModel import io.element.android.features.messages.impl.timeline.model.virtual.TimelineItemTypingNotificationModel import io.element.android.features.messages.impl.timeline.protection.TimelineProtectionEvent @@ -46,6 +48,8 @@ import io.element.android.features.poll.api.actions.SendPollResponseAction import io.element.android.features.roomcall.api.RoomCallState import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.core.coroutine.CoroutineDispatchers +import io.element.android.libraries.designsystem.utils.snackbar.SnackbarDispatcher +import io.element.android.libraries.designsystem.utils.snackbar.SnackbarMessage import io.element.android.libraries.di.annotations.SessionCoroutineScope import io.element.android.libraries.featureflag.api.FeatureFlagService import io.element.android.libraries.featureflag.api.FeatureFlags @@ -68,7 +72,9 @@ import io.element.android.services.analytics.api.finishLongRunningTransaction import io.element.android.services.analyticsproviders.api.AnalyticsUserData import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.persistentSetOf import kotlinx.collections.immutable.toImmutableList +import kotlinx.collections.immutable.toPersistentSet import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.combine @@ -100,6 +106,7 @@ class TimelinePresenter( private val typingNotificationPresenter: Presenter, private val roomCallStatePresenter: Presenter, private val featureFlagService: FeatureFlagService, + private val snackbarDispatcher: SnackbarDispatcher, private val analyticsService: AnalyticsService, private val liveLocationShareManager: ActiveLiveLocationShareManager, private val markAsFullyRead: MarkAsFullyRead, @@ -164,6 +171,18 @@ class TimelinePresenter( value = featureFlagService.isFeatureEnabled(FeatureFlags.JumpToUnread) } + val isMultiSelectEnabled by produceState(false) { + featureFlagService.isFeatureEnabledFlow(FeatureFlags.MessageMultiSelect).collect { value = it } + } + var selectionState by remember { mutableStateOf(SelectionState.Disabled) } + + // When the feature flag is turned off, clear any active selection. + LaunchedEffect(isMultiSelectEnabled) { + if (!isMultiSelectEnabled) { + selectionState = SelectionState.Disabled + } + } + val timelineProtectionState = timelineProtectionPresenter.present() fun handleEvent(event: TimelineEvent) { @@ -244,6 +263,28 @@ class TimelinePresenter( is TimelineEvent.JumpToLive -> { timelineController.focusOnLive() } + is TimelineEvent.EnterSelectionMode -> { + if (!isMultiSelectEnabled) return + selectionState = SelectionState.Active(persistentSetOf(event.eventId)) + } + is TimelineEvent.ToggleSelection -> { + val current = selectionState as? SelectionState.Active ?: return + val selected = current.selectedEventIds + selectionState = when { + event.eventId in selected -> { + val next = (selected - event.eventId).toPersistentSet() + if (next.isEmpty()) SelectionState.Disabled else SelectionState.Active(next) + } + selected.size >= MAX_SELECTION_COUNT -> { + snackbarDispatcher.post(SnackbarMessage(R.string.screen_room_timeline_selection_limit_reached)) + current + } + else -> SelectionState.Active((selected + event.eventId).toPersistentSet()) + } + } + is TimelineEvent.ExitSelectionMode -> { + selectionState = SelectionState.Disabled + } TimelineEvent.HideShieldDialog -> messageShieldDialogData.value = null TimelineEvent.MarkAllAsRead -> sessionCoroutineScope.launch { val latestEventId = room.liveTimeline.getLatestEventId().getOrElse { @@ -353,6 +394,23 @@ class TimelinePresenter( computeNewItemState(timelineItems, prevMostRecentItemId, newEventState) } + // Reconcile the selection when the items change: drop any selected event that is no longer + // present or no longer selectable, and exit selection mode if nothing remains selected. + LaunchedEffect(timelineItems.map { it.identifier() }) { + val active = selectionState as? SelectionState.Active ?: return@LaunchedEffect + val stillSelectable = timelineItems + .filterIsInstance() + .filter { it.canBeSelected() } + .mapNotNull { it.eventId } + .toSet() + val reconciled = active.selectedEventIds.filter { it in stillSelectable }.toPersistentSet() + selectionState = when { + reconciled.isEmpty() -> SelectionState.Disabled + reconciled.size != active.selectedEventIds.size -> SelectionState.Active(reconciled) + else -> active + } + } + // Keyed on the full [timelineItems] reference (not just .size) so we re-scan when the // read marker advances in place — the SDK swaps the marker virtual item to a new position // without changing the list length, e.g. when [markRoomAsFullyRead] is sent while at the @@ -463,6 +521,7 @@ class TimelinePresenter( displayThreadSummaries = displayThreadSummaries, displayJumpToUnread = displayJumpToUnread, jumpToUnread = jumpToUnread.value, + selectionState = selectionState, eventSink = ::handleEvent, ) } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt index 1ebc96f15f..6bd5aa0895 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt @@ -37,6 +37,7 @@ data class TimelineState( val displayThreadSummaries: Boolean, val displayJumpToUnread: Boolean, val jumpToUnread: JumpToUnreadState, + val selectionState: SelectionState, val eventSink: (TimelineEvent) -> Unit, ) { private val lastTimelineEvent = timelineItems.firstOrNull { it is TimelineItem.Event } as? TimelineItem.Event @@ -100,3 +101,14 @@ sealed interface JumpToUnreadState { /** The read marker event is older than the loaded window — load it via focused-event navigation. */ data class OutOfWindow(val eventId: EventId) : JumpToUnreadState } + +val TimelineState.isSelectionModeActive: Boolean + get() = selectionState is SelectionState.Active + +val TimelineState.selectedCount: Int + get() = (selectionState as? SelectionState.Active)?.selectedEventIds?.size ?: 0 + +fun TimelineState.isSelected(eventId: EventId?): Boolean { + if (eventId == null) return false + return (selectionState as? SelectionState.Active)?.selectedEventIds?.contains(eventId) == true +} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateProvider.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateProvider.kt index 89545b5d0b..5faea3de12 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateProvider.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateProvider.kt @@ -63,6 +63,7 @@ fun aTimelineState( displayJumpToUnread: Boolean = false, jumpToUnread: JumpToUnreadState = JumpToUnreadState.Hidden, newEventState: NewEventState = NewEventState.None, + selectionState: SelectionState = SelectionState.Disabled, eventSink: (TimelineEvent) -> Unit = {}, ): TimelineState { val focusedEventId = timelineItems.filterIsInstance().getOrNull(focusedEventIndex)?.eventId @@ -84,6 +85,7 @@ fun aTimelineState( displayThreadSummaries = displayThreadSummaries, displayJumpToUnread = displayJumpToUnread, jumpToUnread = jumpToUnread, + selectionState = selectionState, eventSink = eventSink, ) } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt index 5e7fd34723..0df9be3ca0 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt @@ -11,6 +11,7 @@ package io.element.android.features.messages.impl.timeline import android.view.HapticFeedbackConstants import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.MutableTransitionState +import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut @@ -83,14 +84,17 @@ import io.element.android.compound.tokens.generated.CompoundIcons import io.element.android.features.messages.impl.crypto.sendfailure.resolve.ResolveVerifiedUserSendFailureView import io.element.android.features.messages.impl.timeline.components.FloatingDateBadgeOverlay import io.element.android.features.messages.impl.timeline.components.TimelineItemRow +import io.element.android.features.messages.impl.timeline.components.TimelineItemSelectionData import io.element.android.features.messages.impl.timeline.components.toText import io.element.android.features.messages.impl.timeline.di.LocalTimelineItemPresenterFactories import io.element.android.features.messages.impl.timeline.di.aFakeTimelineItemPresenterFactories import io.element.android.features.messages.impl.timeline.focus.FocusRequestStateView import io.element.android.features.messages.impl.timeline.model.NewEventState import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.canBeSelected import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContentPreviewParam +import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemTextContent import io.element.android.features.messages.impl.timeline.protection.TimelineProtectionState import io.element.android.features.messages.impl.timeline.protection.aTimelineProtectionState import io.element.android.libraries.androidutils.system.copyToClipboard @@ -111,6 +115,7 @@ import io.element.android.libraries.testtags.testTag import io.element.android.libraries.ui.strings.CommonStrings import io.element.android.wysiwyg.link.Link import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.persistentSetOf import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.combine @@ -189,6 +194,18 @@ fun TimelineView( state.eventSink(TimelineEvent.LoadMore(Timeline.PaginationDirection.BACKWARDS)) } + val isSelectionModeActive = state.isSelectionModeActive + // Animate once here (shared by every row) rather than per-row: the value is identical for all + // rows since it only depends on the timeline-wide selection mode. + val selectionProgress by animateFloatAsState( + targetValue = if (isSelectionModeActive) 1f else 0f, + label = "selectionProgress", + ) + fun onToggleSelection(event: TimelineItem.Event) { + val eventId = event.eventId ?: return + state.eventSink(TimelineEvent.ToggleSelection(eventId)) + } + // Animate alpha when timeline is first displayed, to avoid flashes or glitching when viewing rooms AnimatedVisibility(visible = true, enter = fadeIn()) { Box(modifier) { @@ -214,12 +231,21 @@ fun TimelineView( isLastOutgoingMessage = state.isLastOutgoingMessage(timelineItem.identifier()), focusedEventId = state.focusedEventId, displayThreadSummaries = state.displayThreadSummaries, + selectionData = TimelineItemSelectionData( + isSelectionModeActive = isSelectionModeActive, + progress = selectionProgress, + isSelected = state.isSelected((timelineItem as? TimelineItem.Event)?.eventId), + ), onUserDataClick = onUserDataClick, onLinkClick = onLinkClick, onLinkLongClick = ::onLinkLongClick, - onContentClick = onContentClick, + onContentClick = { event -> + if (isSelectionModeActive && event.canBeSelected()) onToggleSelection(event) else onContentClick(event) + }, onGalleryItemClick = onGalleryItemClick, - onLongClick = onMessageLongClick, + onLongClick = { event -> + if (isSelectionModeActive && event.canBeSelected()) onToggleSelection(event) else onMessageLongClick(event) + }, inReplyToClick = ::inReplyToClick, onReactionClick = onReactionClick, onReactionLongClick = onReactionLongClick, @@ -616,6 +642,36 @@ internal fun TimelineViewPreview( } } +@PreviewsDayNight +@Composable +internal fun TimelineViewSelectionModePreview() = ElementPreview { + val timelineItems = aTimelineItemList(aTimelineItemTextContent()) + val selectedEventId = timelineItems.filterIsInstance().first { it.canBeSelected() }.eventId!! + CompositionLocalProvider( + LocalTimelineItemPresenterFactories provides aFakeTimelineItemPresenterFactories(), + ) { + TimelineView( + state = aTimelineState( + timelineItems = timelineItems, + selectionState = SelectionState.Active(persistentSetOf(selectedEventId)), + ), + timelineProtectionState = aTimelineProtectionState(), + onUserDataClick = {}, + onLinkClick = {}, + onContentClick = {}, + onMessageLongClick = {}, + onSwipeToReply = {}, + onReactionClick = { _, _ -> }, + onReactionLongClick = { _, _ -> }, + onJoinCallClick = {}, + onMoreReactionsClick = {}, + onReadReceiptClick = {}, + onGalleryItemClick = { _, _ -> }, + forceJumpToBottomVisibility = true, + ) + } +} + // The jump-to-unread FAB's indicator is always rendered when the FAB is visible — in // production the FAB only appears when unread content exists above. So `hasUnreadAbove` // here only varies the scroll-target state, not the upper indicator's visibility. diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt new file mode 100644 index 0000000000..e980b47155 --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2026 New Vector 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.messages.impl.timeline.components + +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import io.element.android.compound.theme.ElementTheme +import io.element.android.compound.tokens.generated.CompoundIcons +import io.element.android.libraries.designsystem.preview.ElementPreview +import io.element.android.libraries.designsystem.preview.PreviewsDayNight +import io.element.android.libraries.designsystem.theme.components.Icon + +/** + * Compact selection indicator used in the timeline selection mode, in place of a Material + * [androidx.compose.material3.Checkbox] (which reserves a 48dp interactive area). It is purely + * visual: the tap is handled by the whole-row click target, so this only reflects [selected]. + */ +@Composable +internal fun SelectionIndicator( + selected: Boolean, + modifier: Modifier = Modifier, +) { + Icon( + modifier = modifier, + imageVector = if (selected) CompoundIcons.CheckCircleSolid() else CompoundIcons.Circle(), + contentDescription = null, + tint = if (selected) ElementTheme.colors.iconAccentPrimary else ElementTheme.colors.iconTertiary, + ) +} + +@PreviewsDayNight +@Composable +internal fun SelectionIndicatorPreview() = ElementPreview { + Icon( + modifier = Modifier.size(24.dp), + imageVector = CompoundIcons.Circle(), + contentDescription = null, + tint = ElementTheme.colors.iconTertiary, + ) +} + +@PreviewsDayNight +@Composable +internal fun SelectionIndicatorSelectedPreview() = ElementPreview { + SelectionIndicator(selected = true) +} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt index 99e72f4973..d8a8473891 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemEventRow.kt @@ -24,6 +24,7 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.absoluteOffset import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width @@ -59,6 +60,7 @@ import androidx.compose.ui.semantics.traversalIndex import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDirection import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.IntOffset import androidx.compose.ui.unit.LayoutDirection @@ -180,6 +182,9 @@ fun TimelineItemEventRow( onSwipeToReply: () -> Unit, eventSink: (TimelineEvent.TimelineItemEvent) -> Unit, modifier: Modifier = Modifier, + // Horizontal offset applied to this row's content by selection mode. The read receipts are + // anchored to the end edge and should stay pinned, so they are counter-offset by this amount. + selectionContentOffset: Dp = 0.dp, eventContentView: @Composable (Modifier, (ContentAvoidingLayoutData) -> Unit) -> Unit = { contentModifier, onContentLayoutChange -> // Only pass down a custom clickable lambda if the content can be clicked separately val onContentClick = onEventClick.takeUnless { event.isWholeContentClickable } @@ -326,7 +331,10 @@ fun TimelineItemEventRow( receipts = event.readReceiptState.receipts, ), onReadReceiptsClick = { onReadReceiptClick(event) }, - modifier = Modifier.padding(top = 4.dp) + // Counter the selection-mode content slide so the end-anchored read receipts stay pinned. + modifier = Modifier + .padding(top = 4.dp) + .offset(x = -selectionContentOffset) ) } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemGroupedEventsRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemGroupedEventsRow.kt index 5b620a7dc3..7094e302f8 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemGroupedEventsRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemGroupedEventsRow.kt @@ -190,6 +190,7 @@ private fun TimelineItemGroupedEventsRowContent( onSwipeToReply = {}, eventSink = eventSink, eventContentView = eventContentView, + selectionData = TimelineItemSelectionData(), ) } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt index fb9659ff70..7f08aa465e 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt @@ -8,22 +8,30 @@ package io.element.android.features.messages.impl.timeline.components +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawWithCache import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.isTraversalGroup import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import io.element.android.compound.theme.ElementTheme import io.element.android.features.messages.impl.timeline.TimelineEvent @@ -31,6 +39,7 @@ import io.element.android.features.messages.impl.timeline.TimelineRoomInfo import io.element.android.features.messages.impl.timeline.components.event.TimelineItemEventContentView import io.element.android.features.messages.impl.timeline.components.layout.ContentAvoidingLayoutData import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.canBeSelected import io.element.android.features.messages.impl.timeline.model.event.RtcNotificationState import io.element.android.features.messages.impl.timeline.model.event.TimelineItemLegacyCallInviteContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemPollContent @@ -60,6 +69,7 @@ internal fun TimelineItemRow( timelineProtectionState: TimelineProtectionState, focusedEventId: EventId?, displayThreadSummaries: Boolean, + selectionData: TimelineItemSelectionData, onUserDataClick: (MatrixUser) -> Unit, onLinkClick: (Link) -> Unit, onLinkLongClick: (Link) -> Unit, @@ -92,17 +102,130 @@ internal fun TimelineItemRow( ) }, ) { - val backgroundModifier = if (timelineItem.isEvent(focusedEventId)) { - val focusedEventOffset = if ((timelineItem as? TimelineItem.Event)?.showSenderInformation == true) { - 14.dp - } else { - 2.dp + val isSelectionModeActive = selectionData.isSelectionModeActive + val selectionProgress = selectionData.progress + val isSelected = selectionData.isSelected + val backgroundModifier = when { + isSelected -> { + Modifier.background(ElementTheme.colors.bgAccentSelected) + } + timelineItem.isEvent(focusedEventId) -> { + val focusedEventOffset = + if ((timelineItem as? TimelineItem.Event)?.showSenderInformation == true) { + 14.dp + } else { + 2.dp + } + Modifier.focusedEvent(focusedEventOffset) + } + else -> { + Modifier } - Modifier.focusedEvent(focusedEventOffset) - } else { - Modifier } - Box(modifier = modifier.then(backgroundModifier)) { + val selectableEvent = (timelineItem as? TimelineItem.Event)?.takeIf { it.canBeSelected() } + // Only start-aligned message bubbles slide to make room for the selection indicator: + // - Outgoing (own) messages are end-aligned, opposite the indicator, so they already have room. + // - Centered tiles (state events, call tiles, day dividers, grouped events) must stay put. + val isOutgoing = (timelineItem as? TimelineItem.Event)?.isMine == true + val shouldSlideContent = timelineItem.rendersAsBubble() && !isOutgoing + val layoutDirection = LocalLayoutDirection.current + val contentSlide = if (shouldSlideContent) SELECTION_COLUMN_WIDTH * selectionProgress else 0.dp + Box( + modifier = modifier.then(backgroundModifier) + ) { + TimelineItemRowContent( + modifier = Modifier + .fillMaxWidth() + .offset(x = contentSlide), + selectionContentOffset = contentSlide, + timelineItem = timelineItem, + timelineMode = timelineMode, + timelineRoomInfo = timelineRoomInfo, + timelineProtectionState = timelineProtectionState, + isLastOutgoingMessage = isLastOutgoingMessage, + focusedEventId = focusedEventId, + displayThreadSummaries = displayThreadSummaries, + onUserDataClick = onUserDataClick, + onLinkClick = onLinkClick, + onLinkLongClick = onLinkLongClick, + onContentClick = onContentClick, + onGalleryItemClick = onGalleryItemClick, + onLongClick = onLongClick, + inReplyToClick = inReplyToClick, + onReactionClick = onReactionClick, + onReactionLongClick = onReactionLongClick, + onMoreReactionsClick = onMoreReactionsClick, + onReadReceiptClick = onReadReceiptClick, + onJoinCallClick = onJoinCallClick, + onSwipeToReply = onSwipeToReply, + eventSink = eventSink, + eventContentView = eventContentView, + ) + if (selectableEvent != null && selectionProgress > 0f) { + val slideSign = if (layoutDirection == LayoutDirection.Ltr) -1f else 1f + SelectionIndicator( + selected = isSelected, + modifier = Modifier + .align(Alignment.CenterStart) + .graphicsLayer { translationX = slideSign * SELECTION_COLUMN_WIDTH.toPx() * (1f - selectionProgress) } + .padding(start = 12.dp) + .size(24.dp), + ) + } + if (isSelectionModeActive && selectableEvent != null) { + // In selection mode the whole row toggles selection. + Box( + modifier = Modifier + .matchParentSize() + .clickable { onContentClick(selectableEvent) } + ) + } + } +} + +/** Width reserved for the selection indicator; the row content slides by this amount. */ +private val SELECTION_COLUMN_WIDTH = 36.dp + +/** + * Whether this item is rendered as a start/end-aligned message bubble, as opposed to a centered + * tile (state event, legacy call invite, call/RTC notification, day divider, grouped events). + * Mirrors the dispatch in [TimelineItemRowContent]: only bubbles shift to reveal the selection + * indicator; centered tiles stay put. + */ +private fun TimelineItem.rendersAsBubble(): Boolean = this is TimelineItem.Event && + content !is TimelineItemStateContent && + content !is TimelineItemLegacyCallInviteContent && + content !is TimelineItemRtcNotificationContent + +@Suppress("LongMethod") +@Composable +private fun TimelineItemRowContent( + timelineItem: TimelineItem, + timelineMode: Timeline.Mode, + timelineRoomInfo: TimelineRoomInfo, + isLastOutgoingMessage: Boolean, + timelineProtectionState: TimelineProtectionState, + focusedEventId: EventId?, + displayThreadSummaries: Boolean, + onUserDataClick: (MatrixUser) -> Unit, + onLinkClick: (Link) -> Unit, + onLinkLongClick: (Link) -> Unit, + onContentClick: (TimelineItem.Event) -> Unit, + onGalleryItemClick: (TimelineItem.Event, Int) -> Unit, + onLongClick: (TimelineItem.Event) -> Unit, + inReplyToClick: (EventId) -> Unit, + onReactionClick: (key: String, TimelineItem.Event) -> Unit, + onReactionLongClick: (key: String, TimelineItem.Event) -> Unit, + onMoreReactionsClick: (TimelineItem.Event) -> Unit, + onReadReceiptClick: (TimelineItem.Event) -> Unit, + onJoinCallClick: (isAudioCall: Boolean) -> Unit, + onSwipeToReply: (TimelineItem.Event) -> Unit, + eventSink: (TimelineEvent.TimelineItemEvent) -> Unit, + eventContentView: @Composable (TimelineItem.Event, Modifier, (ContentAvoidingLayoutData) -> Unit) -> Unit, + modifier: Modifier = Modifier, + selectionContentOffset: Dp = 0.dp, +) { + Box(modifier) { when (timelineItem) { is TimelineItem.Virtual -> { TimelineItemVirtualRow( @@ -197,6 +320,7 @@ internal fun TimelineItemRow( onSwipeToReply = { onSwipeToReply(timelineItem) }, onGalleryItemClick = { index -> onGalleryItemClick(timelineItem, index) }, eventSink = eventSink, + selectionContentOffset = selectionContentOffset, eventContentView = { contentModifier, onContentLayoutChange -> eventContentView(timelineItem, contentModifier, onContentLayoutChange) }, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemSelectionData.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemSelectionData.kt new file mode 100644 index 0000000000..f8de354aac --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemSelectionData.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2026 New Vector 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.messages.impl.timeline.components + +/** + * Row-scoped selection state passed to [TimelineItemRow]. + * + * @param isSelectionModeActive whether the timeline is currently in selection mode. Drives + * behaviour (e.g. the whole-row click target) and must reflect the real mode, not [progress]. + * @param progress animated 0f..1f value driving the visuals (content slide + indicator slide-in). + * Animated once in TimelineView and shared by every row. Differs from [isSelectionModeActive] + * during the enter/exit animation. + * @param isSelected whether this specific row's event is part of the current selection. + */ +data class TimelineItemSelectionData( + val isSelectionModeActive: Boolean = false, + val isSelected: Boolean = false, + val progress: Float = 0f, +) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelection.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelection.kt new file mode 100644 index 0000000000..9f11e86213 --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelection.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2026 New Vector 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.messages.impl.timeline.model + +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEncryptedContent +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemLegacyCallInviteContent +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemLocationContent +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemRedactedContent +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemRtcNotificationContent +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemStateContent +import io.element.android.features.messages.impl.timeline.model.event.TimelineItemUnknownContent + +/** + * Whether this timeline event can be selected in multi-select ("selection") mode. + */ +fun TimelineItem.Event.canBeSelected(): Boolean { + // Local echoes (no remote eventId) and failed sends are never selectable. + if (!isRemote || failedToSend) return false + return when (content) { + is TimelineItemStateContent, + is TimelineItemRedactedContent, + is TimelineItemEncryptedContent, + is TimelineItemLegacyCallInviteContent, + is TimelineItemRtcNotificationContent, + is TimelineItemLocationContent, + is TimelineItemUnknownContent -> false + else -> true + } +} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt new file mode 100644 index 0000000000..55563d1f1b --- /dev/null +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt @@ -0,0 +1,59 @@ +/* + * Copyright 2026 New Vector 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.messages.impl.topbars + +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.pluralStringResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import io.element.android.compound.tokens.generated.CompoundIcons +import io.element.android.features.messages.impl.R +import io.element.android.libraries.designsystem.preview.ElementPreview +import io.element.android.libraries.designsystem.preview.PreviewsDayNight +import io.element.android.libraries.designsystem.theme.components.Icon +import io.element.android.libraries.designsystem.theme.components.IconButton +import io.element.android.libraries.designsystem.theme.components.Text +import io.element.android.libraries.designsystem.theme.components.TopAppBar +import io.element.android.libraries.ui.strings.CommonStrings + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun SelectionModeTopBar( + selectedCount: Int, + onCancelClick: () -> Unit, + modifier: Modifier = Modifier, +) { + TopAppBar( + modifier = modifier, + title = { + Text(text = pluralStringResource(R.plurals.screen_room_timeline_selection_title, selectedCount, selectedCount)) + }, + navigationIcon = { + IconButton( + onClick = onCancelClick, + ) { + Icon(imageVector = CompoundIcons.Close(), contentDescription = stringResource(CommonStrings.action_close)) + } + }, + ) +} + +@PreviewsDayNight +@Composable +internal fun SelectionModeTopBarPreview( + @PreviewParameter(SelectionCountProvider::class) count: Int, +) = ElementPreview { + SelectionModeTopBar(selectedCount = count, onCancelClick = {}) +} + +internal class SelectionCountProvider : PreviewParameterProvider { + override val values = sequenceOf(0, 1, 5) +} diff --git a/features/messages/impl/src/main/res/values/temporary.xml b/features/messages/impl/src/main/res/values/temporary.xml new file mode 100644 index 0000000000..5dfeaa7b85 --- /dev/null +++ b/features/messages/impl/src/main/res/values/temporary.xml @@ -0,0 +1,15 @@ + + + + + + %1$d selected + %1$d selected + + You can select up to 30 messages + diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenterTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenterTest.kt index e987a32480..2988fbe894 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenterTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenterTest.kt @@ -70,6 +70,44 @@ class ActionListPresenterTest { } } + @Test + fun `present - Select action is present for a remote message when multi-select is enabled`() = runTest { + val presenter = createActionListPresenter( + isDeveloperModeEnabled = false, + featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to true)), + ) + presenter.test { + val initialState = awaitItem() + initialState.eventSink.invoke( + ActionListEvent.ComputeForMessage( + event = aMessageEvent(), + userEventPermissions = aUserEventPermissions(canSendMessage = true), + ) + ) + val successState = awaitItem() + assertThat((successState.target as ActionListState.Target.Success).actions).contains(TimelineItemAction.Select) + } + } + + @Test + fun `present - Select action is absent when multi-select is disabled`() = runTest { + val presenter = createActionListPresenter( + isDeveloperModeEnabled = false, + featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to false)), + ) + presenter.test { + val initialState = awaitItem() + initialState.eventSink.invoke( + ActionListEvent.ComputeForMessage( + event = aMessageEvent(), + userEventPermissions = aUserEventPermissions(canSendMessage = true), + ) + ) + val successState = awaitItem() + assertThat((successState.target as ActionListState.Target.Success).actions).doesNotContain(TimelineItemAction.Select) + } + } + @Test fun `present - compute for message from me redacted`() = runTest { val presenter = createActionListPresenter(isDeveloperModeEnabled = true) diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt index 290246ffb9..6dcf107e0b 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt @@ -34,6 +34,7 @@ import io.element.android.features.poll.test.actions.FakeEndPollAction import io.element.android.features.poll.test.actions.FakeSendPollResponseAction import io.element.android.features.roomcall.api.aStandByCallState import io.element.android.libraries.architecture.Presenter +import io.element.android.libraries.designsystem.utils.snackbar.SnackbarDispatcher import io.element.android.libraries.featureflag.api.FeatureFlags import io.element.android.libraries.featureflag.test.FakeFeatureFlagService import io.element.android.libraries.matrix.api.core.EventId @@ -86,6 +87,7 @@ import io.element.android.tests.testutils.lambda.value import io.element.android.tests.testutils.test import io.element.android.tests.testutils.testCoroutineDispatchers import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.persistentSetOf import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.delay @@ -1821,6 +1823,80 @@ class TimelinePresenterTest { } } + @Test + fun `present - entering selection mode selects the target event`() = runTest { + val timelineItems = MutableStateFlow( + listOf(MatrixTimelineItem.Event(UniqueId("1"), anEventTimelineItem(eventId = AN_EVENT_ID, content = aMessageContent()))) + ) + val presenter = createTimelinePresenter( + timeline = FakeTimeline(timelineItems = timelineItems), + featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to true)), + ) + presenter.test { + val initialState = consumeItemsUntilPredicate { it.hasAnyEvent }.last() + assertThat(initialState.selectionState).isEqualTo(SelectionState.Disabled) + initialState.eventSink(TimelineEvent.EnterSelectionMode(AN_EVENT_ID)) + val state = consumeItemsUntilPredicate { it.isSelectionModeActive }.last() + assertThat(state.selectionState).isEqualTo(SelectionState.Active(persistentSetOf(AN_EVENT_ID))) + assertThat(state.selectedCount).isEqualTo(1) + cancelAndIgnoreRemainingEvents() + } + } + + @Test + fun `present - entering selection mode is ignored when the flag is off`() = runTest { + val featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to false)) + val presenter = createTimelinePresenter(featureFlagService = featureFlagService) + presenter.test { + val initialState = awaitFirstItem() + initialState.eventSink(TimelineEvent.EnterSelectionMode(AN_EVENT_ID)) + expectNoEvents() + assertThat(initialState.selectionState).isEqualTo(SelectionState.Disabled) + cancelAndIgnoreRemainingEvents() + } + } + + @Test + fun `present - toggling the last selected event exits selection mode`() = runTest { + val timelineItems = MutableStateFlow( + listOf(MatrixTimelineItem.Event(UniqueId("1"), anEventTimelineItem(eventId = AN_EVENT_ID, content = aMessageContent()))) + ) + val presenter = createTimelinePresenter( + timeline = FakeTimeline(timelineItems = timelineItems), + featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to true)), + ) + presenter.test { + val initialState = consumeItemsUntilPredicate { it.hasAnyEvent }.last() + initialState.eventSink(TimelineEvent.EnterSelectionMode(AN_EVENT_ID)) + consumeItemsUntilPredicate { it.isSelectionModeActive } + initialState.eventSink(TimelineEvent.ToggleSelection(AN_EVENT_ID)) + val state = consumeItemsUntilPredicate { !it.isSelectionModeActive }.last() + assertThat(state.selectionState).isEqualTo(SelectionState.Disabled) + cancelAndIgnoreRemainingEvents() + } + } + + @Test + fun `present - turning the flag off clears the active selection`() = runTest { + val timelineItems = MutableStateFlow( + listOf(MatrixTimelineItem.Event(UniqueId("1"), anEventTimelineItem(eventId = AN_EVENT_ID, content = aMessageContent()))) + ) + val featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to true)) + val presenter = createTimelinePresenter( + timeline = FakeTimeline(timelineItems = timelineItems), + featureFlagService = featureFlagService, + ) + presenter.test { + val initialState = consumeItemsUntilPredicate { it.hasAnyEvent }.last() + initialState.eventSink(TimelineEvent.EnterSelectionMode(AN_EVENT_ID)) + consumeItemsUntilPredicate { it.isSelectionModeActive } + featureFlagService.setFeatureEnabled(FeatureFlags.MessageMultiSelect, false) + val state = consumeItemsUntilPredicate { !it.isSelectionModeActive }.last() + assertThat(state.selectionState).isEqualTo(SelectionState.Disabled) + cancelAndIgnoreRemainingEvents() + } + } + private suspend fun ReceiveTurbine.awaitFirstItem(): T { return awaitItem() } @@ -1911,6 +1987,7 @@ class TimelinePresenterTest { typingNotificationPresenter = { aTypingNotificationState() }, roomCallStatePresenter = { aStandByCallState() }, featureFlagService = featureFlagService, + snackbarDispatcher = SnackbarDispatcher(), analyticsService = FakeAnalyticsService(), liveLocationShareManager = liveLocationShareManager, markAsFullyRead = markAsFullyRead, diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionTest.kt new file mode 100644 index 0000000000..e293246900 --- /dev/null +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionTest.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2026 New Vector 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.messages.impl.timeline.model + +import com.google.common.truth.Truth.assertThat +import io.element.android.features.messages.impl.timeline.aTimelineItemEvent +import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemRedactedContent +import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemStateEventContent +import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState +import org.junit.Test + +class TimelineItemSelectionTest { + @Test + fun `a remote text message can be selected`() { + val item = aTimelineItemEvent() + assertThat(item.canBeSelected()).isTrue() + } + + @Test + fun `a local echo cannot be selected`() { + val item = aTimelineItemEvent().copy(eventId = null) + assertThat(item.canBeSelected()).isFalse() + } + + @Test + fun `a failed to send message cannot be selected`() { + val item = aTimelineItemEvent(sendState = LocalEventSendState.Failed.Unknown("failed")) + assertThat(item.canBeSelected()).isFalse() + } + + @Test + fun `a state event cannot be selected`() { + val item = aTimelineItemEvent(content = aTimelineItemStateEventContent()) + assertThat(item.canBeSelected()).isFalse() + } + + @Test + fun `a redacted event cannot be selected`() { + val item = aTimelineItemEvent(content = aTimelineItemRedactedContent()) + assertThat(item.canBeSelected()).isFalse() + } +} diff --git a/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt b/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt index af7ccef97f..a50ebce5d7 100644 --- a/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt +++ b/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt @@ -161,4 +161,11 @@ enum class FeatureFlags( defaultValue = { false }, isFinished = false, ), + MessageMultiSelect( + key = "feature.message_multi_select", + title = "Multi-select messages", + description = "Adds a Select action to the message menu to pick several messages at once.", + defaultValue = { false }, + isFinished = false, + ), } From 93831ffcbce22831fbd191f62b5014db615f7e66 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 25 Sep 2026 18:47:17 +0200 Subject: [PATCH 02/22] Forward several events at once --- .../features/forward/api/ForwardEntryPoint.kt | 2 +- .../forward/impl/DefaultForwardEntryPoint.kt | 2 +- .../forward/impl/ForwardMessagesNode.kt | 4 +-- .../forward/impl/ForwardMessagesPresenter.kt | 16 ++++----- .../impl/DefaultForwardEntryPointTest.kt | 4 +-- .../impl/ForwardMessagesPresenterTest.kt | 16 ++++----- .../libraries/matrix/api/timeline/Timeline.kt | 9 ++--- .../matrix/impl/room/RoomContentForwarder.kt | 36 ++++++++++--------- .../impl/timeline/RoomTimelineExtensions.kt | 13 ------- .../matrix/impl/timeline/RustTimeline.kt | 4 +-- .../matrix/test/timeline/FakeTimeline.kt | 6 ++-- 11 files changed, 50 insertions(+), 62 deletions(-) diff --git a/features/forward/api/src/main/kotlin/io/element/android/features/forward/api/ForwardEntryPoint.kt b/features/forward/api/src/main/kotlin/io/element/android/features/forward/api/ForwardEntryPoint.kt index 95b8c43808..bbc3915c86 100644 --- a/features/forward/api/src/main/kotlin/io/element/android/features/forward/api/ForwardEntryPoint.kt +++ b/features/forward/api/src/main/kotlin/io/element/android/features/forward/api/ForwardEntryPoint.kt @@ -23,7 +23,7 @@ interface ForwardEntryPoint : FeatureEntryPoint { } data class Params( - val eventId: EventId, + val eventIds: List, val timelineProvider: TimelineProvider, ) : NodeInputs diff --git a/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/DefaultForwardEntryPoint.kt b/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/DefaultForwardEntryPoint.kt index 97256c6576..e46e268a55 100644 --- a/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/DefaultForwardEntryPoint.kt +++ b/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/DefaultForwardEntryPoint.kt @@ -27,7 +27,7 @@ class DefaultForwardEntryPoint : ForwardEntryPoint { buildContext = buildContext, plugins = listOf( ForwardMessagesNode.Inputs( - eventId = params.eventId, + eventIds = params.eventIds, timelineProvider = params.timelineProvider, ), callback, diff --git a/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/ForwardMessagesNode.kt b/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/ForwardMessagesNode.kt index 1c565a390a..30a48c91de 100644 --- a/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/ForwardMessagesNode.kt +++ b/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/ForwardMessagesNode.kt @@ -52,13 +52,13 @@ class ForwardMessagesNode( object NavTarget : Parcelable data class Inputs( - val eventId: EventId, + val eventIds: List, val timelineProvider: TimelineProvider, ) : NodeInputs private val inputs = inputs() private val callback: ForwardEntryPoint.Callback = callback() - private val presenter = presenterFactory.create(inputs.eventId.value, inputs.timelineProvider) + private val presenter = presenterFactory.create(inputs.eventIds, inputs.timelineProvider) override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node { val callback = object : RoomSelectEntryPoint.Callback { diff --git a/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/ForwardMessagesPresenter.kt b/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/ForwardMessagesPresenter.kt index 6068866653..a36be20ab4 100644 --- a/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/ForwardMessagesPresenter.kt +++ b/features/forward/impl/src/main/kotlin/io/element/android/features/forward/impl/ForwardMessagesPresenter.kt @@ -28,22 +28,20 @@ import timber.log.Timber @AssistedInject class ForwardMessagesPresenter( - @Assisted eventId: String, + @Assisted private val eventIds: List, @Assisted private val timelineProvider: TimelineProvider, @SessionCoroutineScope private val sessionCoroutineScope: CoroutineScope, ) : Presenter { - private val eventId: EventId = EventId(eventId) - @AssistedFactory fun interface Factory { - fun create(eventId: String, timelineProvider: TimelineProvider): ForwardMessagesPresenter + fun create(eventIds: List, timelineProvider: TimelineProvider): ForwardMessagesPresenter } private val forwardingActionState: MutableState>> = mutableStateOf(AsyncAction.Uninitialized) fun onRoomSelected(roomIds: List) { - sessionCoroutineScope.forwardEvent(eventId, roomIds) + sessionCoroutineScope.forwardEvents(eventIds, roomIds) } @Composable @@ -60,14 +58,14 @@ class ForwardMessagesPresenter( ) } - private fun CoroutineScope.forwardEvent( - eventId: EventId, + private fun CoroutineScope.forwardEvents( + eventIds: List, roomIds: List, ) = launch { suspend { - timelineProvider.getActiveTimeline().forwardEvent(eventId, roomIds) + timelineProvider.getActiveTimeline().forwardEvents(eventIds, roomIds) .onFailure { - Timber.e(it, "Error while forwarding event") + Timber.e(it, "Error while forwarding events") } .getOrThrow() roomIds diff --git a/features/forward/impl/src/test/kotlin/io/element/android/features/forward/impl/DefaultForwardEntryPointTest.kt b/features/forward/impl/src/test/kotlin/io/element/android/features/forward/impl/DefaultForwardEntryPointTest.kt index 9ee932a246..c082e4ecd3 100644 --- a/features/forward/impl/src/test/kotlin/io/element/android/features/forward/impl/DefaultForwardEntryPointTest.kt +++ b/features/forward/impl/src/test/kotlin/io/element/android/features/forward/impl/DefaultForwardEntryPointTest.kt @@ -45,7 +45,7 @@ class DefaultForwardEntryPointTest { override fun onDone(roomIds: List) = lambdaError() } val params = ForwardEntryPoint.Params( - eventId = AN_EVENT_ID, + eventIds = listOf(AN_EVENT_ID), timelineProvider = FakeTimelineProvider(), ) val result = entryPoint.createNode( @@ -57,7 +57,7 @@ class DefaultForwardEntryPointTest { assertThat(result).isInstanceOf(ForwardMessagesNode::class.java) assertThat(result.plugins).contains( ForwardMessagesNode.Inputs( - eventId = params.eventId, + eventIds = params.eventIds, timelineProvider = params.timelineProvider, ) ) diff --git a/features/forward/impl/src/test/kotlin/io/element/android/features/forward/impl/ForwardMessagesPresenterTest.kt b/features/forward/impl/src/test/kotlin/io/element/android/features/forward/impl/ForwardMessagesPresenterTest.kt index 0ff3210f2e..5fda2e252c 100644 --- a/features/forward/impl/src/test/kotlin/io/element/android/features/forward/impl/ForwardMessagesPresenterTest.kt +++ b/features/forward/impl/src/test/kotlin/io/element/android/features/forward/impl/ForwardMessagesPresenterTest.kt @@ -44,11 +44,11 @@ class ForwardMessagesPresenterTest { @Test fun `present - forward successful`() = runTest { - val forwardEventLambda = lambdaRecorder { _: EventId, _: List -> + val forwardEventsLambda = lambdaRecorder { _: List, _: List -> Result.success(Unit) } val timeline = FakeTimeline().apply { - this.forwardEventLambda = forwardEventLambda + this.forwardEventsLambda = forwardEventsLambda } val room = FakeJoinedRoom(liveTimeline = timeline) val presenter = createForwardMessagesPresenter(fakeRoom = room) @@ -62,17 +62,17 @@ class ForwardMessagesPresenterTest { assertThat(forwardingState.forwardAction.isLoading()).isTrue() val successfulForwardState = awaitItem() assertThat(successfulForwardState.forwardAction).isEqualTo(AsyncAction.Success(listOf(summary.roomId))) - forwardEventLambda.assertions().isCalledOnce() + forwardEventsLambda.assertions().isCalledOnce() } } @Test fun `present - select a room and forward failed, then clear`() = runTest { - val forwardEventLambda = lambdaRecorder { _: EventId, _: List -> + val forwardEventsLambda = lambdaRecorder { _: List, _: List -> Result.failure(IllegalStateException("error")) } val timeline = FakeTimeline().apply { - this.forwardEventLambda = forwardEventLambda + this.forwardEventsLambda = forwardEventsLambda } val room = FakeJoinedRoom(liveTimeline = timeline) val presenter = createForwardMessagesPresenter(fakeRoom = room) @@ -88,16 +88,16 @@ class ForwardMessagesPresenterTest { // Then clear error failedForwardState.eventSink(ForwardMessagesEvent.ClearError) assertThat(awaitItem().forwardAction.isUninitialized()).isTrue() - forwardEventLambda.assertions().isCalledOnce() + forwardEventsLambda.assertions().isCalledOnce() } } } fun TestScope.createForwardMessagesPresenter( - eventId: EventId = AN_EVENT_ID, + eventIds: List = listOf(AN_EVENT_ID), fakeRoom: FakeJoinedRoom = FakeJoinedRoom(), ) = ForwardMessagesPresenter( - eventId = eventId.value, + eventIds = eventIds, timelineProvider = LiveTimelineProvider(fakeRoom), sessionCoroutineScope = this, ) diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/timeline/Timeline.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/timeline/Timeline.kt index 72483e68f1..51a8964aa0 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/timeline/Timeline.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/timeline/Timeline.kt @@ -316,12 +316,13 @@ interface Timeline : AutoCloseable { suspend fun toggleReaction(emoji: String, eventOrTransactionId: EventOrTransactionId): Result /** - * Forwards the content of an event to other rooms, as new messages sent by the current user. + * Forwards the content of some events to other rooms, as new messages sent by the current user. + * The events are forwarded in the order of [eventIds]. * - * @param eventId the event whose content is forwarded. - * @param roomIds the rooms to forward it to. + * @param eventIds the events whose content is forwarded. + * @param roomIds the rooms to forward them to. */ - suspend fun forwardEvent(eventId: EventId, roomIds: List): Result + suspend fun forwardEvents(eventIds: List, roomIds: List): Result /** * Cancels an event that is still waiting in the send queue, by redacting its local echo. diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RoomContentForwarder.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RoomContentForwarder.kt index 39cde68c31..8191082806 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RoomContentForwarder.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/room/RoomContentForwarder.kt @@ -14,7 +14,6 @@ import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.matrix.api.core.RoomId import io.element.android.libraries.matrix.api.room.ForwardEventException import io.element.android.libraries.matrix.impl.roomlist.roomOrNull -import io.element.android.libraries.matrix.impl.timeline.runWithTimelineListenerRegistered import kotlinx.coroutines.withTimeout import org.matrix.rustcomponents.sdk.MsgLikeKind import org.matrix.rustcomponents.sdk.RoomListService @@ -31,33 +30,36 @@ class RoomContentForwarder( private val roomListService: RoomListService, ) { /** - * Forwards the event with the given [eventId] from the [fromTimeline] to the given [toRoomIds]. - * @param fromTimeline the room to forward the event from - * @param eventId the id of the event to forward - * @param toRoomIds the ids of the rooms to forward the event to - * @param timeoutMs the maximum time in milliseconds to wait for the event to be sent to a room + * Forwards the events with the given [eventIds] from the [fromTimeline] to the given [toRoomIds]. + * The events are sent to each room in the order they are provided in [eventIds], it is up to the caller to sort them. + * @param fromTimeline the room to forward the events from + * @param eventIds the ids of the events to forward, in the order they must be sent + * @param toRoomIds the ids of the rooms to forward the events to + * @param timeoutMs the maximum time in milliseconds to wait for an event to be sent to a room */ suspend fun forward( fromTimeline: Timeline, - eventId: EventId, + eventIds: List, toRoomIds: List, timeoutMs: Long = 5000L ) { - val messageLikeContent = (fromTimeline.getEventTimelineItemByEventId(eventId.value).content as? TimelineItemContent.MsgLike)?.content - ?: throw ForwardEventException(toRoomIds) - - val content = (messageLikeContent.kind as? MsgLikeKind.Message)?.content - ?: throw ForwardEventException(toRoomIds) - + val contents = eventIds.map { eventId -> + val timelineEvent = fromTimeline.getEventTimelineItemByEventId(eventId.value) + val content = timelineEvent.content as? TimelineItemContent.MsgLike ?: throw ForwardEventException(toRoomIds) + val message = content.content.kind as? MsgLikeKind.Message ?: throw ForwardEventException(toRoomIds) + contentWithoutRelationFromMessage(message.content) + } val targetRooms = toRoomIds.toSet().mapNotNull { roomId -> roomListService.roomOrNull(roomId.value) } val failedForwardingTo = mutableSetOf() targetRooms.parallelMap { room -> room.use { targetRoom -> runCatchingExceptions { - // Sending a message requires a registered timeline listener - targetRoom.timeline().runWithTimelineListenerRegistered { - withTimeout(timeoutMs.milliseconds) { - targetRoom.timeline().send(contentWithoutRelationFromMessage(content)) + targetRoom.timeline().use { timeline -> + // Send the contents sequentially, so that they are received in the same order + contents.forEach { content -> + withTimeout(timeoutMs.milliseconds) { + timeline.send(content) + } } } } diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RoomTimelineExtensions.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RoomTimelineExtensions.kt index c932230217..9766da8235 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RoomTimelineExtensions.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RoomTimelineExtensions.kt @@ -53,16 +53,3 @@ internal fun TimelineInterface.timelineDiffFlow(): Flow> = }.catch { Timber.d(it, "timelineDiffFlow() failed") }.buffer(Channel.UNLIMITED) - -internal suspend fun TimelineInterface.runWithTimelineListenerRegistered(action: suspend () -> Unit) { - val result = addListener(NoOpTimelineListener) - try { - action() - } finally { - result.cancelAndDestroy() - } -} - -private object NoOpTimelineListener : TimelineListener { - override fun onUpdate(diff: List) = Unit -} diff --git a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt index c6a737e156..c7dd260d47 100644 --- a/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt +++ b/libraries/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/timeline/RustTimeline.kt @@ -489,9 +489,9 @@ class RustTimeline( } } - override suspend fun forwardEvent(eventId: EventId, roomIds: List): Result = withContext(dispatcher) { + override suspend fun forwardEvents(eventIds: List, roomIds: List): Result = withContext(dispatcher) { runCatchingExceptions { - roomContentForwarder.forward(fromTimeline = inner, eventId = eventId, toRoomIds = roomIds) + roomContentForwarder.forward(fromTimeline = inner, eventIds = eventIds, toRoomIds = roomIds) }.onFailure { Timber.tag(loggerTag).e(it) } diff --git a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/timeline/FakeTimeline.kt b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/timeline/FakeTimeline.kt index d13ac06bd3..88dcb13a8c 100644 --- a/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/timeline/FakeTimeline.kt +++ b/libraries/matrix/test/src/main/kotlin/io/element/android/libraries/matrix/test/timeline/FakeTimeline.kt @@ -355,10 +355,10 @@ class FakeTimeline( ) } - var forwardEventLambda: (eventId: EventId, roomIds: List) -> Result = { _, _ -> lambdaError() } + var forwardEventsLambda: (eventIds: List, roomIds: List) -> Result = { _, _ -> lambdaError() } - override suspend fun forwardEvent(eventId: EventId, roomIds: List): Result = simulateLongTask { - forwardEventLambda(eventId, roomIds) + override suspend fun forwardEvents(eventIds: List, roomIds: List): Result = simulateLongTask { + forwardEventsLambda(eventIds, roomIds) } var createPollLambda: ( From a0bfdd379c41dcf3868986777afb20faf30b077f Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 25 Sep 2026 18:47:17 +0200 Subject: [PATCH 03/22] Pass a list of event ids to the forward screen --- .../appnav/room/joined/JoinedRoomLoadedFlowNode.kt | 2 +- .../features/messages/impl/MessagesFlowNode.kt | 14 +++++++------- .../features/messages/impl/MessagesNavigator.kt | 2 +- .../android/features/messages/impl/MessagesNode.kt | 6 +++--- .../messages/impl/threads/ThreadedMessagesNode.kt | 6 +++--- .../messages/impl/FakeMessagesNavigator.kt | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/appnav/src/main/kotlin/io/element/android/appnav/room/joined/JoinedRoomLoadedFlowNode.kt b/appnav/src/main/kotlin/io/element/android/appnav/room/joined/JoinedRoomLoadedFlowNode.kt index dbe53b75ac..7205d095b4 100644 --- a/appnav/src/main/kotlin/io/element/android/appnav/room/joined/JoinedRoomLoadedFlowNode.kt +++ b/appnav/src/main/kotlin/io/element/android/appnav/room/joined/JoinedRoomLoadedFlowNode.kt @@ -201,7 +201,7 @@ class JoinedRoomLoadedFlowNode( } else { (graph as TimelineBindings).timelineProvider } - val params = ForwardEntryPoint.Params(navTarget.eventId, timelineProvider) + val params = ForwardEntryPoint.Params(listOf(navTarget.eventId), timelineProvider) val callback = object : ForwardEntryPoint.Callback { override fun onDone(roomIds: List) { backstack.pop() diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt index 88a90f6c7d..4c86c75dd8 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesFlowNode.kt @@ -179,7 +179,7 @@ class MessagesFlowNode( @Parcelize data class ForwardEvent( - val eventId: EventId, + val eventIds: List, val fromPinnedEvents: Boolean, ) : NavTarget @@ -303,8 +303,8 @@ class MessagesFlowNode( backstack.push(NavTarget.EventDebugInfo(eventId, debugInfo)) } - override fun forwardEvent(eventId: EventId) { - backstack.push(NavTarget.ForwardEvent(eventId, fromPinnedEvents = false)) + override fun forwardEvents(eventIds: List) { + backstack.push(NavTarget.ForwardEvent(eventIds, fromPinnedEvents = false)) } override fun navigateToReportMessage(eventId: EventId, senderId: UserId) { @@ -464,7 +464,7 @@ class MessagesFlowNode( } else { timelineController } - val params = ForwardEntryPoint.Params(navTarget.eventId, timelineProvider) + val params = ForwardEntryPoint.Params(navTarget.eventIds, timelineProvider) val callback = object : ForwardEntryPoint.Callback { override fun onDone(roomIds: List) { backstack.pop() @@ -551,7 +551,7 @@ class MessagesFlowNode( } override fun handleForwardEventClick(eventId: EventId) { - backstack.push(NavTarget.ForwardEvent(eventId = eventId, fromPinnedEvents = true)) + backstack.push(NavTarget.ForwardEvent(eventIds = listOf(eventId), fromPinnedEvents = true)) } override fun navigateToThread(threadRootId: ThreadId) { @@ -617,8 +617,8 @@ class MessagesFlowNode( backstack.push(NavTarget.EventDebugInfo(eventId, debugInfo)) } - override fun handleForwardEventClick(eventId: EventId) { - backstack.push(NavTarget.ForwardEvent(eventId, fromPinnedEvents = false)) + override fun handleForwardEventClick(eventIds: List) { + backstack.push(NavTarget.ForwardEvent(eventIds, fromPinnedEvents = false)) } override fun navigateToReportMessage(eventId: EventId, senderId: UserId) { diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesNavigator.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesNavigator.kt index 6113b68aab..b51c516214 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesNavigator.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesNavigator.kt @@ -18,7 +18,7 @@ import kotlinx.collections.immutable.ImmutableList interface MessagesNavigator { fun navigateToEventDebugInfo(eventId: EventId?, debugInfo: TimelineItemDebugInfo) - fun forwardEvent(eventId: EventId) + fun forwardEvents(eventIds: List) fun navigateToReportMessage(eventId: EventId, senderId: UserId) fun navigateToEditPoll(eventId: EventId) fun navigateToPreviewAttachments(attachments: ImmutableList, inReplyToEventId: EventId?) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesNode.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesNode.kt index 97d3465ce7..d95ba0bd45 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesNode.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesNode.kt @@ -130,7 +130,7 @@ class MessagesNode( fun navigateToRoomMemberDetails(userId: UserId) fun handlePermalinkClick(data: PermalinkData) fun navigateToEventDebugInfo(eventId: EventId?, debugInfo: TimelineItemDebugInfo) - fun forwardEvent(eventId: EventId) + fun forwardEvents(eventIds: List) fun navigateToReportMessage(eventId: EventId, senderId: UserId) fun navigateToSendLocation() fun navigateToCreatePoll() @@ -213,8 +213,8 @@ class MessagesNode( callback.navigateToEventDebugInfo(eventId, debugInfo) } - override fun forwardEvent(eventId: EventId) { - callback.forwardEvent(eventId) + override fun forwardEvents(eventIds: List) { + callback.forwardEvents(eventIds) } override fun navigateToReportMessage(eventId: EventId, senderId: UserId) { diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/threads/ThreadedMessagesNode.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/threads/ThreadedMessagesNode.kt index cf3c701015..01d466d83b 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/threads/ThreadedMessagesNode.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/threads/ThreadedMessagesNode.kt @@ -135,7 +135,7 @@ class ThreadedMessagesNode( fun navigateToRoomMemberDetails(userId: UserId) fun handlePermalinkClick(data: PermalinkData) fun navigateToEventDebugInfo(eventId: EventId?, debugInfo: TimelineItemDebugInfo) - fun handleForwardEventClick(eventId: EventId) + fun handleForwardEventClick(eventIds: List) fun navigateToReportMessage(eventId: EventId, senderId: UserId) fun navigateToSendLocation() fun navigateToCreatePoll() @@ -219,8 +219,8 @@ class ThreadedMessagesNode( callback.navigateToEventDebugInfo(eventId, debugInfo) } - override fun forwardEvent(eventId: EventId) { - callback.handleForwardEventClick(eventId) + override fun forwardEvents(eventIds: List) { + callback.handleForwardEventClick(eventIds) } override fun navigateToReportMessage(eventId: EventId, senderId: UserId) { diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/FakeMessagesNavigator.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/FakeMessagesNavigator.kt index 68f9a8d17a..1d9243af3d 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/FakeMessagesNavigator.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/FakeMessagesNavigator.kt @@ -19,7 +19,7 @@ import kotlinx.collections.immutable.ImmutableList class FakeMessagesNavigator( private val onShowEventDebugInfoClickLambda: (eventId: EventId?, debugInfo: TimelineItemDebugInfo) -> Unit = { _, _ -> lambdaError() }, - private val onForwardEventClickLambda: (eventId: EventId) -> Unit = { _ -> lambdaError() }, + private val onForwardEventClickLambda: (eventIds: List) -> Unit = { _ -> lambdaError() }, private val onReportContentClickLambda: (eventId: EventId, senderId: UserId) -> Unit = { _, _ -> lambdaError() }, private val onEditPollClickLambda: (eventId: EventId) -> Unit = { _ -> lambdaError() }, private val onPreviewAttachmentLambda: (attachments: ImmutableList, inReplyToEventId: EventId?) -> Unit = { _, _ -> lambdaError() }, @@ -34,8 +34,8 @@ class FakeMessagesNavigator( onShowEventDebugInfoClickLambda(eventId, debugInfo) } - override fun forwardEvent(eventId: EventId) { - onForwardEventClickLambda(eventId) + override fun forwardEvents(eventIds: List) { + onForwardEventClickLambda(eventIds) } override fun navigateToReportMessage(eventId: EventId, senderId: UserId) { From cec42ae4e6fff161475d491c57c372c3f621977b Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 25 Sep 2026 18:47:28 +0200 Subject: [PATCH 04/22] Enter selection mode from the Forward action --- .../features/messages/impl/MessagesEvent.kt | 1 + .../messages/impl/MessagesPresenter.kt | 32 ++++--- .../features/messages/impl/MessagesView.kt | 8 +- .../impl/actionlist/ActionListPresenter.kt | 9 -- .../actionlist/model/TimelineItemAction.kt | 1 - .../model/TimelineItemActionComparator.kt | 1 - .../messages/impl/timeline/SelectionState.kt | 30 ++++++- .../messages/impl/timeline/TimelineEvent.kt | 2 +- .../impl/timeline/TimelinePresenter.kt | 26 +++--- .../messages/impl/timeline/TimelineState.kt | 37 +++++++- .../messages/impl/timeline/TimelineView.kt | 12 +-- .../components/TimelineItemSelectionData.kt | 1 + .../timeline/model/TimelineItemSelection.kt | 34 -------- .../impl/topbars/SelectionModeTopBar.kt | 21 ++++- .../messages/impl/MessagesPresenterTest.kt | 84 +++++++++++++++++-- .../actionlist/ActionListPresenterTest.kt | 38 --------- .../impl/timeline/SelectionActionTest.kt | 60 +++++++++++++ .../impl/timeline/TimelinePresenterTest.kt | 38 +++++++-- .../impl/timeline/TimelineStateTest.kt | 77 +++++++++++++++++ .../model/TimelineItemSelectionTest.kt | 47 ----------- 20 files changed, 379 insertions(+), 180 deletions(-) delete mode 100644 features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelection.kt create mode 100644 features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionActionTest.kt create mode 100644 features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateTest.kt delete mode 100644 features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionTest.kt diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesEvent.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesEvent.kt index 4d621e417f..adbf1f15ab 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesEvent.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesEvent.kt @@ -21,6 +21,7 @@ sealed interface MessagesEvent { data object StopLiveLocationShare : MessagesEvent data object ShowLiveLocationShare : MessagesEvent data object MarkAsFullyReadAndExit : MessagesEvent + data object ConfirmSelectionAction : MessagesEvent } enum class InviteDialogAction { diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt index bcbfc35255..5a24c64787 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesPresenter.kt @@ -39,6 +39,8 @@ import io.element.android.features.messages.impl.messagecomposer.MessageComposer import io.element.android.features.messages.impl.messagecomposer.MessageComposerState import io.element.android.features.messages.impl.pinned.banner.PinnedMessagesBannerState import io.element.android.features.messages.impl.timeline.MarkAsFullyRead +import io.element.android.features.messages.impl.timeline.SelectionAction +import io.element.android.features.messages.impl.timeline.SelectionState import io.element.android.features.messages.impl.timeline.TimelineController import io.element.android.features.messages.impl.timeline.TimelineEvent import io.element.android.features.messages.impl.timeline.TimelineState @@ -53,6 +55,7 @@ import io.element.android.features.messages.impl.timeline.model.event.TimelineIt import io.element.android.features.messages.impl.timeline.model.event.captionOrNull import io.element.android.features.messages.impl.timeline.model.event.htmlCaptionOrNull import io.element.android.features.messages.impl.timeline.protection.TimelineProtectionState +import io.element.android.features.messages.impl.timeline.selectedEventIdsInTimelineOrder import io.element.android.features.messages.impl.voicemessages.composer.DefaultVoiceMessageComposerPresenter import io.element.android.features.roomcall.api.RoomCallState import io.element.android.features.roommembermoderation.api.RoomMemberModerationEvent @@ -253,6 +256,17 @@ class MessagesPresenter( timelineProtectionState = timelineProtectionState, ) } + is MessagesEvent.ConfirmSelectionAction -> { + val selection = timelineState.selectionState as? SelectionState.Active + if (selection != null) { + when (selection.action) { + SelectionAction.Forward -> { + navigator.forwardEvents(timelineState.selectedEventIdsInTimelineOrder()) + } + } + timelineState.eventSink(TimelineEvent.ExitSelectionMode) + } + } is MessagesEvent.ToggleReaction -> { localCoroutineScope.toggleReaction(event.emoji, event.eventOrTransactionId) } @@ -395,17 +409,20 @@ class MessagesPresenter( } } TimelineItemAction.ViewSource -> handleShowDebugInfoAction(targetEvent) - TimelineItemAction.Forward -> handleForwardAction(targetEvent) + TimelineItemAction.Forward -> { + val eventId = targetEvent.eventId ?: return@launch + if (featureFlagService.isFeatureEnabled(FeatureFlags.MessageMultiSelect)) { + timelineState.eventSink(TimelineEvent.EnterSelectionMode(SelectionAction.Forward, eventId)) + } else { + navigator.forwardEvents(listOf(eventId)) + } + } TimelineItemAction.ReportContent -> handleReportAction(targetEvent) TimelineItemAction.EndPoll -> handleEndPollAction(targetEvent, timelineState) TimelineItemAction.Pin -> handlePinAction(targetEvent) TimelineItemAction.Unpin -> handleUnpinAction(targetEvent) TimelineItemAction.ViewInTimeline -> Unit TimelineItemAction.RetrySending -> handleRetrySending(targetEvent) - TimelineItemAction.Select -> { - val eventId = targetEvent.eventId ?: return@launch - timelineState.eventSink(TimelineEvent.EnterSelectionMode(eventId)) - } } } @@ -588,11 +605,6 @@ class MessagesPresenter( navigator.navigateToEventDebugInfo(event.eventId, event.debugInfo) } - private fun handleForwardAction(event: TimelineItem.Event) { - if (event.eventId == null) return - navigator.forwardEvent(event.eventId) - } - private fun handleReportAction(event: TimelineItem.Event) { if (event.eventId == null) return navigator.navigateToReportMessage(event.eventId, event.senderId) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt index c4bcf552b5..0a82e52d08 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt @@ -10,8 +10,6 @@ package io.element.android.features.messages.impl import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.expandVertically -import androidx.compose.animation.fadeIn -import androidx.compose.animation.fadeOut import androidx.compose.animation.shrinkVertically import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -79,6 +77,7 @@ import io.element.android.features.messages.impl.pinned.banner.PinnedMessagesBan import io.element.android.features.messages.impl.pinned.banner.PinnedMessagesBannerView import io.element.android.features.messages.impl.pinned.banner.PinnedMessagesBannerViewDefaults import io.element.android.features.messages.impl.timeline.FOCUS_ON_PINNED_EVENT_DEBOUNCE_DURATION_IN_MILLIS +import io.element.android.features.messages.impl.timeline.SelectionState import io.element.android.features.messages.impl.timeline.TimelineEvent import io.element.android.features.messages.impl.timeline.TimelineView import io.element.android.features.messages.impl.timeline.aGroupedEvents @@ -248,11 +247,16 @@ fun MessagesView( topBar = { when { state.timelineState.isSelectionModeActive -> { + val selection = state.timelineState.selectionState as SelectionState.Active SelectionModeTopBar( selectedCount = state.timelineState.selectedCount, + action = selection.action, onCancelClick = { state.timelineState.eventSink(TimelineEvent.ExitSelectionMode) }, + onConfirmClick = { + state.eventSink(MessagesEvent.ConfirmSelectionAction) + }, ) } state.timelineState.timelineMode is Timeline.Mode.Thread -> { diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt index 66ed7dd757..8caa95f31d 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenter.kt @@ -27,7 +27,6 @@ import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUser import io.element.android.features.messages.impl.crypto.sendfailure.VerifiedUserSendFailureFactory import io.element.android.features.messages.impl.timeline.model.TimelineItem import io.element.android.features.messages.impl.timeline.model.TimelineItemThreadInfo -import io.element.android.features.messages.impl.timeline.model.canBeSelected import io.element.android.features.messages.impl.timeline.model.event.TimelineItemAttachmentsContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContentWithAttachment @@ -110,7 +109,6 @@ class DefaultActionListPresenter( }.collectAsState(initial = persistentListOf()) val isThreadsEnabled = featureFlagService.isFeatureEnabledFlow(FeatureFlags.Threads).collectAsState(false) - val isMultiSelectEnabled = featureFlagService.isFeatureEnabledFlow(FeatureFlags.MessageMultiSelect).collectAsState(false) fun handleEvent(event: ActionListEvent) { when (event) { @@ -122,7 +120,6 @@ class DefaultActionListPresenter( pinnedEventIds = pinnedEventIds, target = target, isThreadsEnabled = isThreadsEnabled.value, - isMultiSelectEnabled = isMultiSelectEnabled.value, ) } } @@ -140,7 +137,6 @@ class DefaultActionListPresenter( pinnedEventIds: ImmutableList, target: MutableState, isThreadsEnabled: Boolean, - isMultiSelectEnabled: Boolean, ) = launch { target.value = ActionListState.Target.Loading(timelineItem) @@ -150,7 +146,6 @@ class DefaultActionListPresenter( isDeveloperModeEnabled = isDeveloperModeEnabled, isEventPinned = pinnedEventIds.contains(timelineItem.eventId), isThreadsEnabled = isThreadsEnabled, - isMultiSelectEnabled = isMultiSelectEnabled, ) val verifiedUserSendFailure = userSendFailureFactory.create(timelineItem.localSendState) @@ -184,7 +179,6 @@ class DefaultActionListPresenter( isDeveloperModeEnabled: Boolean, isEventPinned: Boolean, isThreadsEnabled: Boolean, - isMultiSelectEnabled: Boolean, ): List { val canRedact = timelineItem.isMine && usersEventPermissions.canRedactOwn || !timelineItem.isMine && usersEventPermissions.canRedactOther return buildSet { @@ -206,9 +200,6 @@ class DefaultActionListPresenter( if (timelineItem.isRemote && timelineItem.content.canBeForwarded()) { add(TimelineItemAction.Forward) } - if (isMultiSelectEnabled && timelineItem.canBeSelected()) { - add(TimelineItemAction.Select) - } if (timelineItem.isEditable && usersEventPermissions.canSendMessage) { if (timelineItem.content is TimelineItemEventContentWithAttachment || timelineItem.content is TimelineItemGalleryContent || diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemAction.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemAction.kt index c7ee198ebc..3c64223e59 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemAction.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemAction.kt @@ -20,7 +20,6 @@ enum class TimelineItemAction( ) { ViewInTimeline(CommonStrings.action_view_in_timeline, CompoundDrawables.ic_compound_visibility_on), Forward(CommonStrings.action_forward, CompoundDrawables.ic_compound_forward), - Select(CommonStrings.action_select, CompoundDrawables.ic_compound_check), CopyText(CommonStrings.action_copy_text, CompoundDrawables.ic_compound_copy), CopyCaption(CommonStrings.action_copy_caption, CompoundDrawables.ic_compound_copy), CopyLink(CommonStrings.action_copy_link_to_message, CompoundDrawables.ic_compound_link), diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemActionComparator.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemActionComparator.kt index 86b62794ba..2f6fa4e4e0 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemActionComparator.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/actionlist/model/TimelineItemActionComparator.kt @@ -19,7 +19,6 @@ class TimelineItemActionComparator : Comparator { TimelineItemAction.Reply, TimelineItemAction.ReplyInThread, TimelineItemAction.Forward, - TimelineItemAction.Select, TimelineItemAction.Edit, TimelineItemAction.EditPoll, TimelineItemAction.AddCaption, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt index 91b0d2e73a..f2738480aa 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt @@ -7,18 +7,42 @@ package io.element.android.features.messages.impl.timeline +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes import androidx.compose.runtime.Immutable +import io.element.android.compound.R +import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.event.canBeForwarded import io.element.android.libraries.matrix.api.core.EventId +import io.element.android.libraries.ui.strings.CommonStrings import kotlinx.collections.immutable.ImmutableSet /** Maximum number of messages that can be selected at once. */ -const val MAX_SELECTION_COUNT = 30 +const val MAX_SELECTION_COUNT = 10 @Immutable sealed interface SelectionState { /** Selection mode is not active. */ data object Disabled : SelectionState - /** Selection mode is active with the given selection. */ - data class Active(val selectedEventIds: ImmutableSet) : SelectionState + /** Selection mode is active for [action], with the given selection. */ + data class Active( + val action: SelectionAction, + val selectedEventIds: ImmutableSet, + ) : SelectionState +} + +/** + * An action which can be performed on several timeline events at once, and which selection mode can be entered for. + */ +enum class SelectionAction(@field:StringRes val titleRes: Int, @field:DrawableRes val iconRes: Int) { + Forward(CommonStrings.action_forward, R.drawable.ic_compound_forward), +} + +/** + * Whether [event] can be part of a selection made for this action. + * Each action uses the same criteria as the single event action it mirrors. + */ +fun SelectionAction.canApplyTo(event: TimelineItem.Event): Boolean = when (this) { + SelectionAction.Forward -> event.isRemote && event.content.canBeForwarded() } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineEvent.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineEvent.kt index f21bfe88aa..ac67d93784 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineEvent.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineEvent.kt @@ -29,7 +29,7 @@ sealed interface TimelineEvent { data object MarkAllAsRead : TimelineEvent - data class EnterSelectionMode(val eventId: EventId) : TimelineEvent + data class EnterSelectionMode(val action: SelectionAction, val eventId: EventId) : TimelineEvent data class ToggleSelection(val eventId: EventId) : TimelineEvent data object ExitSelectionMode : TimelineEvent diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt index 80812264fd..320e362024 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt @@ -34,7 +34,6 @@ import io.element.android.features.messages.impl.timeline.factories.TimelineItem import io.element.android.features.messages.impl.timeline.factories.TimelineItemsFactoryConfig import io.element.android.features.messages.impl.timeline.model.NewEventState import io.element.android.features.messages.impl.timeline.model.TimelineItem -import io.element.android.features.messages.impl.timeline.model.canBeSelected import io.element.android.features.messages.impl.timeline.model.virtual.TimelineItemReadMarkerModel import io.element.android.features.messages.impl.timeline.model.virtual.TimelineItemTypingNotificationModel import io.element.android.features.messages.impl.timeline.protection.TimelineProtectionEvent @@ -265,7 +264,7 @@ class TimelinePresenter( } is TimelineEvent.EnterSelectionMode -> { if (!isMultiSelectEnabled) return - selectionState = SelectionState.Active(persistentSetOf(event.eventId)) + selectionState = SelectionState.Active(event.action, persistentSetOf(event.eventId)) } is TimelineEvent.ToggleSelection -> { val current = selectionState as? SelectionState.Active ?: return @@ -273,13 +272,13 @@ class TimelinePresenter( selectionState = when { event.eventId in selected -> { val next = (selected - event.eventId).toPersistentSet() - if (next.isEmpty()) SelectionState.Disabled else SelectionState.Active(next) + if (next.isEmpty()) SelectionState.Disabled else current.copy(selectedEventIds = next) } selected.size >= MAX_SELECTION_COUNT -> { snackbarDispatcher.post(SnackbarMessage(R.string.screen_room_timeline_selection_limit_reached)) current } - else -> SelectionState.Active((selected + event.eventId).toPersistentSet()) + else -> current.copy(selectedEventIds = (selected + event.eventId).toPersistentSet()) } } is TimelineEvent.ExitSelectionMode -> { @@ -394,19 +393,22 @@ class TimelinePresenter( computeNewItemState(timelineItems, prevMostRecentItemId, newEventState) } - // Reconcile the selection when the items change: drop any selected event that is no longer - // present or no longer selectable, and exit selection mode if nothing remains selected. - LaunchedEffect(timelineItems.map { it.identifier() }) { - val active = selectionState as? SelectionState.Active ?: return@LaunchedEffect - val stillSelectable = timelineItems + val selectableEventIds = (selectionState as? SelectionState.Active)?.let { active -> + timelineItems .filterIsInstance() - .filter { it.canBeSelected() } + .filter { active.action.canApplyTo(it) } .mapNotNull { it.eventId } .toSet() - val reconciled = active.selectedEventIds.filter { it in stillSelectable }.toPersistentSet() + }.orEmpty() + + // Reconcile the selection when the items change: drop any selected event that is no longer + // present or no longer selectable, and exit selection mode if nothing remains selected. + LaunchedEffect(selectableEventIds) { + val active = selectionState as? SelectionState.Active ?: return@LaunchedEffect + val reconciled = active.selectedEventIds.filter { it in selectableEventIds }.toPersistentSet() selectionState = when { reconciled.isEmpty() -> SelectionState.Disabled - reconciled.size != active.selectedEventIds.size -> SelectionState.Active(reconciled) + reconciled.size != active.selectedEventIds.size -> active.copy(selectedEventIds = reconciled) else -> active } } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt index 6bd5aa0895..bc571f6634 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt @@ -21,6 +21,8 @@ import io.element.android.libraries.matrix.api.core.UniqueId import io.element.android.libraries.matrix.api.room.tombstone.PredecessorRoom import io.element.android.libraries.matrix.api.timeline.Timeline import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.toImmutableList import kotlin.time.Duration data class TimelineState( @@ -108,7 +110,36 @@ val TimelineState.isSelectionModeActive: Boolean val TimelineState.selectedCount: Int get() = (selectionState as? SelectionState.Active)?.selectedEventIds?.size ?: 0 -fun TimelineState.isSelected(eventId: EventId?): Boolean { - if (eventId == null) return false - return (selectionState as? SelectionState.Active)?.selectedEventIds?.contains(eventId) == true +fun TimelineState.isSelected(item: TimelineItem): Boolean { + val selection = selectionState as? SelectionState.Active ?: return false + return when(item){ + is TimelineItem.Event -> selection.selectedEventIds.contains(item.eventId) + else -> false + } +} + +/** + * Whether [item] can be selected right now: selection mode must be active, and the action it was entered for must accept this event. + */ +fun TimelineState.canSelect(item: TimelineItem): Boolean { + val selection = selectionState as? SelectionState.Active ?: return false + return when(item) { + is TimelineItem.Event -> selection.action.canApplyTo(item) + else -> false + } +} + +/** + * The selected event ids, sorted from the oldest to the most recent one, as they appear in the timeline. + * The selection itself is stored as a set, in the order the events were tapped, which is not necessarily the order they must be acted on. + */ +fun TimelineState.selectedEventIdsInTimelineOrder(): ImmutableList { + val selectedEventIds = (selectionState as? SelectionState.Active)?.selectedEventIds ?: return persistentListOf() + return timelineItems + .filterIsInstance() + .mapNotNull { it.eventId } + .filter { it in selectedEventIds } + // Most recent item is first in the timeline, so reverse the result. + .reversed() + .toImmutableList() } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt index 0df9be3ca0..eb9eef7c8f 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt @@ -91,7 +91,6 @@ import io.element.android.features.messages.impl.timeline.di.aFakeTimelineItemPr import io.element.android.features.messages.impl.timeline.focus.FocusRequestStateView import io.element.android.features.messages.impl.timeline.model.NewEventState import io.element.android.features.messages.impl.timeline.model.TimelineItem -import io.element.android.features.messages.impl.timeline.model.canBeSelected import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContentPreviewParam import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemTextContent @@ -234,17 +233,18 @@ fun TimelineView( selectionData = TimelineItemSelectionData( isSelectionModeActive = isSelectionModeActive, progress = selectionProgress, - isSelected = state.isSelected((timelineItem as? TimelineItem.Event)?.eventId), + isSelected = state.isSelected(timelineItem), + canBeSelected = state.canSelect(timelineItem), ), onUserDataClick = onUserDataClick, onLinkClick = onLinkClick, onLinkLongClick = ::onLinkLongClick, onContentClick = { event -> - if (isSelectionModeActive && event.canBeSelected()) onToggleSelection(event) else onContentClick(event) + if (state.canSelect(event)) onToggleSelection(event) else onContentClick(event) }, onGalleryItemClick = onGalleryItemClick, onLongClick = { event -> - if (isSelectionModeActive && event.canBeSelected()) onToggleSelection(event) else onMessageLongClick(event) + if (state.canSelect(event)) onToggleSelection(event) else onMessageLongClick(event) }, inReplyToClick = ::inReplyToClick, onReactionClick = onReactionClick, @@ -646,14 +646,14 @@ internal fun TimelineViewPreview( @Composable internal fun TimelineViewSelectionModePreview() = ElementPreview { val timelineItems = aTimelineItemList(aTimelineItemTextContent()) - val selectedEventId = timelineItems.filterIsInstance().first { it.canBeSelected() }.eventId!! + val selectedEventId = timelineItems.filterIsInstance().first { SelectionAction.Forward.canApplyTo(it) }.eventId!! CompositionLocalProvider( LocalTimelineItemPresenterFactories provides aFakeTimelineItemPresenterFactories(), ) { TimelineView( state = aTimelineState( timelineItems = timelineItems, - selectionState = SelectionState.Active(persistentSetOf(selectedEventId)), + selectionState = SelectionState.Active(SelectionAction.Forward, persistentSetOf(selectedEventId)), ), timelineProtectionState = aTimelineProtectionState(), onUserDataClick = {}, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemSelectionData.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemSelectionData.kt index f8de354aac..641be44fe8 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemSelectionData.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemSelectionData.kt @@ -20,5 +20,6 @@ package io.element.android.features.messages.impl.timeline.components data class TimelineItemSelectionData( val isSelectionModeActive: Boolean = false, val isSelected: Boolean = false, + val canBeSelected: Boolean = false, val progress: Float = 0f, ) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelection.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelection.kt deleted file mode 100644 index 9f11e86213..0000000000 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelection.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2026 New Vector 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.messages.impl.timeline.model - -import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEncryptedContent -import io.element.android.features.messages.impl.timeline.model.event.TimelineItemLegacyCallInviteContent -import io.element.android.features.messages.impl.timeline.model.event.TimelineItemLocationContent -import io.element.android.features.messages.impl.timeline.model.event.TimelineItemRedactedContent -import io.element.android.features.messages.impl.timeline.model.event.TimelineItemRtcNotificationContent -import io.element.android.features.messages.impl.timeline.model.event.TimelineItemStateContent -import io.element.android.features.messages.impl.timeline.model.event.TimelineItemUnknownContent - -/** - * Whether this timeline event can be selected in multi-select ("selection") mode. - */ -fun TimelineItem.Event.canBeSelected(): Boolean { - // Local echoes (no remote eventId) and failed sends are never selectable. - if (!isRemote || failedToSend) return false - return when (content) { - is TimelineItemStateContent, - is TimelineItemRedactedContent, - is TimelineItemEncryptedContent, - is TimelineItemLegacyCallInviteContent, - is TimelineItemRtcNotificationContent, - is TimelineItemLocationContent, - is TimelineItemUnknownContent -> false - else -> true - } -} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt index 55563d1f1b..1e96d7b1e1 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt @@ -16,6 +16,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider import io.element.android.compound.tokens.generated.CompoundIcons import io.element.android.features.messages.impl.R +import io.element.android.features.messages.impl.timeline.SelectionAction import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.PreviewsDayNight import io.element.android.libraries.designsystem.theme.components.Icon @@ -28,7 +29,9 @@ import io.element.android.libraries.ui.strings.CommonStrings @Composable fun SelectionModeTopBar( selectedCount: Int, + action: SelectionAction, onCancelClick: () -> Unit, + onConfirmClick: () -> Unit, modifier: Modifier = Modifier, ) { TopAppBar( @@ -43,6 +46,17 @@ fun SelectionModeTopBar( Icon(imageVector = CompoundIcons.Close(), contentDescription = stringResource(CommonStrings.action_close)) } }, + actions = { + IconButton( + onClick = onConfirmClick, + enabled = selectedCount > 0, + ) { + Icon( + resourceId = action.iconRes, + contentDescription = stringResource(action.titleRes), + ) + } + }, ) } @@ -51,7 +65,12 @@ fun SelectionModeTopBar( internal fun SelectionModeTopBarPreview( @PreviewParameter(SelectionCountProvider::class) count: Int, ) = ElementPreview { - SelectionModeTopBar(selectedCount = count, onCancelClick = {}) + SelectionModeTopBar( + selectedCount = count, + action = SelectionAction.Forward, + onCancelClick = {}, + onConfirmClick = {}, + ) } internal class SelectionCountProvider : PreviewParameterProvider { diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/MessagesPresenterTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/MessagesPresenterTest.kt index 4c0abc0a34..152cb8a7a0 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/MessagesPresenterTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/MessagesPresenterTest.kt @@ -28,8 +28,12 @@ import io.element.android.features.messages.impl.pinned.banner.aLoadedPinnedMess import io.element.android.features.messages.impl.threads.list.aThreadListItem import io.element.android.features.messages.impl.timeline.FakeMarkAsFullyRead import io.element.android.features.messages.impl.timeline.MarkAsFullyRead +import io.element.android.features.messages.impl.timeline.SelectionAction +import io.element.android.features.messages.impl.timeline.SelectionState import io.element.android.features.messages.impl.timeline.TimelineController import io.element.android.features.messages.impl.timeline.TimelineEvent +import io.element.android.features.messages.impl.timeline.TimelineState +import io.element.android.features.messages.impl.timeline.aTimelineItemEvent import io.element.android.features.messages.impl.timeline.aTimelineState import io.element.android.features.messages.impl.timeline.model.TimelineItemThreadInfo import io.element.android.features.messages.impl.timeline.model.event.TimelineItemFileContent @@ -76,6 +80,7 @@ import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSen import io.element.android.libraries.matrix.api.timeline.item.event.toEventOrTransactionId import io.element.android.libraries.matrix.test.AN_AVATAR_URL import io.element.android.libraries.matrix.test.AN_EVENT_ID +import io.element.android.libraries.matrix.test.AN_EVENT_ID_2 import io.element.android.libraries.matrix.test.AN_EXCEPTION import io.element.android.libraries.matrix.test.A_CAPTION import io.element.android.libraries.matrix.test.A_ROOM_ID @@ -113,6 +118,7 @@ import io.element.android.tests.testutils.lambda.value import io.element.android.tests.testutils.testCoroutineDispatchers import io.element.android.tests.testutils.testWithLifecycleOwner import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.persistentSetOf import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow @@ -285,17 +291,37 @@ class MessagesPresenterTest { } @Test - fun `present - handle action forward`() = runTest { - val onForwardEventClickLambda = lambdaRecorder { } - val navigator = FakeMessagesNavigator( - onForwardEventClickLambda = onForwardEventClickLambda, + fun `present - handle action forward enters selection mode when multi select is enabled`() = runTest { + val timelineEventSink = lambdaRecorder { } + val presenter = createMessagesPresenter( + timelineEventSink = timelineEventSink, + featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to true)), ) - val presenter = createMessagesPresenter(navigator = navigator) presenter.testWithLifecycleOwner { val initialState = awaitItem() initialState.eventSink(MessagesEvent.HandleAction(TimelineItemAction.Forward, aMessageEvent())) assertThat(awaitItem().actionListState.target).isEqualTo(ActionListState.Target.None) - onForwardEventClickLambda.assertions().isCalledOnce().with(value(AN_EVENT_ID)) + timelineEventSink.assertions().isCalledOnce() + .with(value(TimelineEvent.EnterSelectionMode(SelectionAction.Forward, AN_EVENT_ID))) + cancelAndIgnoreRemainingEvents() + } + } + + @Test + fun `present - handle action forward navigates directly when multi select is disabled`() = runTest { + val onForwardEventClickLambda = lambdaRecorder, Unit> { } + val navigator = FakeMessagesNavigator( + onForwardEventClickLambda = onForwardEventClickLambda, + ) + val presenter = createMessagesPresenter( + navigator = navigator, + featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to false)), + ) + presenter.testWithLifecycleOwner { + val initialState = awaitItem() + initialState.eventSink(MessagesEvent.HandleAction(TimelineItemAction.Forward, aMessageEvent())) + assertThat(awaitItem().actionListState.target).isEqualTo(ActionListState.Target.None) + onForwardEventClickLambda.assertions().isCalledOnce().with(value(listOf(AN_EVENT_ID))) } } @@ -1424,6 +1450,49 @@ class MessagesPresenterTest { canPinUnpin = canPinUnpin, ) + @Test + fun `present - confirm selection action forwards the selection in timeline order`() = runTest { + val onForwardEventClickLambda = lambdaRecorder, Unit> { } + val navigator = FakeMessagesNavigator(onForwardEventClickLambda = onForwardEventClickLambda) + val timelineEventSink = lambdaRecorder { } + val presenter = createMessagesPresenter( + navigator = navigator, + timelineEventSink = timelineEventSink, + timelineState = aTimelineState( + // The timeline is rendered from the most recent event to the oldest one. + timelineItems = persistentListOf( + aTimelineItemEvent(eventId = AN_EVENT_ID_2), + aTimelineItemEvent(eventId = AN_EVENT_ID), + ), + selectionState = SelectionState.Active( + SelectionAction.Forward, + persistentSetOf(AN_EVENT_ID_2, AN_EVENT_ID), + ), + eventSink = timelineEventSink, + ), + ) + presenter.testWithLifecycleOwner { + val initialState = awaitItem() + initialState.eventSink(MessagesEvent.ConfirmSelectionAction) + onForwardEventClickLambda.assertions().isCalledOnce().with(value(listOf(AN_EVENT_ID, AN_EVENT_ID_2))) + timelineEventSink.assertions().isCalledOnce().with(value(TimelineEvent.ExitSelectionMode)) + cancelAndIgnoreRemainingEvents() + } + } + + @Test + fun `present - confirm selection action does nothing when no selection is active`() = runTest { + val onForwardEventClickLambda = lambdaRecorder, Unit> { } + val navigator = FakeMessagesNavigator(onForwardEventClickLambda = onForwardEventClickLambda) + val presenter = createMessagesPresenter(navigator = navigator) + presenter.testWithLifecycleOwner { + val initialState = awaitItem() + initialState.eventSink(MessagesEvent.ConfirmSelectionAction) + onForwardEventClickLambda.assertions().isNeverCalled() + cancelAndIgnoreRemainingEvents() + } + } + private fun TestScope.createMessagesPresenter( coroutineDispatchers: CoroutineDispatchers = testCoroutineDispatchers(), timeline: Timeline = FakeTimeline(), @@ -1446,6 +1515,7 @@ class MessagesPresenterTest { clipboardHelper: FakeClipboardHelper = FakeClipboardHelper(), analyticsService: FakeAnalyticsService = FakeAnalyticsService(), timelineEventSink: (TimelineEvent) -> Unit = {}, + timelineState: TimelineState = aTimelineState(eventSink = timelineEventSink), permalinkParser: PermalinkParser = FakePermalinkParser(), messageComposerPresenter: Presenter = Presenter { aMessageComposerState( @@ -1468,7 +1538,7 @@ class MessagesPresenterTest { room = joinedRoom, composerPresenter = messageComposerPresenter, voiceMessageComposerPresenterFactory = FakeDefaultVoiceMessageComposerPresenterFactory(backgroundScope), - timelinePresenter = { aTimelineState(eventSink = timelineEventSink) }, + timelinePresenter = { timelineState }, timelineProtectionPresenter = { aTimelineProtectionState() }, identityChangeStatePresenter = { anIdentityChangeState() }, linkPresenter = { aLinkState() }, diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenterTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenterTest.kt index 2988fbe894..e987a32480 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenterTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/actionlist/ActionListPresenterTest.kt @@ -70,44 +70,6 @@ class ActionListPresenterTest { } } - @Test - fun `present - Select action is present for a remote message when multi-select is enabled`() = runTest { - val presenter = createActionListPresenter( - isDeveloperModeEnabled = false, - featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to true)), - ) - presenter.test { - val initialState = awaitItem() - initialState.eventSink.invoke( - ActionListEvent.ComputeForMessage( - event = aMessageEvent(), - userEventPermissions = aUserEventPermissions(canSendMessage = true), - ) - ) - val successState = awaitItem() - assertThat((successState.target as ActionListState.Target.Success).actions).contains(TimelineItemAction.Select) - } - } - - @Test - fun `present - Select action is absent when multi-select is disabled`() = runTest { - val presenter = createActionListPresenter( - isDeveloperModeEnabled = false, - featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to false)), - ) - presenter.test { - val initialState = awaitItem() - initialState.eventSink.invoke( - ActionListEvent.ComputeForMessage( - event = aMessageEvent(), - userEventPermissions = aUserEventPermissions(canSendMessage = true), - ) - ) - val successState = awaitItem() - assertThat((successState.target as ActionListState.Target.Success).actions).doesNotContain(TimelineItemAction.Select) - } - } - @Test fun `present - compute for message from me redacted`() = runTest { val presenter = createActionListPresenter(isDeveloperModeEnabled = true) diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionActionTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionActionTest.kt new file mode 100644 index 0000000000..4939ec3a50 --- /dev/null +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionActionTest.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2026 New Vector 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.messages.impl.timeline + +import com.google.common.truth.Truth.assertThat +import io.element.android.features.messages.impl.timeline.model.event.aStaticLocationMode +import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemLocationContent +import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemRedactedContent +import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemStateEventContent +import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemStickerContent +import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState +import org.junit.Test + +class SelectionActionTest { + @Test + fun `Forward - a remote text message can be selected`() { + assertThat(SelectionAction.Forward.canApplyTo(aTimelineItemEvent())).isTrue() + } + + @Test + fun `Forward - a local echo cannot be selected`() { + assertThat(SelectionAction.Forward.canApplyTo(aTimelineItemEvent().copy(eventId = null))).isFalse() + } + + @Test + fun `Forward - a failed to send message cannot be selected`() { + // A message which failed to send is a local echo: it has no event id. + val item = aTimelineItemEvent(sendState = LocalEventSendState.Failed.Unknown("failed")).copy(eventId = null) + assertThat(SelectionAction.Forward.canApplyTo(item)).isFalse() + } + + @Test + fun `Forward - a state event cannot be selected`() { + val item = aTimelineItemEvent(content = aTimelineItemStateEventContent()) + assertThat(SelectionAction.Forward.canApplyTo(item)).isFalse() + } + + @Test + fun `Forward - a redacted event cannot be selected`() { + val item = aTimelineItemEvent(content = aTimelineItemRedactedContent()) + assertThat(SelectionAction.Forward.canApplyTo(item)).isFalse() + } + + @Test + fun `Forward - a sticker cannot be selected, it cannot be forwarded`() { + val item = aTimelineItemEvent(content = aTimelineItemStickerContent()) + assertThat(SelectionAction.Forward.canApplyTo(item)).isFalse() + } + + @Test + fun `Forward - a static location can be selected, it can be forwarded`() { + val item = aTimelineItemEvent(content = aTimelineItemLocationContent(mode = aStaticLocationMode())) + assertThat(SelectionAction.Forward.canApplyTo(item)).isTrue() + } +} diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt index 6dcf107e0b..d6534deb23 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt @@ -50,8 +50,10 @@ import io.element.android.libraries.matrix.api.timeline.ReceiptType import io.element.android.libraries.matrix.api.timeline.Timeline import io.element.android.libraries.matrix.api.timeline.item.event.EventReaction import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState +import io.element.android.libraries.matrix.api.timeline.item.event.OtherState import io.element.android.libraries.matrix.api.timeline.item.event.ReactionSender import io.element.android.libraries.matrix.api.timeline.item.event.Receipt +import io.element.android.libraries.matrix.api.timeline.item.event.StateContent import io.element.android.libraries.matrix.api.timeline.item.event.TimelineItemEventOrigin import io.element.android.libraries.matrix.api.timeline.item.virtual.VirtualTimelineItem import io.element.android.libraries.matrix.test.AN_EVENT_ID @@ -1835,9 +1837,9 @@ class TimelinePresenterTest { presenter.test { val initialState = consumeItemsUntilPredicate { it.hasAnyEvent }.last() assertThat(initialState.selectionState).isEqualTo(SelectionState.Disabled) - initialState.eventSink(TimelineEvent.EnterSelectionMode(AN_EVENT_ID)) + initialState.eventSink(TimelineEvent.EnterSelectionMode(SelectionAction.Forward, AN_EVENT_ID)) val state = consumeItemsUntilPredicate { it.isSelectionModeActive }.last() - assertThat(state.selectionState).isEqualTo(SelectionState.Active(persistentSetOf(AN_EVENT_ID))) + assertThat(state.selectionState).isEqualTo(SelectionState.Active(SelectionAction.Forward, persistentSetOf(AN_EVENT_ID))) assertThat(state.selectedCount).isEqualTo(1) cancelAndIgnoreRemainingEvents() } @@ -1849,7 +1851,7 @@ class TimelinePresenterTest { val presenter = createTimelinePresenter(featureFlagService = featureFlagService) presenter.test { val initialState = awaitFirstItem() - initialState.eventSink(TimelineEvent.EnterSelectionMode(AN_EVENT_ID)) + initialState.eventSink(TimelineEvent.EnterSelectionMode(SelectionAction.Forward, AN_EVENT_ID)) expectNoEvents() assertThat(initialState.selectionState).isEqualTo(SelectionState.Disabled) cancelAndIgnoreRemainingEvents() @@ -1867,7 +1869,7 @@ class TimelinePresenterTest { ) presenter.test { val initialState = consumeItemsUntilPredicate { it.hasAnyEvent }.last() - initialState.eventSink(TimelineEvent.EnterSelectionMode(AN_EVENT_ID)) + initialState.eventSink(TimelineEvent.EnterSelectionMode(SelectionAction.Forward, AN_EVENT_ID)) consumeItemsUntilPredicate { it.isSelectionModeActive } initialState.eventSink(TimelineEvent.ToggleSelection(AN_EVENT_ID)) val state = consumeItemsUntilPredicate { !it.isSelectionModeActive }.last() @@ -1888,7 +1890,7 @@ class TimelinePresenterTest { ) presenter.test { val initialState = consumeItemsUntilPredicate { it.hasAnyEvent }.last() - initialState.eventSink(TimelineEvent.EnterSelectionMode(AN_EVENT_ID)) + initialState.eventSink(TimelineEvent.EnterSelectionMode(SelectionAction.Forward, AN_EVENT_ID)) consumeItemsUntilPredicate { it.isSelectionModeActive } featureFlagService.setFeatureEnabled(FeatureFlags.MessageMultiSelect, false) val state = consumeItemsUntilPredicate { !it.isSelectionModeActive }.last() @@ -1897,6 +1899,32 @@ class TimelinePresenterTest { } } + @Test + fun `present - selection drops events the action cannot apply to`() = runTest { + val timelineItems = MutableStateFlow( + listOf(MatrixTimelineItem.Event(UniqueId("1"), anEventTimelineItem(eventId = AN_EVENT_ID, content = aMessageContent()))) + ) + val presenter = createTimelinePresenter( + timeline = FakeTimeline(timelineItems = timelineItems), + featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to true)), + ) + presenter.test { + val initialState = consumeItemsUntilPredicate { it.hasAnyEvent }.last() + initialState.eventSink(TimelineEvent.EnterSelectionMode(SelectionAction.Forward, AN_EVENT_ID)) + consumeItemsUntilPredicate { it.isSelectionModeActive } + // The message is replaced by a state event, which cannot be forwarded. + timelineItems.value = listOf( + MatrixTimelineItem.Event( + UniqueId("1"), + anEventTimelineItem(eventId = AN_EVENT_ID, content = StateContent("", OtherState.RoomCreate)), + ) + ) + val state = consumeItemsUntilPredicate { !it.isSelectionModeActive }.last() + assertThat(state.selectionState).isEqualTo(SelectionState.Disabled) + cancelAndIgnoreRemainingEvents() + } + } + private suspend fun ReceiveTurbine.awaitFirstItem(): T { return awaitItem() } diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateTest.kt new file mode 100644 index 0000000000..3ee818e438 --- /dev/null +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateTest.kt @@ -0,0 +1,77 @@ +/* + * Copyright 2026 New Vector 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.messages.impl.timeline + +import com.google.common.truth.Truth.assertThat +import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemRedactedContent +import io.element.android.libraries.matrix.test.AN_EVENT_ID +import io.element.android.libraries.matrix.test.AN_EVENT_ID_2 +import io.element.android.libraries.matrix.test.AN_EVENT_ID_3 +import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.persistentSetOf +import org.junit.Test + +class TimelineStateTest { + @Test + fun `selectedEventIdsInTimelineOrder - when selection is disabled, the list is empty`() { + val state = aTimelineState( + timelineItems = persistentListOf(aTimelineItemEvent(eventId = AN_EVENT_ID)), + selectionState = SelectionState.Disabled, + ) + assertThat(state.selectedEventIdsInTimelineOrder()).isEmpty() + } + + @Test + fun `selectedEventIdsInTimelineOrder - the events are sorted from the oldest to the most recent one`() { + // The timeline items are rendered from the most recent to the oldest event. + val state = aTimelineState( + timelineItems = persistentListOf( + aTimelineItemEvent(eventId = AN_EVENT_ID_3), + aTimelineItemEvent(eventId = AN_EVENT_ID_2), + aTimelineItemEvent(eventId = AN_EVENT_ID), + ), + // The events have been tapped in a random order. + selectionState = SelectionState.Active(SelectionAction.Forward, persistentSetOf(AN_EVENT_ID_2, AN_EVENT_ID, AN_EVENT_ID_3)), + ) + assertThat(state.selectedEventIdsInTimelineOrder()).containsExactly(AN_EVENT_ID, AN_EVENT_ID_2, AN_EVENT_ID_3).inOrder() + } + + @Test + fun `selectedEventIdsInTimelineOrder - the events which are not in the timeline are ignored`() { + val state = aTimelineState( + timelineItems = persistentListOf( + aTimelineItemEvent(eventId = AN_EVENT_ID_2), + aTimelineItemEvent(eventId = AN_EVENT_ID), + ), + selectionState = SelectionState.Active(SelectionAction.Forward, persistentSetOf(AN_EVENT_ID_2, AN_EVENT_ID_3)), + ) + assertThat(state.selectedEventIdsInTimelineOrder()).containsExactly(AN_EVENT_ID_2) + } + + @Test + fun `canSelect - returns false when selection mode is disabled`() { + val event = aTimelineItemEvent(eventId = AN_EVENT_ID) + val state = aTimelineState( + timelineItems = persistentListOf(event), + selectionState = SelectionState.Disabled, + ) + assertThat(state.canSelect(event)).isFalse() + } + + @Test + fun `canSelect - follows the action predicate when selection mode is active`() { + val forwardable = aTimelineItemEvent(eventId = AN_EVENT_ID) + val notForwardable = aTimelineItemEvent(eventId = AN_EVENT_ID_2, content = aTimelineItemRedactedContent()) + val state = aTimelineState( + timelineItems = persistentListOf(forwardable, notForwardable), + selectionState = SelectionState.Active(SelectionAction.Forward, persistentSetOf(AN_EVENT_ID)), + ) + assertThat(state.canSelect(forwardable)).isTrue() + assertThat(state.canSelect(notForwardable)).isFalse() + } +} diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionTest.kt deleted file mode 100644 index e293246900..0000000000 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionTest.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2026 New Vector 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.messages.impl.timeline.model - -import com.google.common.truth.Truth.assertThat -import io.element.android.features.messages.impl.timeline.aTimelineItemEvent -import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemRedactedContent -import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemStateEventContent -import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState -import org.junit.Test - -class TimelineItemSelectionTest { - @Test - fun `a remote text message can be selected`() { - val item = aTimelineItemEvent() - assertThat(item.canBeSelected()).isTrue() - } - - @Test - fun `a local echo cannot be selected`() { - val item = aTimelineItemEvent().copy(eventId = null) - assertThat(item.canBeSelected()).isFalse() - } - - @Test - fun `a failed to send message cannot be selected`() { - val item = aTimelineItemEvent(sendState = LocalEventSendState.Failed.Unknown("failed")) - assertThat(item.canBeSelected()).isFalse() - } - - @Test - fun `a state event cannot be selected`() { - val item = aTimelineItemEvent(content = aTimelineItemStateEventContent()) - assertThat(item.canBeSelected()).isFalse() - } - - @Test - fun `a redacted event cannot be selected`() { - val item = aTimelineItemEvent(content = aTimelineItemRedactedContent()) - assertThat(item.canBeSelected()).isFalse() - } -} From f4399a392ba962e69b4d4c6a21946b657928ada9 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 25 Sep 2026 18:47:48 +0200 Subject: [PATCH 05/22] Use a Checkbox for the timeline selection indicator --- .../timeline/components/SelectionIndicator.kt | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt index e980b47155..86261057c8 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt @@ -7,44 +7,38 @@ package io.element.android.features.messages.impl.timeline.components -import androidx.compose.foundation.layout.size +import androidx.compose.material3.LocalMinimumInteractiveComponentSize import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Modifier import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.dp -import io.element.android.compound.theme.ElementTheme -import io.element.android.compound.tokens.generated.CompoundIcons import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.PreviewsDayNight -import io.element.android.libraries.designsystem.theme.components.Icon +import io.element.android.libraries.designsystem.theme.components.Checkbox /** - * Compact selection indicator used in the timeline selection mode, in place of a Material - * [androidx.compose.material3.Checkbox] (which reserves a 48dp interactive area). It is purely - * visual: the tap is handled by the whole-row click target, so this only reflects [selected]. + * Selection indicator used in the timeline selection mode. It renders the Compound [Checkbox], with the minimum + * interactive size enforcement disabled so that it fits the compact selection column. It is purely visual: the tap + * is handled by the whole-row click target, so this only reflects [selected]. */ @Composable internal fun SelectionIndicator( selected: Boolean, modifier: Modifier = Modifier, ) { - Icon( - modifier = modifier, - imageVector = if (selected) CompoundIcons.CheckCircleSolid() else CompoundIcons.Circle(), - contentDescription = null, - tint = if (selected) ElementTheme.colors.iconAccentPrimary else ElementTheme.colors.iconTertiary, - ) + CompositionLocalProvider(LocalMinimumInteractiveComponentSize provides Dp.Unspecified) { + Checkbox( + modifier = modifier, + checked = selected, + onCheckedChange = null, + ) + } } @PreviewsDayNight @Composable internal fun SelectionIndicatorPreview() = ElementPreview { - Icon( - modifier = Modifier.size(24.dp), - imageVector = CompoundIcons.Circle(), - contentDescription = null, - tint = ElementTheme.colors.iconTertiary, - ) + SelectionIndicator(selected = false) } @PreviewsDayNight From 0a11e88f06609ddc773bb3eaf5399ce2388a696a Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 25 Sep 2026 18:48:58 +0200 Subject: [PATCH 06/22] Align the selection indicator with the message bubble --- .../timeline/components/MessageEventBubble.kt | 16 +++ .../timeline/components/TimelineItemRow.kt | 130 ++++++++++-------- 2 files changed, 88 insertions(+), 58 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/MessageEventBubble.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/MessageEventBubble.kt index 0dcf489fe3..7f4375e632 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/MessageEventBubble.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/MessageEventBubble.kt @@ -32,6 +32,8 @@ import androidx.compose.ui.graphics.Shape import androidx.compose.ui.graphics.drawOutline import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.graphics.layer.CompositingStrategy +import androidx.compose.ui.layout.HorizontalAlignmentLine +import androidx.compose.ui.layout.layout import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp @@ -53,12 +55,20 @@ import io.element.android.libraries.testtags.TestTags import io.element.android.libraries.testtags.testTag import io.element.android.libraries.ui.utils.a11y.isTalkbackActive import io.element.android.libraries.ui.utils.graphics.drawInLayer +import kotlin.math.min private val BUBBLE_RADIUS = 12.dp private val avatarRadius = AvatarSize.TimelineSender.dp / 2 private val MIN_BUBBLE_WIDTH = 80.dp +/** + * Alignment line published by [MessageEventBubble] at its vertical center. + * It lets the timeline row align decorations with the bubble itself, instead of with the whole row, whose height also + * covers the sender information, the reactions, the thread summary and the read receipts. + */ +val BubbleVerticalCenter = HorizontalAlignmentLine(::min) + @Composable fun MessageEventBubble( state: BubbleState, @@ -93,6 +103,12 @@ fun MessageEventBubble( val updatedBorderColor by rememberUpdatedState(borderColor) BoxWithConstraints( modifier = modifier + .layout { measurable, constraints -> + val placeable = measurable.measure(constraints) + layout(placeable.width, placeable.height, mapOf(BubbleVerticalCenter to placeable.height / 2)) { + placeable.place(0, 0) + } + } .drawWithCache { // Calculate the outline of the background and cache it val outline = bubbleShape.createOutline(size, layoutDirection, this) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt index 7f08aa465e..d547d823a8 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt @@ -8,7 +8,6 @@ package io.element.android.features.messages.impl.timeline.components -import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Box @@ -18,18 +17,20 @@ import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawWithCache import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.layout.AlignmentLine +import androidx.compose.ui.layout.Layout import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.isTraversalGroup import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp @@ -39,7 +40,6 @@ import io.element.android.features.messages.impl.timeline.TimelineRoomInfo import io.element.android.features.messages.impl.timeline.components.event.TimelineItemEventContentView import io.element.android.features.messages.impl.timeline.components.layout.ContentAvoidingLayoutData import io.element.android.features.messages.impl.timeline.model.TimelineItem -import io.element.android.features.messages.impl.timeline.model.canBeSelected import io.element.android.features.messages.impl.timeline.model.event.RtcNotificationState import io.element.android.features.messages.impl.timeline.model.event.TimelineItemLegacyCallInviteContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemPollContent @@ -106,10 +106,7 @@ internal fun TimelineItemRow( val selectionProgress = selectionData.progress val isSelected = selectionData.isSelected val backgroundModifier = when { - isSelected -> { - Modifier.background(ElementTheme.colors.bgAccentSelected) - } - timelineItem.isEvent(focusedEventId) -> { + timelineItem.isEvent(focusedEventId) && !isSelectionModeActive -> { val focusedEventOffset = if ((timelineItem as? TimelineItem.Event)?.showSenderInformation == true) { 14.dp @@ -122,7 +119,7 @@ internal fun TimelineItemRow( Modifier } } - val selectableEvent = (timelineItem as? TimelineItem.Event)?.takeIf { it.canBeSelected() } + val selectableEvent = (timelineItem as? TimelineItem.Event)?.takeIf { selectionData.canBeSelected } // Only start-aligned message bubbles slide to make room for the selection indicator: // - Outgoing (own) messages are end-aligned, opposite the indicator, so they already have room. // - Centered tiles (state events, call tiles, day dividers, grouped events) must stay put. @@ -130,60 +127,77 @@ internal fun TimelineItemRow( val shouldSlideContent = timelineItem.rendersAsBubble() && !isOutgoing val layoutDirection = LocalLayoutDirection.current val contentSlide = if (shouldSlideContent) SELECTION_COLUMN_WIDTH * selectionProgress else 0.dp - Box( - modifier = modifier.then(backgroundModifier) - ) { - TimelineItemRowContent( - modifier = Modifier - .fillMaxWidth() - .offset(x = contentSlide), - selectionContentOffset = contentSlide, - timelineItem = timelineItem, - timelineMode = timelineMode, - timelineRoomInfo = timelineRoomInfo, - timelineProtectionState = timelineProtectionState, - isLastOutgoingMessage = isLastOutgoingMessage, - focusedEventId = focusedEventId, - displayThreadSummaries = displayThreadSummaries, - onUserDataClick = onUserDataClick, - onLinkClick = onLinkClick, - onLinkLongClick = onLinkLongClick, - onContentClick = onContentClick, - onGalleryItemClick = onGalleryItemClick, - onLongClick = onLongClick, - inReplyToClick = inReplyToClick, - onReactionClick = onReactionClick, - onReactionLongClick = onReactionLongClick, - onMoreReactionsClick = onMoreReactionsClick, - onReadReceiptClick = onReadReceiptClick, - onJoinCallClick = onJoinCallClick, - onSwipeToReply = onSwipeToReply, - eventSink = eventSink, - eventContentView = eventContentView, - ) - if (selectableEvent != null && selectionProgress > 0f) { - val slideSign = if (layoutDirection == LayoutDirection.Ltr) -1f else 1f - SelectionIndicator( - selected = isSelected, - modifier = Modifier - .align(Alignment.CenterStart) - .graphicsLayer { translationX = slideSign * SELECTION_COLUMN_WIDTH.toPx() * (1f - selectionProgress) } - .padding(start = 12.dp) - .size(24.dp), - ) - } - if (isSelectionModeActive && selectableEvent != null) { - // In selection mode the whole row toggles selection. - Box( - modifier = Modifier - .matchParentSize() - .clickable { onContentClick(selectableEvent) } - ) + Layout( + modifier = modifier.then(backgroundModifier), + contents = listOf( + { + TimelineItemRowContent( + modifier = Modifier + .fillMaxWidth() + .offset(x = contentSlide), + selectionContentOffset = contentSlide, + timelineItem = timelineItem, + timelineMode = timelineMode, + timelineRoomInfo = timelineRoomInfo, + timelineProtectionState = timelineProtectionState, + isLastOutgoingMessage = isLastOutgoingMessage, + focusedEventId = focusedEventId, + displayThreadSummaries = displayThreadSummaries, + onUserDataClick = onUserDataClick, + onLinkClick = onLinkClick, + onLinkLongClick = onLinkLongClick, + onContentClick = onContentClick, + onGalleryItemClick = onGalleryItemClick, + onLongClick = onLongClick, + inReplyToClick = inReplyToClick, + onReactionClick = onReactionClick, + onReactionLongClick = onReactionLongClick, + onMoreReactionsClick = onMoreReactionsClick, + onReadReceiptClick = onReadReceiptClick, + onJoinCallClick = onJoinCallClick, + onSwipeToReply = onSwipeToReply, + eventSink = eventSink, + eventContentView = eventContentView, + ) + }, + { + if (selectableEvent != null && selectionProgress > 0f) { + val slideSign = if (layoutDirection == LayoutDirection.Ltr) -1f else 1f + SelectionIndicator( + selected = isSelected, + modifier = Modifier + .graphicsLayer { translationX = slideSign * SELECTION_COLUMN_WIDTH.toPx() * (1f - selectionProgress) } + .padding(start = 16.dp) + .size(24.dp), + ) + } + }, + { + if (isSelectionModeActive && selectableEvent != null) { + // In selection mode the whole row toggles selection. + Box(modifier = Modifier.clickable { onContentClick(selectableEvent) }) + } + }, + ), + ) { (contentMeasurables, indicatorMeasurables, overlayMeasurables), constraints -> + val contentPlaceable = contentMeasurables.first().measure(constraints) + val width = contentPlaceable.width + val height = contentPlaceable.height + val indicatorPlaceable = indicatorMeasurables.firstOrNull()?.measure(constraints.copy(minWidth = 0, minHeight = 0)) + val overlayPlaceable = overlayMeasurables.firstOrNull()?.measure(Constraints.fixed(width, height)) + layout(width = width, height = height) { + contentPlaceable.place(0, 0) + if (indicatorPlaceable != null) { + val bubbleCenter = contentPlaceable[BubbleVerticalCenter].takeIf { it != AlignmentLine.Unspecified } ?: (height / 2) + val x = if (layoutDirection == LayoutDirection.Ltr) 0 else width - indicatorPlaceable.width + indicatorPlaceable.place(x = x, y = bubbleCenter - indicatorPlaceable.height / 2) + } + overlayPlaceable?.place(0, 0) } } } -/** Width reserved for the selection indicator; the row content slides by this amount. */ +/** Width reserved for the selection indicator : the row content slides by this amount. */ private val SELECTION_COLUMN_WIDTH = 36.dp /** From 971f196d5429d6a4604a5529106c517db9b22b75 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 25 Sep 2026 18:48:58 +0200 Subject: [PATCH 07/22] Intercept clicks on every row in selection mode --- .../messages/impl/timeline/components/TimelineItemRow.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt index d547d823a8..3db8508617 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt @@ -27,6 +27,7 @@ import androidx.compose.ui.layout.AlignmentLine import androidx.compose.ui.layout.Layout import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.Role import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.isTraversalGroup import androidx.compose.ui.semantics.semantics @@ -173,9 +174,12 @@ internal fun TimelineItemRow( } }, { - if (isSelectionModeActive && selectableEvent != null) { + if (isSelectionModeActive) { // In selection mode the whole row toggles selection. - Box(modifier = Modifier.clickable { onContentClick(selectableEvent) }) + Box(modifier = Modifier.clickable(enabled = selectionData.canBeSelected, role = Role.Checkbox) { + if(selectableEvent != null) + onContentClick(selectableEvent) + }) } }, ), From d8b66945754046bcac6f1b2b47b93c35a306f69c Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 25 Sep 2026 18:50:51 +0200 Subject: [PATCH 08/22] Apply ktlint formatting --- .../android/features/messages/impl/timeline/TimelineState.kt | 4 ++-- .../messages/impl/timeline/components/TimelineItemRow.kt | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt index bc571f6634..f8976de874 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineState.kt @@ -112,7 +112,7 @@ val TimelineState.selectedCount: Int fun TimelineState.isSelected(item: TimelineItem): Boolean { val selection = selectionState as? SelectionState.Active ?: return false - return when(item){ + return when (item) { is TimelineItem.Event -> selection.selectedEventIds.contains(item.eventId) else -> false } @@ -123,7 +123,7 @@ fun TimelineState.isSelected(item: TimelineItem): Boolean { */ fun TimelineState.canSelect(item: TimelineItem): Boolean { val selection = selectionState as? SelectionState.Active ?: return false - return when(item) { + return when (item) { is TimelineItem.Event -> selection.action.canApplyTo(item) else -> false } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt index 3db8508617..6f26b8c441 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt @@ -177,8 +177,9 @@ internal fun TimelineItemRow( if (isSelectionModeActive) { // In selection mode the whole row toggles selection. Box(modifier = Modifier.clickable(enabled = selectionData.canBeSelected, role = Role.Checkbox) { - if(selectableEvent != null) - onContentClick(selectableEvent) + if (selectableEvent != null) { + onContentClick(selectableEvent) + } }) } }, From 69a1870f58a952c6e78ddcbbdf0087348e30a361 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 29 Sep 2026 16:35:33 +0200 Subject: [PATCH 09/22] Use existing strings --- .../messages/impl/timeline/TimelinePresenter.kt | 3 ++- .../messages/impl/topbars/SelectionModeTopBar.kt | 3 ++- .../impl/src/main/res/values/temporary.xml | 15 --------------- 3 files changed, 4 insertions(+), 17 deletions(-) delete mode 100644 features/messages/impl/src/main/res/values/temporary.xml diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt index 320e362024..a712e47cba 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt @@ -63,6 +63,7 @@ import io.element.android.libraries.matrix.api.timeline.Timeline import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState import io.element.android.libraries.matrix.api.timeline.item.event.TimelineItemEventOrigin import io.element.android.libraries.preferences.api.store.SessionPreferencesStore +import io.element.android.libraries.ui.strings.CommonStrings import io.element.android.services.analytics.api.AnalyticsLongRunningTransaction.DisplayFirstTimelineItems import io.element.android.services.analytics.api.AnalyticsLongRunningTransaction.NotificationToMessage import io.element.android.services.analytics.api.AnalyticsLongRunningTransaction.OpenRoom @@ -275,7 +276,7 @@ class TimelinePresenter( if (next.isEmpty()) SelectionState.Disabled else current.copy(selectedEventIds = next) } selected.size >= MAX_SELECTION_COUNT -> { - snackbarDispatcher.post(SnackbarMessage(R.string.screen_room_timeline_selection_limit_reached)) + snackbarDispatcher.post(SnackbarMessage(CommonStrings.screen_room_maximum_messages_selected)) current } else -> current.copy(selectedEventIds = (selected + event.eventId).toPersistentSet()) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt index 1e96d7b1e1..e918c0da2b 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt @@ -23,6 +23,7 @@ import io.element.android.libraries.designsystem.theme.components.Icon import io.element.android.libraries.designsystem.theme.components.IconButton import io.element.android.libraries.designsystem.theme.components.Text import io.element.android.libraries.designsystem.theme.components.TopAppBar +import io.element.android.libraries.ui.strings.CommonPlurals import io.element.android.libraries.ui.strings.CommonStrings @OptIn(ExperimentalMaterial3Api::class) @@ -37,7 +38,7 @@ fun SelectionModeTopBar( TopAppBar( modifier = modifier, title = { - Text(text = pluralStringResource(R.plurals.screen_room_timeline_selection_title, selectedCount, selectedCount)) + Text(text = pluralStringResource(CommonPlurals.common_selected_count, selectedCount, selectedCount)) }, navigationIcon = { IconButton( diff --git a/features/messages/impl/src/main/res/values/temporary.xml b/features/messages/impl/src/main/res/values/temporary.xml deleted file mode 100644 index 5dfeaa7b85..0000000000 --- a/features/messages/impl/src/main/res/values/temporary.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - %1$d selected - %1$d selected - - You can select up to 30 messages - From 62f9b7f0b40cc112b3fdc68c26438ea4d6fc7ae8 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 29 Sep 2026 20:53:51 +0200 Subject: [PATCH 10/22] Use "Forward to" as forward screen title --- .../android/libraries/roomselect/impl/RoomSelectView.kt | 2 +- libraries/ui-strings/src/main/res/values/localazy.xml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt b/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt index 43b91068f9..118acf25cb 100644 --- a/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt +++ b/libraries/roomselect/impl/src/main/kotlin/io/element/android/libraries/roomselect/impl/RoomSelectView.kt @@ -123,7 +123,7 @@ fun RoomSelectView( topBar = { TopAppBar( titleStr = when (state.mode) { - RoomSelectMode.Forward -> stringResource(CommonStrings.common_forward_message) + RoomSelectMode.Forward -> stringResource(CommonStrings.common_forward_to) RoomSelectMode.Share -> stringResource(CommonStrings.common_send_to) }, navigationIcon = { diff --git a/libraries/ui-strings/src/main/res/values/localazy.xml b/libraries/ui-strings/src/main/res/values/localazy.xml index 7a0ce8fd4e..0079c8f47e 100644 --- a/libraries/ui-strings/src/main/res/values/localazy.xml +++ b/libraries/ui-strings/src/main/res/values/localazy.xml @@ -98,6 +98,7 @@ "Choose file" "Choose photo" "Clear" + "Clear all" "Close" "Complete verification" "Confirm" @@ -286,6 +287,7 @@ Reason: %1$s." "File saved" "File saved to Downloads" "Forward message" + "Forward to" "Frequently used" "Gallery" @@ -412,6 +414,7 @@ Reason: %1$s." "Shared live location" "Shared location" "Shared space" + "Signed in" "Removing device" "Something went wrong" "We encountered an issue. Please try again." From bb649838322fc56b06e1b00ca680a24f2fb95c3c Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 30 Sep 2026 11:48:31 +0200 Subject: [PATCH 11/22] Move TimelineItemSelectionData to model package --- .../messages/impl/pinned/list/PinnedMessagesListView.kt | 2 +- .../features/messages/impl/timeline/TimelinePresenter.kt | 1 - .../features/messages/impl/timeline/TimelineView.kt | 2 +- .../timeline/components/TimelineItemGroupedEventsRow.kt | 1 + .../messages/impl/timeline/components/TimelineItemRow.kt | 1 + .../{components => model}/TimelineItemSelectionData.kt | 8 +++++--- .../features/messages/impl/topbars/SelectionModeTopBar.kt | 1 - 7 files changed, 9 insertions(+), 7 deletions(-) rename features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/{components => model}/TimelineItemSelectionData.kt (66%) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/list/PinnedMessagesListView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/list/PinnedMessagesListView.kt index c47b93b02b..f7bba24f95 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/list/PinnedMessagesListView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/pinned/list/PinnedMessagesListView.kt @@ -33,13 +33,13 @@ import io.element.android.features.messages.impl.link.LinkEvent import io.element.android.features.messages.impl.link.LinkView import io.element.android.features.messages.impl.timeline.TimelineEvent import io.element.android.features.messages.impl.timeline.components.TimelineItemRow -import io.element.android.features.messages.impl.timeline.components.TimelineItemSelectionData import io.element.android.features.messages.impl.timeline.components.customreaction.CustomReactionBottomSheet import io.element.android.features.messages.impl.timeline.components.customreaction.CustomReactionEvent import io.element.android.features.messages.impl.timeline.components.event.TimelineItemEventContentView import io.element.android.features.messages.impl.timeline.components.reactionsummary.ReactionSummaryEvent import io.element.android.features.messages.impl.timeline.components.reactionsummary.ReactionSummaryView import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.TimelineItemSelectionData import io.element.android.features.messages.impl.timeline.model.event.TimelineItemPollContent import io.element.android.features.messages.impl.timeline.protection.TimelineProtectionState import io.element.android.features.poll.api.pollcontent.PollTitleView diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt index 3c0c22a2e9..c46e28de1a 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt @@ -25,7 +25,6 @@ import dev.zacsweers.metro.AssistedFactory import dev.zacsweers.metro.AssistedInject import io.element.android.features.location.api.live.ActiveLiveLocationShareManager import io.element.android.features.messages.impl.MessagesNavigator -import io.element.android.features.messages.impl.R import io.element.android.features.messages.impl.UserEventPermissions import io.element.android.features.messages.impl.crypto.sendfailure.resolve.ResolveVerifiedUserSendFailureEvent import io.element.android.features.messages.impl.crypto.sendfailure.resolve.ResolveVerifiedUserSendFailureState diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt index 71c7bd3540..f948f478b5 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt @@ -84,13 +84,13 @@ import io.element.android.compound.tokens.generated.CompoundIcons import io.element.android.features.messages.impl.crypto.sendfailure.resolve.ResolveVerifiedUserSendFailureView import io.element.android.features.messages.impl.timeline.components.FloatingDateBadgeOverlay import io.element.android.features.messages.impl.timeline.components.TimelineItemRow -import io.element.android.features.messages.impl.timeline.components.TimelineItemSelectionData import io.element.android.features.messages.impl.timeline.components.toText import io.element.android.features.messages.impl.timeline.di.LocalTimelineItemPresenterFactories import io.element.android.features.messages.impl.timeline.di.aFakeTimelineItemPresenterFactories import io.element.android.features.messages.impl.timeline.focus.FocusRequestStateView import io.element.android.features.messages.impl.timeline.model.NewEventState import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.TimelineItemSelectionData import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemEventContentPreviewParam import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemTextContent diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemGroupedEventsRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemGroupedEventsRow.kt index 1cd10fdf01..b03b76dd79 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemGroupedEventsRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemGroupedEventsRow.kt @@ -27,6 +27,7 @@ import io.element.android.features.messages.impl.timeline.components.receipt.Rea import io.element.android.features.messages.impl.timeline.components.receipt.TimelineItemReadReceiptView import io.element.android.features.messages.impl.timeline.groups.isRedactedMessagesGroup import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.TimelineItemSelectionData import io.element.android.features.messages.impl.timeline.protection.TimelineProtectionState import io.element.android.features.messages.impl.timeline.protection.aTimelineProtectionState import io.element.android.libraries.designsystem.preview.ElementPreview diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt index e1b3204552..32cef08ea7 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt @@ -40,6 +40,7 @@ import io.element.android.features.messages.impl.timeline.TimelineEvent import io.element.android.features.messages.impl.timeline.TimelineRoomInfo import io.element.android.features.messages.impl.timeline.components.event.TimelineItemEventContentView import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.TimelineItemSelectionData import io.element.android.features.messages.impl.timeline.model.event.RtcNotificationState import io.element.android.features.messages.impl.timeline.model.event.TimelineItemLegacyCallInviteContent import io.element.android.features.messages.impl.timeline.model.event.TimelineItemPollContent diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemSelectionData.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionData.kt similarity index 66% rename from features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemSelectionData.kt rename to features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionData.kt index 641be44fe8..60a30d5c73 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemSelectionData.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionData.kt @@ -1,14 +1,14 @@ /* - * Copyright 2026 New Vector Ltd. + * 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.messages.impl.timeline.components +package io.element.android.features.messages.impl.timeline.model /** - * Row-scoped selection state passed to [TimelineItemRow]. + * Row-scoped selection state passed to [io.element.android.features.messages.impl.timeline.components.TimelineItemRow]. * * @param isSelectionModeActive whether the timeline is currently in selection mode. Drives * behaviour (e.g. the whole-row click target) and must reflect the real mode, not [progress]. @@ -16,6 +16,8 @@ package io.element.android.features.messages.impl.timeline.components * Animated once in TimelineView and shared by every row. Differs from [isSelectionModeActive] * during the enter/exit animation. * @param isSelected whether this specific row's event is part of the current selection. + * @param canBeSelected whether this specific row's event can be selected for the action selection mode was entered for. + * Rows which cannot be selected render no indicator, and their content does not slide. */ data class TimelineItemSelectionData( val isSelectionModeActive: Boolean = false, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt index e918c0da2b..1d12699277 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt @@ -15,7 +15,6 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider import io.element.android.compound.tokens.generated.CompoundIcons -import io.element.android.features.messages.impl.R import io.element.android.features.messages.impl.timeline.SelectionAction import io.element.android.libraries.designsystem.preview.ElementPreview import io.element.android.libraries.designsystem.preview.PreviewsDayNight From ae409aa8d2da4fbeeeaec22fabe0d7b44e020df6 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 30 Sep 2026 11:49:26 +0200 Subject: [PATCH 12/22] Add preview for messages view in selection mode --- .../features/messages/impl/MessagesView.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt index 9097ed682b..b4f084ebd6 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt @@ -77,13 +77,16 @@ import io.element.android.features.messages.impl.pinned.banner.PinnedMessagesBan import io.element.android.features.messages.impl.pinned.banner.PinnedMessagesBannerView import io.element.android.features.messages.impl.pinned.banner.PinnedMessagesBannerViewDefaults import io.element.android.features.messages.impl.timeline.FOCUS_ON_PINNED_EVENT_DEBOUNCE_DURATION_IN_MILLIS +import io.element.android.features.messages.impl.timeline.SelectionAction import io.element.android.features.messages.impl.timeline.SelectionState import io.element.android.features.messages.impl.timeline.TimelineEvent import io.element.android.features.messages.impl.timeline.TimelineView import io.element.android.features.messages.impl.timeline.aGroupedEvents import io.element.android.features.messages.impl.timeline.aTimelineItemDaySeparator import io.element.android.features.messages.impl.timeline.aTimelineItemEvent +import io.element.android.features.messages.impl.timeline.aTimelineItemList import io.element.android.features.messages.impl.timeline.aTimelineState +import io.element.android.features.messages.impl.timeline.canApplyTo import io.element.android.features.messages.impl.timeline.components.CallMenuItem import io.element.android.features.messages.impl.timeline.components.customreaction.CustomReactionEvent import io.element.android.features.messages.impl.timeline.components.reactionsummary.ReactionSummaryEvent @@ -138,6 +141,7 @@ import io.element.android.libraries.textcomposer.model.TextEditorState import io.element.android.libraries.ui.strings.CommonStrings import io.element.android.wysiwyg.link.Link import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.toPersistentSet import timber.log.Timber import kotlin.time.Duration.Companion.milliseconds @@ -756,6 +760,40 @@ internal fun MessagesViewPreview(@PreviewParameter(MessagesStatePreviewParam::cl ) } +@PreviewsDayNight +@Composable +internal fun MessagesViewSelectionModePreview() = ElementPreview { + val timelineItems = aTimelineItemList(aTimelineItemTextContent()) + val selectedEventIds = timelineItems + .filterIsInstance() + .filter { SelectionAction.Forward.canApplyTo(it) } + .take(2) + .mapNotNull { it.eventId } + .toPersistentSet() + MessagesView( + state = aMessagesState( + timelineState = aTimelineState( + timelineItems = timelineItems, + selectionState = SelectionState.Active(SelectionAction.Forward, selectedEventIds), + ), + ), + onBackClick = {}, + onRoomDetailsClick = {}, + onEventContentClick = { _, _ -> false }, + onGalleryEventItemClick = { _, _, _ -> false }, + onUserDataClick = {}, + onLinkClick = { _, _ -> }, + onSendLocationClick = {}, + onCreatePollClick = {}, + onJoinCallClick = {}, + onViewAllPinnedMessagesClick = { }, + forceJumpToBottomVisibility = true, + knockRequestsBannerView = {}, + customReactionBottomSheet = {}, + onThreadsListClick = {}, + ) +} + @Preview @Composable internal fun MessagesViewA11yPreview() = ElementPreview { From e99861a5c12a3f778eef5df46231955337e0cb94 Mon Sep 17 00:00:00 2001 From: ganfra Date: Fri, 2 Oct 2026 20:41:04 +0200 Subject: [PATCH 13/22] Keep selection mode active until explicitly exited --- .../features/messages/impl/MessagesView.kt | 5 ++ .../messages/impl/timeline/SelectionState.kt | 42 ++++++++- .../impl/timeline/TimelinePresenter.kt | 36 +++----- .../impl/timeline/SelectionStateTest.kt | 89 +++++++++++++++++++ .../impl/timeline/TimelinePresenterTest.kt | 70 ++++++++++++--- 5 files changed, 204 insertions(+), 38 deletions(-) create mode 100644 features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt index b4f084ebd6..92c91dfee5 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt @@ -8,6 +8,7 @@ package io.element.android.features.messages.impl +import androidx.activity.compose.BackHandler import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.expandVertically import androidx.compose.animation.shrinkVertically @@ -194,6 +195,10 @@ fun MessagesView( } } + BackHandler(enabled = state.timelineState.isSelectionModeActive) { + state.timelineState.eventSink(TimelineEvent.ExitSelectionMode) + } + fun onContentClick(event: TimelineItem.Event) { Timber.v("onMessageClick= ${event.id}") val eventId = event.eventId diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt index f2738480aa..7a9f073bc0 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt @@ -16,6 +16,7 @@ import io.element.android.features.messages.impl.timeline.model.event.canBeForwa import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.ui.strings.CommonStrings import kotlinx.collections.immutable.ImmutableSet +import kotlinx.collections.immutable.toPersistentSet /** Maximum number of messages that can be selected at once. */ const val MAX_SELECTION_COUNT = 10 @@ -25,7 +26,10 @@ sealed interface SelectionState { /** Selection mode is not active. */ data object Disabled : SelectionState - /** Selection mode is active for [action], with the given selection. */ + /** + * Selection mode is active for [action], with the given selection. + * [selectedEventIds] can be empty: selection mode is never exited automatically, only when the user explicitly leaves it. + */ data class Active( val action: SelectionAction, val selectedEventIds: ImmutableSet, @@ -46,3 +50,39 @@ enum class SelectionAction(@field:StringRes val titleRes: Int, @field:DrawableRe fun SelectionAction.canApplyTo(event: TimelineItem.Event): Boolean = when (this) { SelectionAction.Forward -> event.isRemote && event.content.canBeForwarded() } + +/** + * This selection without [eventIds]. + * Selection mode stays active even when nothing remains selected, see [SelectionState.Active]. + */ +fun SelectionState.deselect(eventIds: Set): SelectionState = when (this) { + SelectionState.Disabled -> this + is SelectionState.Active -> copy(selectedEventIds = (selectedEventIds - eventIds).toPersistentSet()) +} + +/** + * The ids of the selected events which [SelectionState.Active.action] cannot be applied to anymore, for instance because the message has been + * deleted. They are meant to be given to [deselect]. + */ +fun SelectionState.eventIdsToDeselect(timelineItems: List): Set { + val selection = this as? SelectionState.Active ?: return emptySet() + if (selection.selectedEventIds.isEmpty()) return emptySet() + val result = mutableSetOf() + + fun process(event: TimelineItem.Event) { + val eventId = event.eventId ?: return + if (eventId in selection.selectedEventIds && !selection.action.canApplyTo(event)) { + result.add(eventId) + } + } + + timelineItems.forEach { item -> + when (item) { + is TimelineItem.Event -> process(item) + // A deleted message can be folded into a group of deleted messages, so look inside the groups too. + is TimelineItem.GroupedEvents -> item.events.forEach(::process) + is TimelineItem.Virtual -> Unit + } + } + return result +} diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt index c46e28de1a..a7d4641085 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt @@ -77,9 +77,11 @@ import kotlinx.collections.immutable.toPersistentSet import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -273,10 +275,8 @@ class TimelinePresenter( val current = selectionState as? SelectionState.Active ?: return val selected = current.selectedEventIds selectionState = when { - event.eventId in selected -> { - val next = (selected - event.eventId).toPersistentSet() - if (next.isEmpty()) SelectionState.Disabled else current.copy(selectedEventIds = next) - } + // Deselecting the last event does not exit selection mode: it is only left explicitly, as on iOS. + event.eventId in selected -> current.deselect(setOf(event.eventId)) selected.size >= MAX_SELECTION_COUNT -> { snackbarDispatcher.post(SnackbarMessage(CommonStrings.screen_room_maximum_messages_selected)) current @@ -371,6 +371,14 @@ class TimelinePresenter( } .launchIn(this) + // Drop the selected events which the action cannot be applied to anymore, for instance because the message has been deleted. + timelineItemsFactory.timelineItems + .map { items -> selectionState.eventIdsToDeselect(items) } + .filter { eventIdsToDeselect -> eventIdsToDeselect.isNotEmpty() } + .flowOn(dispatchers.computation) + .onEach { eventIdsToDeselect -> selectionState = selectionState.deselect(eventIdsToDeselect) } + .launchIn(this) + combine( timelineController.timelineItems(), room.membersStateFlow, @@ -396,26 +404,6 @@ class TimelinePresenter( computeNewItemState(timelineItems, prevMostRecentItemId, newEventState) } - val selectableEventIds = (selectionState as? SelectionState.Active)?.let { active -> - timelineItems - .filterIsInstance() - .filter { active.action.canApplyTo(it) } - .mapNotNull { it.eventId } - .toSet() - }.orEmpty() - - // Reconcile the selection when the items change: drop any selected event that is no longer - // present or no longer selectable, and exit selection mode if nothing remains selected. - LaunchedEffect(selectableEventIds) { - val active = selectionState as? SelectionState.Active ?: return@LaunchedEffect - val reconciled = active.selectedEventIds.filter { it in selectableEventIds }.toPersistentSet() - selectionState = when { - reconciled.isEmpty() -> SelectionState.Disabled - reconciled.size != active.selectedEventIds.size -> active.copy(selectedEventIds = reconciled) - else -> active - } - } - // Keyed on the full [timelineItems] reference (not just .size) so we re-scan when the // read marker advances in place — the SDK swaps the marker virtual item to a new position // without changing the list length, e.g. when [markRoomAsFullyRead] is sent while at the diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt new file mode 100644 index 0000000000..ea45813a10 --- /dev/null +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt @@ -0,0 +1,89 @@ +/* + * Copyright 2026 New Vector 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.messages.impl.timeline + +import com.google.common.truth.Truth.assertThat +import io.element.android.features.messages.impl.timeline.model.TimelineItem +import io.element.android.features.messages.impl.timeline.model.event.aTimelineItemRedactedContent +import io.element.android.libraries.matrix.api.core.EventId +import io.element.android.libraries.matrix.api.core.UniqueId +import io.element.android.libraries.matrix.test.AN_EVENT_ID +import io.element.android.libraries.matrix.test.AN_EVENT_ID_2 +import io.element.android.libraries.matrix.test.AN_EVENT_ID_3 +import kotlinx.collections.immutable.persistentListOf +import kotlinx.collections.immutable.toPersistentSet +import org.junit.Test + +class SelectionStateTest { + @Test + fun `eventIdsToDeselect - selection mode being disabled has nothing to drop`() { + val items = listOf(aTimelineItemEvent(eventId = AN_EVENT_ID, content = aTimelineItemRedactedContent())) + assertThat(SelectionState.Disabled.eventIdsToDeselect(items)).isEmpty() + } + + @Test + fun `eventIdsToDeselect - an empty selection has nothing to drop`() { + val items = listOf(aTimelineItemEvent(eventId = AN_EVENT_ID, content = aTimelineItemRedactedContent())) + assertThat(anActiveSelection().eventIdsToDeselect(items)).isEmpty() + } + + @Test + fun `eventIdsToDeselect - a selected event the action still applies to is kept`() { + val items = listOf(aTimelineItemEvent(eventId = AN_EVENT_ID)) + assertThat(anActiveSelection(listOf(AN_EVENT_ID)).eventIdsToDeselect(items)).isEmpty() + } + + @Test + fun `eventIdsToDeselect - a selected event which has been deleted is dropped`() { + val items = listOf( + aTimelineItemEvent(eventId = AN_EVENT_ID_2, content = aTimelineItemRedactedContent()), + aTimelineItemEvent(eventId = AN_EVENT_ID), + ) + assertThat(anActiveSelection(listOf(AN_EVENT_ID, AN_EVENT_ID_2)).eventIdsToDeselect(items)).containsExactly(AN_EVENT_ID_2) + } + + @Test + fun `eventIdsToDeselect - a selected event which is not in the timeline is ignored`() { + val items = listOf(aTimelineItemEvent(eventId = AN_EVENT_ID)) + // AN_EVENT_ID_3 may simply not be loaded anymore, so it is not dropped here. + assertThat(anActiveSelection(listOf(AN_EVENT_ID, AN_EVENT_ID_3)).eventIdsToDeselect(items)).isEmpty() + } + + @Test + fun `eventIdsToDeselect - a deleted selected event folded into a group is dropped`() { + val items = listOf( + TimelineItem.GroupedEvents( + id = UniqueId("group"), + events = persistentListOf( + aTimelineItemEvent(eventId = AN_EVENT_ID_2, content = aTimelineItemRedactedContent()), + aTimelineItemEvent(eventId = AN_EVENT_ID_3, content = aTimelineItemRedactedContent()), + ), + aggregatedReadReceipts = persistentListOf(), + ), + aTimelineItemEvent(eventId = AN_EVENT_ID), + ) + assertThat(anActiveSelection(listOf(AN_EVENT_ID, AN_EVENT_ID_2)).eventIdsToDeselect(items)).containsExactly(AN_EVENT_ID_2) + } + + @Test + fun `deselect - removes the given events and keeps selection mode active`() { + val selection = anActiveSelection(listOf(AN_EVENT_ID, AN_EVENT_ID_2)) + assertThat(selection.deselect(setOf(AN_EVENT_ID))).isEqualTo(anActiveSelection(listOf(AN_EVENT_ID_2))) + assertThat(selection.deselect(setOf(AN_EVENT_ID, AN_EVENT_ID_2))).isEqualTo(anActiveSelection()) + } + + @Test + fun `deselect - does nothing when selection mode is disabled`() { + assertThat(SelectionState.Disabled.deselect(setOf(AN_EVENT_ID))).isEqualTo(SelectionState.Disabled) + } + + private fun anActiveSelection(eventIds: List = emptyList()) = SelectionState.Active( + action = SelectionAction.Forward, + selectedEventIds = eventIds.toPersistentSet(), + ) +} diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt index 45667e298c..eeb97befff 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenterTest.kt @@ -50,10 +50,8 @@ import io.element.android.libraries.matrix.api.timeline.ReceiptType import io.element.android.libraries.matrix.api.timeline.Timeline import io.element.android.libraries.matrix.api.timeline.item.event.EventReaction import io.element.android.libraries.matrix.api.timeline.item.event.LocalEventSendState -import io.element.android.libraries.matrix.api.timeline.item.event.OtherState import io.element.android.libraries.matrix.api.timeline.item.event.ReactionSender import io.element.android.libraries.matrix.api.timeline.item.event.Receipt -import io.element.android.libraries.matrix.api.timeline.item.event.StateContent import io.element.android.libraries.matrix.api.timeline.item.event.TimelineItemEventOrigin import io.element.android.libraries.matrix.api.timeline.item.virtual.VirtualTimelineItem import io.element.android.libraries.matrix.test.AN_EVENT_ID @@ -1862,7 +1860,7 @@ class TimelinePresenterTest { } @Test - fun `present - toggling the last selected event exits selection mode`() = runTest { + fun `present - toggling the last selected event keeps selection mode active`() = runTest { val timelineItems = MutableStateFlow( listOf(MatrixTimelineItem.Event(UniqueId("1"), anEventTimelineItem(eventId = AN_EVENT_ID, content = aMessageContent()))) ) @@ -1875,6 +1873,28 @@ class TimelinePresenterTest { initialState.eventSink(TimelineEvent.EnterSelectionMode(SelectionAction.Forward, AN_EVENT_ID)) consumeItemsUntilPredicate { it.isSelectionModeActive } initialState.eventSink(TimelineEvent.ToggleSelection(AN_EVENT_ID)) + // Selection mode is only exited explicitly, so an empty selection keeps it active. + val state = consumeItemsUntilPredicate { it.selectedCount == 0 }.last() + assertThat(state.selectionState).isEqualTo(SelectionState.Active(SelectionAction.Forward, persistentSetOf())) + assertThat(state.isSelectionModeActive).isTrue() + cancelAndIgnoreRemainingEvents() + } + } + + @Test + fun `present - exiting selection mode clears the selection`() = runTest { + val timelineItems = MutableStateFlow( + listOf(MatrixTimelineItem.Event(UniqueId("1"), anEventTimelineItem(eventId = AN_EVENT_ID, content = aMessageContent()))) + ) + val presenter = createTimelinePresenter( + timeline = FakeTimeline(timelineItems = timelineItems), + featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to true)), + ) + presenter.test { + val initialState = consumeItemsUntilPredicate { it.hasAnyEvent }.last() + initialState.eventSink(TimelineEvent.EnterSelectionMode(SelectionAction.Forward, AN_EVENT_ID)) + consumeItemsUntilPredicate { it.isSelectionModeActive } + initialState.eventSink(TimelineEvent.ExitSelectionMode) val state = consumeItemsUntilPredicate { !it.isSelectionModeActive }.last() assertThat(state.selectionState).isEqualTo(SelectionState.Disabled) cancelAndIgnoreRemainingEvents() @@ -1903,7 +1923,35 @@ class TimelinePresenterTest { } @Test - fun `present - selection drops events the action cannot apply to`() = runTest { + fun `present - a selected event which cannot be forwarded anymore is deselected`() = runTest { + val timelineItems = MutableStateFlow( + listOf( + MatrixTimelineItem.Event(UniqueId("1"), anEventTimelineItem(eventId = AN_EVENT_ID, content = aMessageContent())), + MatrixTimelineItem.Event(UniqueId("2"), anEventTimelineItem(eventId = AN_EVENT_ID_2, content = aMessageContent())), + ) + ) + val presenter = createTimelinePresenter( + timeline = FakeTimeline(timelineItems = timelineItems), + featureFlagService = FakeFeatureFlagService(initialState = mapOf(FeatureFlags.MessageMultiSelect.key to true)), + ) + presenter.test { + val initialState = consumeItemsUntilPredicate { it.hasAnyEvent }.last() + initialState.eventSink(TimelineEvent.EnterSelectionMode(SelectionAction.Forward, AN_EVENT_ID)) + initialState.eventSink(TimelineEvent.ToggleSelection(AN_EVENT_ID_2)) + consumeItemsUntilPredicate { it.selectedCount == 2 } + // The first message is deleted, so it cannot be forwarded anymore. + timelineItems.value = listOf( + MatrixTimelineItem.Event(UniqueId("1"), anEventTimelineItem(eventId = AN_EVENT_ID, content = aRedactedContent())), + MatrixTimelineItem.Event(UniqueId("2"), anEventTimelineItem(eventId = AN_EVENT_ID_2, content = aMessageContent())), + ) + val state = consumeItemsUntilPredicate { it.selectedCount == 1 }.last() + assertThat(state.selectionState).isEqualTo(SelectionState.Active(SelectionAction.Forward, persistentSetOf(AN_EVENT_ID_2))) + cancelAndIgnoreRemainingEvents() + } + } + + @Test + fun `present - the selection survives a timeline which no longer contains the selected event`() = runTest { val timelineItems = MutableStateFlow( listOf(MatrixTimelineItem.Event(UniqueId("1"), anEventTimelineItem(eventId = AN_EVENT_ID, content = aMessageContent()))) ) @@ -1915,15 +1963,11 @@ class TimelinePresenterTest { val initialState = consumeItemsUntilPredicate { it.hasAnyEvent }.last() initialState.eventSink(TimelineEvent.EnterSelectionMode(SelectionAction.Forward, AN_EVENT_ID)) consumeItemsUntilPredicate { it.isSelectionModeActive } - // The message is replaced by a state event, which cannot be forwarded. - timelineItems.value = listOf( - MatrixTimelineItem.Event( - UniqueId("1"), - anEventTimelineItem(eventId = AN_EVENT_ID, content = StateContent("", OtherState.RoomCreate)), - ) - ) - val state = consumeItemsUntilPredicate { !it.isSelectionModeActive }.last() - assertThat(state.selectionState).isEqualTo(SelectionState.Disabled) + // The timeline no longer holds the selected event, for instance because it has been reset or because it switched to a detached timeline. + timelineItems.value = emptyList() + val state = consumeItemsUntilPredicate { !it.hasAnyEvent }.last() + // The selection is the user intent: it is only validated when the action is confirmed, so that a transient timeline update cannot drop it. + assertThat(state.selectionState).isEqualTo(SelectionState.Active(SelectionAction.Forward, persistentSetOf(AN_EVENT_ID))) cancelAndIgnoreRemainingEvents() } } From 721cedbc459947eb7a5c8a516bf54b6d1d65da6c Mon Sep 17 00:00:00 2001 From: ElementBot Date: Mon, 5 Oct 2026 16:25:38 +0000 Subject: [PATCH 14/22] Update screenshots --- ...imeline.components_SelectionIndicatorSelected_Day_0_en.png | 3 +++ ...eline.components_SelectionIndicatorSelected_Night_0_en.png | 3 +++ ...s.impl.timeline.components_SelectionIndicator_Day_0_en.png | 3 +++ ...impl.timeline.components_SelectionIndicator_Night_0_en.png | 3 +++ ...sages.impl.timeline_TimelineViewSelectionMode_Day_0_en.png | 3 +++ ...ges.impl.timeline_TimelineViewSelectionMode_Night_0_en.png | 3 +++ ...res.messages.impl.topbars_SelectionModeTopBar_Day_0_en.png | 3 +++ ...res.messages.impl.topbars_SelectionModeTopBar_Day_1_en.png | 3 +++ ...res.messages.impl.topbars_SelectionModeTopBar_Day_2_en.png | 3 +++ ...s.messages.impl.topbars_SelectionModeTopBar_Night_0_en.png | 3 +++ ...s.messages.impl.topbars_SelectionModeTopBar_Night_1_en.png | 3 +++ ...s.messages.impl.topbars_SelectionModeTopBar_Night_2_en.png | 3 +++ ...tures.messages.impl_MessagesViewSelectionMode_Day_0_en.png | 3 +++ ...res.messages.impl_MessagesViewSelectionMode_Night_0_en.png | 3 +++ .../libraries.roomselect.impl_RoomSelectView_Day_0_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Day_1_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Day_2_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Day_3_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Day_4_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Night_0_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Night_1_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Night_2_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Night_3_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Night_4_en.png | 4 ++-- 24 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicatorSelected_Day_0_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicatorSelected_Night_0_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicator_Day_0_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicator_Night_0_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.timeline_TimelineViewSelectionMode_Day_0_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.timeline_TimelineViewSelectionMode_Night_0_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_0_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_1_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_2_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_0_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_1_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_2_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl_MessagesViewSelectionMode_Day_0_en.png create mode 100644 tests/uitests/src/test/snapshots/images/features.messages.impl_MessagesViewSelectionMode_Night_0_en.png diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicatorSelected_Day_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicatorSelected_Day_0_en.png new file mode 100644 index 0000000000..daa500f1ca --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicatorSelected_Day_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8bc29e05e6f4bd8f8e9278c94b4f25e5154ed8c11f7c733aac16960e047599d0 +size 4309 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicatorSelected_Night_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicatorSelected_Night_0_en.png new file mode 100644 index 0000000000..6ff7e570d3 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicatorSelected_Night_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6243cdd7d3199a355c1ff5f5332bfd29c38f3b0ccd45dc0af6efdbc81c564e5 +size 4194 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicator_Day_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicator_Day_0_en.png new file mode 100644 index 0000000000..89451164a3 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicator_Day_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0665afc8ecb2119b0472adc7b5aaf5ff1726dc3538bab5ccdc37e4710569d1e +size 3894 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicator_Night_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicator_Night_0_en.png new file mode 100644 index 0000000000..1da717df5c --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline.components_SelectionIndicator_Night_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a61a03abf31e3143f1e02e4dd978e35b63bf2df0a634333edd08f0ee1fc8f1e +size 3881 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline_TimelineViewSelectionMode_Day_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline_TimelineViewSelectionMode_Day_0_en.png new file mode 100644 index 0000000000..cac3d8f820 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline_TimelineViewSelectionMode_Day_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd3ea7b8a04d58c1b3a825eeeeb798e3cf5ef333531d07456f654266706a8304 +size 44353 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline_TimelineViewSelectionMode_Night_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline_TimelineViewSelectionMode_Night_0_en.png new file mode 100644 index 0000000000..b54609e4c9 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.timeline_TimelineViewSelectionMode_Night_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3aa79e39645f154961fac99f4a58f3f0393225ba898e155f5a87acdbaa1df146 +size 45998 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_0_en.png new file mode 100644 index 0000000000..7b034776af --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86162a6692bab6684d7ca14c69085d6c3da52cc5b2efca76da307c3df626342a +size 8095 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_1_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_1_en.png new file mode 100644 index 0000000000..9f1e06b15c --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_1_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca18b30acb9cca3d6c7baa204a847efdee0ad7dac55659cae6f5085b62bd878e +size 7619 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_2_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_2_en.png new file mode 100644 index 0000000000..2c244facd5 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Day_2_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fbb3853157d790596a1ee73dee89967efcd0a2dadaa004d745e70f79ebb9910b +size 7922 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_0_en.png new file mode 100644 index 0000000000..d96bcd8dcd --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4c0ae289da14f583717c16394e48a36f89e49d509a5f2547e9815178562799c +size 7567 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_1_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_1_en.png new file mode 100644 index 0000000000..fd64fcd38b --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_1_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:97f9c238900766dde4e7a2db1810cda11d453bb13b41213e5cf2b60548ebf47c +size 7205 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_2_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_2_en.png new file mode 100644 index 0000000000..2deddffe3a --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl.topbars_SelectionModeTopBar_Night_2_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2721dc2ee00dce017522144f9ab7643817fc4abcd49e8d41f62fda04d2cec1f9 +size 7448 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl_MessagesViewSelectionMode_Day_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl_MessagesViewSelectionMode_Day_0_en.png new file mode 100644 index 0000000000..8bce40ff14 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl_MessagesViewSelectionMode_Day_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d8d6dab0b68be7a3feec477fd6026a0a6e4e8aeebd8c67adcec52270669420e +size 53355 diff --git a/tests/uitests/src/test/snapshots/images/features.messages.impl_MessagesViewSelectionMode_Night_0_en.png b/tests/uitests/src/test/snapshots/images/features.messages.impl_MessagesViewSelectionMode_Night_0_en.png new file mode 100644 index 0000000000..d4f3bff641 --- /dev/null +++ b/tests/uitests/src/test/snapshots/images/features.messages.impl_MessagesViewSelectionMode_Night_0_en.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39b9f7d1de15cb084e46996755d9f1b2be25278eb90070d0983d67146dc55edb +size 54377 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_0_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_0_en.png index bf4223a9cf..ed28276533 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_0_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_0_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6b164aa5e1a4e8115aede74944e450dfd3abe33d13f6b91bc27745d87679a7f9 -size 13080 +oid sha256:bf1e3ce457d2e28ee929ade5bfc1abfc0a62ef2dc8443824300d15f78e843b75 +size 11233 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_1_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_1_en.png index 309ace3cff..eacac1fc43 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_1_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_1_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:99beabe21f4f1dad2673e96631dd6756b78cb1c1495c7a7ba8d44257b593e007 -size 10999 +oid sha256:90452c32320a3eaad1c520885c487dc6242e1333f2084940c85e8f4060940b1e +size 9166 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_2_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_2_en.png index c186f08d29..a74397edcd 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_2_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_2_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4bbd7ca482fe8e846b2748d25e429a5fffd2c0ecc88014942efb90ea312cb298 -size 34413 +oid sha256:c3959f54f33bb8302839691e8c1a6f24b5b192c318bc4767636a27bb2578061d +size 32623 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_3_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_3_en.png index cb7871cabf..9e671f14cf 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_3_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_3_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:18eef832d5c341dbc7d9c6c5495464dd9bfbd5c9355c3fe74384e6b1fdb0fe40 -size 32481 +oid sha256:95cd751b1fcdd38cd38b5dd0335f0d157b9a0dfd45ca6a7eebf4ae55488f0c84 +size 30661 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_4_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_4_en.png index 16399a868c..3ab43d84e3 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_4_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_4_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9ebb9b7f9c8e657d8e5a7fae6a133449fbbbb7529260dc4feb6c5da176eb1103 -size 36481 +oid sha256:91c711395cfbca04b7b41c23d01012870a97a4b4b0291d6dc81c0949e60d98e8 +size 34783 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_0_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_0_en.png index 4af9e7c6f5..149038c4f5 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_0_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_0_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9ba018ba755b9925df764eec9a42a0f18853bce9944f153e853dda5427267e54 -size 12481 +oid sha256:71b4ecc3a18de7be9eb8ef453852f6f9a5c44ae8edb0a14cdf09a4a240c3faab +size 10703 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_1_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_1_en.png index ac3d4a319d..9287ee04f3 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_1_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_1_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6293fe8bfd160716a014932d7b9348fcad9cfad08a0c747bd49cf5922a5b685d -size 10732 +oid sha256:6e4a4c20eb92cf93d5e7a76973b46863ed79b32e36c9d970b311b9681a382b23 +size 8957 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_2_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_2_en.png index 6ecca16bce..0fd706f24c 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_2_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_2_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0653e38a43b99d9b07e41cdccc1bdad0e1d22a1449fea87f3909c061dffeea1e -size 34221 +oid sha256:94998fe24668f8dde57a1cdfb6e8e8cc25f1d74d8b3eb69fccf4db9067667a86 +size 32446 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_3_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_3_en.png index dd4fa7ec73..8fa06609d9 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_3_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_3_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:396c1b84d656baefa9161221bbc82343d55552dd7ea6aa44d87b4fc1a294a769 -size 32436 +oid sha256:b77e1b57b374991fdfd48c2ed42f1eefbbc3afeeda6c802831d9ab5949518581 +size 30666 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_4_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_4_en.png index 5178aaf31c..1b7bc1040d 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_4_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_4_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b5e5d889237d4e539e595c0dffd0f565b47b11257a8ef592567de0d302116f92 -size 36737 +oid sha256:a8d56ee6a21f4e9dfe20c64b6cc55eb94bb8b281aba375be31904660b4fa9e88 +size 35101 From 7ef93b51e481ee4cd55d46ae3a3c541562b747c9 Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 5 Oct 2026 20:47:57 +0200 Subject: [PATCH 15/22] Use the Element Creations license header on the new selection files --- .../android/features/messages/impl/timeline/SelectionState.kt | 2 +- .../messages/impl/timeline/components/SelectionIndicator.kt | 2 +- .../features/messages/impl/topbars/SelectionModeTopBar.kt | 2 +- .../features/messages/impl/timeline/SelectionActionTest.kt | 2 +- .../features/messages/impl/timeline/SelectionStateTest.kt | 2 +- .../features/messages/impl/timeline/TimelineStateTest.kt | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt index 7a9f073bc0..b252dfd10e 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt @@ -1,5 +1,5 @@ /* - * Copyright 2026 New Vector Ltd. + * 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. diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt index 86261057c8..f405b79e69 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/SelectionIndicator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2026 New Vector Ltd. + * 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. diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt index 1d12699277..50b14e5958 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt @@ -1,5 +1,5 @@ /* - * Copyright 2026 New Vector Ltd. + * 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. diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionActionTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionActionTest.kt index 4939ec3a50..1d7155f742 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionActionTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionActionTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2026 New Vector Ltd. + * 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. diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt index ea45813a10..bb8f66630d 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2026 New Vector Ltd. + * 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. diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateTest.kt index 3ee818e438..8e3cb997c2 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/TimelineStateTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2026 New Vector Ltd. + * 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. From d4310cb6e9aa286a6889594111073daadfa1ffe7 Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 5 Oct 2026 20:48:05 +0200 Subject: [PATCH 16/22] Use toImmutableSet instead of toPersistentSet --- .../io/element/android/features/messages/impl/MessagesView.kt | 4 ++-- .../android/features/messages/impl/timeline/SelectionState.kt | 4 ++-- .../features/messages/impl/timeline/TimelinePresenter.kt | 4 ++-- .../features/messages/impl/timeline/SelectionStateTest.kt | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt index 92c91dfee5..50b90be650 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesView.kt @@ -142,7 +142,7 @@ import io.element.android.libraries.textcomposer.model.TextEditorState import io.element.android.libraries.ui.strings.CommonStrings import io.element.android.wysiwyg.link.Link import kotlinx.collections.immutable.persistentListOf -import kotlinx.collections.immutable.toPersistentSet +import kotlinx.collections.immutable.toImmutableSet import timber.log.Timber import kotlin.time.Duration.Companion.milliseconds @@ -774,7 +774,7 @@ internal fun MessagesViewSelectionModePreview() = ElementPreview { .filter { SelectionAction.Forward.canApplyTo(it) } .take(2) .mapNotNull { it.eventId } - .toPersistentSet() + .toImmutableSet() MessagesView( state = aMessagesState( timelineState = aTimelineState( diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt index b252dfd10e..3c44839468 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/SelectionState.kt @@ -16,7 +16,7 @@ import io.element.android.features.messages.impl.timeline.model.event.canBeForwa import io.element.android.libraries.matrix.api.core.EventId import io.element.android.libraries.ui.strings.CommonStrings import kotlinx.collections.immutable.ImmutableSet -import kotlinx.collections.immutable.toPersistentSet +import kotlinx.collections.immutable.toImmutableSet /** Maximum number of messages that can be selected at once. */ const val MAX_SELECTION_COUNT = 10 @@ -57,7 +57,7 @@ fun SelectionAction.canApplyTo(event: TimelineItem.Event): Boolean = when (this) */ fun SelectionState.deselect(eventIds: Set): SelectionState = when (this) { SelectionState.Disabled -> this - is SelectionState.Active -> copy(selectedEventIds = (selectedEventIds - eventIds).toPersistentSet()) + is SelectionState.Active -> copy(selectedEventIds = (selectedEventIds - eventIds).toImmutableSet()) } /** diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt index 0b70088336..a7006985a5 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt @@ -75,7 +75,7 @@ import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentSetOf import kotlinx.collections.immutable.toImmutableList -import kotlinx.collections.immutable.toPersistentSet +import kotlinx.collections.immutable.toImmutableSet import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.combine @@ -285,7 +285,7 @@ class TimelinePresenter( snackbarDispatcher.post(SnackbarMessage(CommonStrings.screen_room_maximum_messages_selected)) current } - else -> current.copy(selectedEventIds = (selected + event.eventId).toPersistentSet()) + else -> current.copy(selectedEventIds = (selected + event.eventId).toImmutableSet()) } } is TimelineEvent.ExitSelectionMode -> { diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt index bb8f66630d..920b3bdaae 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/timeline/SelectionStateTest.kt @@ -16,7 +16,7 @@ import io.element.android.libraries.matrix.test.AN_EVENT_ID import io.element.android.libraries.matrix.test.AN_EVENT_ID_2 import io.element.android.libraries.matrix.test.AN_EVENT_ID_3 import kotlinx.collections.immutable.persistentListOf -import kotlinx.collections.immutable.toPersistentSet +import kotlinx.collections.immutable.toImmutableSet import org.junit.Test class SelectionStateTest { @@ -84,6 +84,6 @@ class SelectionStateTest { private fun anActiveSelection(eventIds: List = emptyList()) = SelectionState.Active( action = SelectionAction.Forward, - selectedEventIds = eventIds.toPersistentSet(), + selectedEventIds = eventIds.toImmutableSet(), ) } From 9b2dcd4b260e43b10883ec373c2a1811817e8a6f Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 5 Oct 2026 20:48:14 +0200 Subject: [PATCH 17/22] Fix the Konsist preview naming for the selection previews --- .../features/messages/impl/topbars/SelectionModeTopBar.kt | 4 ++-- .../io/element/android/tests/konsist/KonsistClassNameTest.kt | 1 + .../io/element/android/tests/konsist/KonsistPreviewTest.kt | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt index 50b14e5958..5cd2b15bda 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/topbars/SelectionModeTopBar.kt @@ -63,7 +63,7 @@ fun SelectionModeTopBar( @PreviewsDayNight @Composable internal fun SelectionModeTopBarPreview( - @PreviewParameter(SelectionCountProvider::class) count: Int, + @PreviewParameter(SelectionCountPreviewParam::class) count: Int, ) = ElementPreview { SelectionModeTopBar( selectedCount = count, @@ -73,6 +73,6 @@ internal fun SelectionModeTopBarPreview( ) } -internal class SelectionCountProvider : PreviewParameterProvider { +internal class SelectionCountPreviewParam : PreviewParameterProvider { override val values = sequenceOf(0, 1, 5) } diff --git a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt index 7c6eb2b630..5fa83ac198 100644 --- a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt +++ b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistClassNameTest.kt @@ -66,6 +66,7 @@ class KonsistClassNameTest { "EditableAvatarViewUriPreviewParam", "LoginModeViewErrorPreviewParam", "OverlapRatioPreviewParam", + "SelectionCountPreviewParam", "TextFileContentPreviewParam", "HtmlMessageContentPreviewParam", ) diff --git a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistPreviewTest.kt b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistPreviewTest.kt index 339ba1023a..f01cef9791 100644 --- a/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistPreviewTest.kt +++ b/tests/konsist/src/test/kotlin/io/element/android/tests/konsist/KonsistPreviewTest.kt @@ -110,6 +110,7 @@ class KonsistPreviewTest { "MessageComposerViewVoicePreview", "MessagesReactionButtonAddPreview", "MessagesReactionButtonExtraPreview", + "MessagesViewSelectionModePreview", "MessagesViewWithIdentityChangePreview", "PendingMemberRowWithLongNamePreview", "PinUnlockViewInAppPreview", @@ -133,6 +134,7 @@ class KonsistPreviewTest { "SasEmojisPreview", "SecureBackupSetupViewChangePreview", "SelectedUserCannotRemovePreview", + "SelectionIndicatorSelectedPreview", "SpaceMembersViewNoHeroesPreview", "SyncStateViewServerUnreachablePreview", "TextComposerAddCaptionPreview", @@ -179,6 +181,7 @@ class KonsistPreviewTest { "TimelineItemVoiceViewScanningContentPreview", "TimelineItemVoiceViewUnifiedPreview", "TimelineViewMessageShieldPreview", + "TimelineViewSelectionModePreview", "TimelineViewWithReadMarkerBothIndicatorsPreview", "TimelineViewWithReadMarkerJumpToUnreadIndicatorOnlyPreview", "UserAvatarColorsPreview", From cb501f3b5f0186ac046b84f6e114a25b7bd60db9 Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 5 Oct 2026 20:48:24 +0200 Subject: [PATCH 18/22] Fix the Detekt issues on the timeline selection code --- .../messages/impl/timeline/components/TimelineItemRow.kt | 2 +- .../impl/timeline/model/TimelineItemSelectionData.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt index 32cef08ea7..bc19f239cc 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt @@ -194,7 +194,7 @@ internal fun TimelineItemRow( layout(width = width, height = height) { contentPlaceable.place(0, 0) if (indicatorPlaceable != null) { - val bubbleCenter = contentPlaceable[BubbleVerticalCenter].takeIf { it != AlignmentLine.Unspecified } ?: (height / 2) + val bubbleCenter = contentPlaceable[BubbleVerticalCenter].takeIf { it != AlignmentLine.Unspecified } ?: height / 2 val x = if (layoutDirection == LayoutDirection.Ltr) 0 else width - indicatorPlaceable.width indicatorPlaceable.place(x = x, y = bubbleCenter - indicatorPlaceable.height / 2) } diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionData.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionData.kt index 60a30d5c73..eab6a2523f 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionData.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionData.kt @@ -12,12 +12,12 @@ package io.element.android.features.messages.impl.timeline.model * * @param isSelectionModeActive whether the timeline is currently in selection mode. Drives * behaviour (e.g. the whole-row click target) and must reflect the real mode, not [progress]. - * @param progress animated 0f..1f value driving the visuals (content slide + indicator slide-in). - * Animated once in TimelineView and shared by every row. Differs from [isSelectionModeActive] - * during the enter/exit animation. * @param isSelected whether this specific row's event is part of the current selection. * @param canBeSelected whether this specific row's event can be selected for the action selection mode was entered for. * Rows which cannot be selected render no indicator, and their content does not slide. + * @param progress animated 0f..1f value driving the visuals (content slide + indicator slide-in). + * Animated once in TimelineView and shared by every row. Differs from [isSelectionModeActive] + * during the enter/exit animation. */ data class TimelineItemSelectionData( val isSelectionModeActive: Boolean = false, From 752b0c59b6e40f804d0499f723327089bd84cd84 Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 5 Oct 2026 20:48:35 +0200 Subject: [PATCH 19/22] Move the composable lambda parameter last in TimelineItemRowContent --- .../messages/impl/timeline/components/TimelineItemRow.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt index bc19f239cc..d729ee6532 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemRow.kt @@ -241,9 +241,9 @@ private fun TimelineItemRowContent( onJoinCallClick: (isAudioCall: Boolean) -> Unit, onSwipeToReply: (TimelineItem.Event) -> Unit, eventSink: (TimelineEvent.TimelineItemEvent) -> Unit, - eventContentView: @Composable (TimelineItem.Event, Modifier, (ContentAvoidingLayoutData) -> Unit) -> Unit, modifier: Modifier = Modifier, selectionContentOffset: Dp = 0.dp, + eventContentView: @Composable (TimelineItem.Event, Modifier, (ContentAvoidingLayoutData) -> Unit) -> Unit, ) { Box(modifier) { when (timelineItem) { From 5631a91e282cecd1bda1086f007c89a667449436 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 7 Oct 2026 12:25:43 +0200 Subject: [PATCH 20/22] Update the multi-select feature flag description --- .../element/android/libraries/featureflag/api/FeatureFlags.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt b/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt index 7939c2bda2..0024ce1f9a 100644 --- a/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt +++ b/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt @@ -157,7 +157,7 @@ enum class FeatureFlags( MessageMultiSelect( key = "feature.message_multi_select", title = "Multi-select messages", - description = "Adds a Select action to the message menu to pick several messages at once.", + description = "The Forward action enters a selection mode, to pick and forward up to 10 messages at once.", defaultValue = { false }, isFinished = false, isInLabs = false, From c4173ae185cd6dda06ca679b1157fce308815335 Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 8 Oct 2026 17:42:08 +0200 Subject: [PATCH 21/22] Fix the row selection documentation about sliding content --- .../messages/impl/timeline/model/TimelineItemSelectionData.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionData.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionData.kt index eab6a2523f..be2c39c6bf 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionData.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/TimelineItemSelectionData.kt @@ -14,7 +14,8 @@ package io.element.android.features.messages.impl.timeline.model * behaviour (e.g. the whole-row click target) and must reflect the real mode, not [progress]. * @param isSelected whether this specific row's event is part of the current selection. * @param canBeSelected whether this specific row's event can be selected for the action selection mode was entered for. - * Rows which cannot be selected render no indicator, and their content does not slide. + * Rows which cannot be selected render no indicator and ignore clicks, but their content still slides: sliding only depends on the row being a + * start-aligned bubble, so that the bubbles stay aligned with each other. * @param progress animated 0f..1f value driving the visuals (content slide + indicator slide-in). * Animated once in TimelineView and shared by every row. Differs from [isSelectionModeActive] * during the enter/exit animation. From a53bf586e98486f8e8105b4633be717cd5bfbe5a Mon Sep 17 00:00:00 2001 From: ElementBot Date: Thu, 8 Oct 2026 16:04:27 +0000 Subject: [PATCH 22/22] Update screenshots --- .../libraries.roomselect.impl_RoomSelectView_Day_2_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Day_3_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Day_4_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Night_2_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Night_3_en.png | 4 ++-- .../libraries.roomselect.impl_RoomSelectView_Night_4_en.png | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_2_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_2_en.png index a3efa82e01..7ac7728536 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_2_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_2_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c4614a485e74a734ae29d28588f482e38124543c16169443859bbfb1052fa348 -size 36016 +oid sha256:96da17f60cf84b6e5052d9753e3e81fc6f27e1ca78bbadb4501c9e4c864b6eeb +size 34329 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_3_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_3_en.png index 1bd6536c16..48e6dbced5 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_3_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_3_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7a8c5f7dd955e112736c4eeb6a0f9a52cda2f08264f50567d13e2bca8ed1fcf5 -size 33921 +oid sha256:da7a0e6c7ed39c6d1c8f900e32d6139da70333bac1356b017148f68ea7c1dcbf +size 32126 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_4_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_4_en.png index 566292b739..19362d4a71 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_4_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Day_4_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:23c03d8ceeb921a6fe5ec71764c71e6cb6623ae25b6e455cd4e39e673732bab7 -size 37812 +oid sha256:c234a4c6b0c3219e4cfc6330601b15f7dc1db385b4024c18bd7f3376c27f7122 +size 36112 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_2_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_2_en.png index 660cfc382e..c4d89d3fb0 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_2_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_2_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f68669e01f3ad0e984e70876cbcb2fe54fdbe78fa579000919bb025fab05ab27 -size 35943 +oid sha256:f472811552d7499bd0acd7c929224a643957816cb4122c1a95ceaf5a7b32f1f3 +size 34198 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_3_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_3_en.png index 5e079df0be..60b3f75e62 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_3_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_3_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:23a17d6f9e1e44452d4f18b31ccfd93070baba947d7d5b5d5dce1accc737c964 -size 34066 +oid sha256:d722f376b5cc87f8a11be2d42347fbf90f31b04699f9ec6373ed068454545372 +size 32336 diff --git a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_4_en.png b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_4_en.png index 4b82ca3c80..c27956224c 100644 --- a/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_4_en.png +++ b/tests/uitests/src/test/snapshots/images/libraries.roomselect.impl_RoomSelectView_Night_4_en.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c6b20e6f50dc0a3a7f9086252fb1be322602cfed48c0750791ad24d88feb9ca1 -size 38032 +oid sha256:f45a3dff7b5b669c643394ba12e0df55344ff76177030d1ae1de57275c57c4c6 +size 36401