Add multi selection to the Forward action (#6190)

* Start message selection from the Forward action

Behind the multi-select developer option, choosing Forward on a message
now starts a selection with that message checked, instead of the
dedicated Select menu action which is removed. Only forwardable
messages can be selected: remote, decrypted, non-redacted events that
aren't state, unsupported, poll or live location items.

The chrome follows the Figma exploration: the room header stays, an X
in the trailing toolbar position ends the selection, rows show only the
checkbox (no highlight, 10pt gap to the bubble), and the composer is
replaced by a single primary "Forward N messages" button. The limits
are now 10 messages into 5 rooms.

Tapping the button forwards the selection in timeline order, never in
the order the messages were tapped. MessageForwardingItem carries
several contents and the forwarding screen sends them one after the
other per room, reporting a single error toast on partial failures.
The selection is kept while the forwarding screen is open so cancelling
it returns to the selection; it is cleared by the flow coordinator once
the messages are sent, or by the X in the timeline.

New plural action_forward_messages lives in Untranslated for now;
action_select and screen_room_selection_count are no longer used.

* Tidy the selection code after review

Reuse ToolbarButton's cancel role for the selection's toolbar item so it
matches the other screens on every OS version, and disable the room
header while selecting so the room details can't cover the selection.

Move the forwardable/selected item helpers next to the existing
nonisolated array extension, drop the unused MessageForwardingItem
initialisers and the single-item makeForwardingItem overload, and
simplify the forwarding loop now that a room either sends or isn't
reachable.

The action bar preview builds its own view model instead of putting
the shared mock into selection mode for every later preview, and a
test locks that Forward keeps forwarding directly in the pinned
timeline.

* Select messages to forward from the pinned timeline too

Forward is offered in the pinned events timeline, so with the flag on
it starts a selection there as well, with the same cancel item in the
toolbar and the same forward button at the bottom. Forwarding from
that sheet already dismisses the whole sheet, so the selection is
discarded with it. Only the media timelines keep forwarding a single
item directly.

* Confirm with a toast when messages are forwarded to several rooms

When a single room is picked the flow opens it, which is confirmation
enough. When several rooms are picked the user stays in the origin room,
so a "Messages forwarded" toast tells them it worked, as in the designs.
The new screen_room_message_forwarded / screen_room_messages_forwarded
strings live in Untranslated for now.

* Apply review suggestions to multi-message forwarding

Strings
- The forward button and the multi-room toast now use the Localazy
  plurals action_forward_messages and screen_room_messages_forwarded;
  the toast shows the count. The Untranslated copies and the unused
  action_select are gone.

Selection
- Drop the dead startSelection view action and the redundant
  canSelectMessages guard; tests start a selection through Forward
  like the app does.
- Remove two comments on the selection state that restated the code.

Forwarding
- After a send, clear the selection in the room and any open thread
  instead of working out which one started it; only one can be
  selecting at a time.
- Explain that stickers are excluded because the SDK can only forward
  m.room.message content.

* Rename the timeline selection to message selection

"Selection" alone was too generic in a timeline that also has text and
room selections. The selection state, toolbar, action bar and
accessibility types, the timeline state's property, the view actions
and the public clear method now say "message selection". Private
helpers keep their short names.

* Rename MessageForwardingItem to MessageForwardingPayload

The type now carries several messages, so "item" no longer described
it. The factory method and the variables and action labels holding it
follow the new name.
This commit is contained in:
Mauro
2026-09-25 13:51:14 +02:00
committed by GitHub
parent fc8ee9d93d
commit ad1d7a3010
71 changed files with 826 additions and 388 deletions
@@ -224,8 +224,8 @@ class TimelineInteractionHandler {
analyticsService.trackInteraction(name: .PinnedMessageListViewTimeline)
guard let eventID = itemID.eventID else { return }
actionsSubject.send(.viewInRoomTimeline(eventID: eventID))
case .downloadMedia, .selectMessages:
break // Handled by the media preview screen and the TimelineViewModel respectively.
case .downloadMedia:
break // Handled inline in the media preview screen.
case .translate:
guard let messageTimelineItem = timelineItem as? EventBasedMessageTimelineItemProtocol else { return }
actionsSubject.send(.showTranslation(text: messageTimelineItem.body))
@@ -22,7 +22,7 @@ enum TimelineViewModelAction {
case displayEditPollForm(eventID: String, poll: Poll)
case displayMediaUploadPreviewScreen(mediaURLs: [URL])
case displaySenderDetails(userID: String)
case displayMessageForwarding(forwardingItem: MessageForwardingItem)
case displayMessageForwarding(forwardingPayload: MessageForwardingPayload)
case displayMediaPreview(TimelineMediaPreviewViewModel)
case displayLocation(StaticLocationData)
case displayLiveLocation(sender: TimelineItemSender, initialLiveLocationShare: LiveLocationShare)
@@ -69,11 +69,11 @@ enum TimelineViewAction {
/// The user has confirmed the removal of an item, optionally giving a reason.
case redactConfirmed(itemID: TimelineItemIdentifier, reason: String?)
/// Start a multi-selection with the specified item.
case startSelection(itemID: TimelineItemIdentifier)
/// Add or remove an item from the active multi-selection.
case toggleSelection(itemID: TimelineItemIdentifier)
case clearSelection
case toggleMessageSelection(itemID: TimelineItemIdentifier)
case clearMessageSelection
/// Forward the selected messages, in timeline order.
case forwardMessageSelection
case tappedOnSenderDetails(sender: TimelineItemSender)
case displayReactionSummary(itemID: TimelineItemIdentifier, key: String)
@@ -137,7 +137,7 @@ struct TimelineViewState: BindableState {
var linkPreviewsEnabled: Bool
var jumpToReadMarkerEnabled: Bool
var selection: TimelineSelectionState
var messageSelection: TimelineMessageSelectionState
let hasPredecessor: Bool
@@ -206,12 +206,10 @@ struct TimelineViewStateBindings {
}
/// The state of the multi-selection of messages, active as soon as an item is selected.
struct TimelineSelectionState: Equatable {
static let limit = 30
struct TimelineMessageSelectionState: Equatable {
static let limit = 10
/// Mirrors the `messageMultiSelectEnabled` feature flag.
var isEnabled = false
/// The event IDs of the selected items. Only remote messages can be selected.
var selectedEventIDs: Set<String> = []
var isActive: Bool {
@@ -354,12 +352,12 @@ enum ScrollDirection: Equatable {
}
extension TimelineViewState {
/// Multi-selection is only offered in the room and thread timelines.
/// Multi-selection is offered everywhere but the media timelines.
var canSelectMessages: Bool {
guard selection.isEnabled else { return false }
guard messageSelection.isEnabled else { return false }
return switch timelineKind {
case .live, .detached, .thread: true
case .pinned, .media: false
case .live, .detached, .thread, .pinned: true
case .media: false
}
}
@@ -103,7 +103,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
areThreadsEnabled: appSettings.threadsEnabled,
linkPreviewsEnabled: appSettings.linkPreviewsEnabled,
jumpToReadMarkerEnabled: appSettings.jumpToReadMarkerEnabled,
selection: .init(isEnabled: appSettings.messageMultiSelectEnabled),
messageSelection: .init(isEnabled: appSettings.messageMultiSelectEnabled),
hasPredecessor: roomProxy.predecessorRoom != nil,
pinnedEventIDs: roomProxy.infoPublisher.value.pinnedEventIDs,
emojiProvider: emojiProvider,
@@ -198,7 +198,7 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
}
case .displayTimelineItemMenu(let itemID):
timelineInteractionHandler.displayTimelineItemActionMenu(for: itemID)
case .handleTimelineItemMenuAction(let itemID, .selectMessages):
case .handleTimelineItemMenuAction(let itemID, .forward) where state.canSelectMessages:
startSelection(itemID: itemID)
case .handleTimelineItemMenuAction(let itemID, let action):
timelineInteractionHandler.handleTimelineItemMenuAction(action, itemID: itemID)
@@ -206,12 +206,12 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
state.bindings.redactConfirmationInfo = nil
// A blank reason is no reason at all, so don't send one.
timelineInteractionHandler.redact(itemID, reason: reason?.isBlank == false ? reason : nil)
case .startSelection(let itemID):
startSelection(itemID: itemID)
case .toggleSelection(let itemID):
case .toggleMessageSelection(let itemID):
toggleSelection(itemID: itemID)
case .clearSelection:
state.selection.selectedEventIDs.removeAll()
case .clearMessageSelection:
clearMessageSelection()
case .forwardMessageSelection:
forwardSelection()
case .tappedOnSenderDetails(let sender):
handleTappedOnSenderDetails(sender: sender)
case .displayEmojiPicker(let itemID):
@@ -313,11 +313,6 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
await userSession.liveLocationManager.stopLiveLocation(roomID: roomProxy.id)
}
func makeForwardingItem(for itemID: TimelineItemIdentifier) async -> MessageForwardingItem? {
guard let content = await timelineController.messageEventContent(for: itemID) else { return nil }
return .init(id: itemID, roomID: roomProxy.id, content: content)
}
// MARK: - Private
private func handleTappedOnSenderDetails(sender: TimelineItemSender) {
@@ -1059,13 +1054,6 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
state.bindings.readReceiptsSummaryInfo = .init(orderedReceipts: eventTimelineItem.properties.orderedReadReceipts, id: eventTimelineItem.id)
}
// MARK: - Message forwarding
private func forwardMessage(itemID: TimelineItemIdentifier) async {
guard let forwardingItem = await makeForwardingItem(for: itemID) else { return }
actionsSubject.send(.displayMessageForwarding(forwardingItem: forwardingItem))
}
// MARK: Pills
private func pillContextUpdater(_ pillContext: PillContext) {
@@ -1185,68 +1173,106 @@ class TimelineViewModel: TimelineViewModelType, TimelineViewModelProtocol {
}
}
// MARK: - Message forwarding
extension TimelineViewModel {
func makeForwardingPayload(for itemIDs: [TimelineItemIdentifier]) async -> MessageForwardingPayload? {
var ids = [TimelineItemIdentifier]()
var contents = [RoomMessageEventContentWithoutRelation]()
for itemID in itemIDs {
guard let content = await timelineController.messageEventContent(for: itemID) else { continue }
ids.append(itemID)
contents.append(content)
}
guard !contents.isEmpty else { return nil }
return .init(ids: ids, roomID: roomProxy.id, contents: contents)
}
private func forwardMessage(itemID: TimelineItemIdentifier) async {
guard let forwardingPayload = await makeForwardingPayload(for: [itemID]) else { return }
actionsSubject.send(.displayMessageForwarding(forwardingPayload: forwardingPayload))
}
}
// MARK: - Selection
extension TimelineViewModel {
private func setupSelectionSubscriptions() {
appSettings.messageMultiSelectEnabledPublisher
.sink { [weak self] isEnabled in
self?.state.selection.isEnabled = isEnabled
self?.state.messageSelection.isEnabled = isEnabled
if !isEnabled {
self?.state.selection.selectedEventIDs.removeAll()
self?.state.messageSelection.selectedEventIDs.removeAll()
}
}
.store(in: &cancellables)
}
private func startSelection(itemID: TimelineItemIdentifier) {
guard state.canSelectMessages, let eventID = selectableEventID(for: itemID) else { return }
guard let eventID = selectableEventID(for: itemID) else { return }
// The composer is collapsed while selecting, so don't leave the microphone open behind it.
Task { await timelineInteractionHandler.stopRecordingVoiceMessageIfNeeded() }
actionsSubject.send(.composer(action: .removeFocus))
guard !state.selection.isAtLimit || state.selection.selectedEventIDs.contains(eventID) else {
guard !state.messageSelection.isAtLimit || state.messageSelection.selectedEventIDs.contains(eventID) else {
showSelectionLimitToast()
return
}
state.selection.selectedEventIDs.insert(eventID)
state.messageSelection.selectedEventIDs.insert(eventID)
}
private func toggleSelection(itemID: TimelineItemIdentifier) {
guard state.selection.isActive, let eventID = selectableEventID(for: itemID) else { return }
guard state.messageSelection.isActive, let eventID = selectableEventID(for: itemID) else { return }
if state.selection.selectedEventIDs.contains(eventID) {
state.selection.selectedEventIDs.remove(eventID)
} else if state.selection.isAtLimit {
if state.messageSelection.selectedEventIDs.contains(eventID) {
state.messageSelection.selectedEventIDs.remove(eventID)
} else if state.messageSelection.isAtLimit {
showSelectionLimitToast()
} else {
state.selection.selectedEventIDs.insert(eventID)
state.messageSelection.selectedEventIDs.insert(eventID)
}
}
/// Drops selected items that are no longer selectable (e.g. redacted), or the whole selection
/// when the timeline is swapped, so the selection always refers to items that are on screen.
private func reconcileSelection(with timelineItems: [RoomTimelineItemProtocol], isSwitchingTimelines: Bool) {
guard state.selection.isActive else { return }
guard state.messageSelection.isActive else { return }
if isSwitchingTimelines {
state.selection.selectedEventIDs.removeAll()
state.messageSelection.selectedEventIDs.removeAll()
return
}
let selectableEventIDs = timelineItems.compactMap { item -> String? in
guard let item = item as? EventBasedTimelineItemProtocol, item.isBulkSelectable else { return nil }
return item.id.eventID
}
state.selection.selectedEventIDs.formIntersection(selectableEventIDs)
let forwardableEventIDs = timelineItems.forwardableItems.compactMap(\.id.eventID)
state.messageSelection.selectedEventIDs.formIntersection(forwardableEventIDs)
}
/// The event ID of the item, when it is part of this timeline and can be bulk selected.
/// Ends the selection, either from the close button or once the selected messages have been forwarded.
func clearMessageSelection() {
state.messageSelection.selectedEventIDs.removeAll()
}
/// Forwards the selection in timeline order, which is unrelated to the order the messages were selected in.
/// The selection is kept until the forwarding completes, so cancelling the picker returns to it.
private func forwardSelection() {
let itemIDs = timelineController.timelineItems.selectedItems(state.messageSelection.selectedEventIDs).map(\.id)
Task {
guard let forwardingPayload = await makeForwardingPayload(for: itemIDs) else {
displayErrorToast(L10n.errorUnknown)
return
}
actionsSubject.send(.displayMessageForwarding(forwardingPayload: forwardingPayload))
}
}
/// The event ID of the item, when it is part of this timeline and can be forwarded.
private func selectableEventID(for itemID: TimelineItemIdentifier) -> String? {
guard let item = timelineController.timelineItems.firstUsingStableID(itemID) as? EventBasedTimelineItemProtocol,
item.isBulkSelectable else {
item.isForwardable else {
return nil
}
return item.id.eventID
@@ -19,6 +19,8 @@ protocol TimelineViewModelProtocol {
func focusOnEvent(eventID: String) async
/// Stops the current live location sharing
func stopLiveLocationSharing() async
/// Handles getting the content to forward an item given its item ID.
func makeForwardingItem(for itemID: TimelineItemIdentifier) async -> MessageForwardingItem?
/// Handles getting the contents to forward the given items, keeping the order of the given IDs.
func makeForwardingPayload(for itemIDs: [TimelineItemIdentifier]) async -> MessageForwardingPayload?
/// Ends the message selection, e.g. once the selected messages have been forwarded.
func clearMessageSelection()
}
@@ -339,7 +339,6 @@ struct TimelineItemMenu_Previews: PreviewProvider, TestablePreview {
pinnedEventIDs: [],
isViewSourceEnabled: true,
areThreadsEnabled: true,
isMultiSelectEnabled: false,
timelineKind: .live,
emojiProvider: EmojiProvider(appSettings: .volatile()))
guard let actions = provider.makeActions() else { return nil }
@@ -68,7 +68,6 @@ enum TimelineItemMenuAction: Identifiable, Hashable {
case reply(isThread: Bool)
case replyInThread
case forward(itemID: TimelineItemIdentifier)
case selectMessages
case viewSource
case report
case react
@@ -170,8 +169,6 @@ enum TimelineItemMenuAction: Identifiable, Hashable {
Label(L10n.actionReplyInThread, icon: \.threads)
case .forward:
Label(L10n.actionForward, icon: \.forward)
case .selectMessages:
Label(L10n.actionSelect, icon: \.check)
case .redact(let isMedia):
Label(isMedia ? L10n.actionDeleteFile : L10n.actionRemoveMessage, icon: \.delete)
case .viewSource:
@@ -17,7 +17,6 @@ struct TimelineItemMenuActionProvider {
let pinnedEventIDs: Set<String>
let isViewSourceEnabled: Bool
let areThreadsEnabled: Bool
let isMultiSelectEnabled: Bool
let timelineKind: TimelineKind
let emojiProvider: EmojiProviderProtocol
@@ -66,10 +65,6 @@ struct TimelineItemMenuActionProvider {
actions.append(.forward(itemID: item.id))
}
if isMultiSelectEnabled, item.isBulkSelectable {
actions.append(.selectMessages)
}
if item.isEditable, canCurrentUserSendMessage {
if item.supportsMediaCaption {
if item.hasMediaCaption {
@@ -9,7 +9,7 @@
import SwiftUI
/// How a timeline item takes part in an active multi-selection, for accessibility purposes.
enum TimelineItemAccessibilitySelection {
enum TimelineItemAccessibilityMessageSelection {
/// No selection is active, the item offers its regular message actions.
case none
/// A selection is active, the item acts as a toggle when it can be selected.
@@ -18,7 +18,7 @@ enum TimelineItemAccessibilitySelection {
private struct TimelineItemAccessibilityModifier: ViewModifier {
let timelineItem: RoomTimelineItemProtocol
let selection: TimelineItemAccessibilitySelection
let selection: TimelineItemAccessibilityMessageSelection
let action: () -> Void
private var isSelecting: Bool {
@@ -77,7 +77,7 @@ private struct TimelineItemAccessibilityModifier: ViewModifier {
}
}
case .selecting(let isSelected):
if let item = timelineItem as? EventBasedTimelineItemProtocol, item.isBulkSelectable {
if let item = timelineItem as? EventBasedTimelineItemProtocol, item.isForwardable {
view
.accessibilityAddTraits(isSelected ? [.isButton, .isSelected] : .isButton)
.accessibilityAction(.default, action)
@@ -91,7 +91,7 @@ private struct TimelineItemAccessibilityModifier: ViewModifier {
extension View {
func timelineItemAccessibility(_ timelineItem: RoomTimelineItemProtocol,
selection: TimelineItemAccessibilitySelection = .none,
selection: TimelineItemAccessibilityMessageSelection = .none,
action: @escaping () -> Void) -> some View {
modifier(TimelineItemAccessibilityModifier(timelineItem: timelineItem, selection: selection, action: action))
}
@@ -42,12 +42,12 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
return context.viewState.pinnedEventIDs.contains(eventID)
}
private var isSelectionActive: Bool {
context.viewState.selection.isActive
private var isMessageSelectionActive: Bool {
context.viewState.messageSelection.isActive
}
private var isSelected: Bool {
context.viewState.selection.contains(timelineItem.id.eventID)
context.viewState.messageSelection.contains(timelineItem.id.eventID)
}
/// The base padding applied to bubbles on either side.
@@ -61,18 +61,17 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
}
var body: some View {
HStack(spacing: 0) {
if isSelectionActive {
HStack(spacing: 10) {
if isMessageSelectionActive {
selectionIndicator
}
bubble
}
.padding(EdgeInsets(top: 1, leading: 8, bottom: 1, trailing: 8))
.background(isSelected ? Color.compound.bgAccentSelected : .clear)
.highlightedTimelineItem(isFocussed)
.overlay { selectionOverlay }
.animation(.elementDefault.disabledDuringTests(), value: isSelectionActive)
.animation(.elementDefault.disabledDuringTests(), value: isMessageSelectionActive)
.onPreferenceChange(ContentScanningFailurePreferenceKey.self) { contentScanningFailure = $0 }
}
@@ -80,7 +79,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
// The ZStack keeps the transition on the indicator's appearance rather than its checked state.
ZStack {
ListRowAccessory.multiSelection(isSelected)
.opacity(timelineItem.isBulkSelectable ? 1 : 0) // Keeps the bubbles aligned.
.opacity(timelineItem.isForwardable ? 1 : 0) // Keeps the bubbles aligned.
}
.padding(.leading, 8)
.transition(.move(edge: .leading).combined(with: .opacity))
@@ -90,7 +89,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
/// Captures every touch while selecting so the content's own gestures can't fire.
@ViewBuilder
private var selectionOverlay: some View {
if isSelectionActive {
if isMessageSelectionActive {
Color.clear
.contentShape(Rectangle())
.onTapGesture { toggleSelection() }
@@ -172,8 +171,8 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
// Figma overlaps reactions by 3
VStack(alignment: alignment, spacing: -3) {
messageBubbleWithActions
.timelineItemAccessibility(timelineItem, selection: isSelectionActive ? .selecting(isSelected: isSelected) : .none) {
if isSelectionActive {
.timelineItemAccessibility(timelineItem, selection: isMessageSelectionActive ? .selecting(isSelected: isSelected) : .none) {
if isMessageSelectionActive {
toggleSelection()
} else {
context.send(viewAction: .displayTimelineItemMenu(itemID: timelineItem.id))
@@ -189,7 +188,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
isLayoutRTL: timelineItem.isOutgoing)
// Workaround to stop the message long press stealing the touch from the reaction buttons
.onTapGesture { }
.accessibilityHidden(isSelectionActive)
.accessibilityHidden(isMessageSelectionActive)
}
if context.viewState.areThreadsEnabled,
@@ -199,7 +198,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
context.send(viewAction: .displayThread(itemID: timelineItem.id))
}
.padding(5)
.accessibilityHidden(isSelectionActive)
.accessibilityHidden(isMessageSelectionActive)
}
}
}
@@ -213,7 +212,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
// specific taps within the timeline views themselves.
}
// The UIKit recogniser would still receive touches through the selection overlay.
.longPressWithFeedback(isEnabled: !isSelectionActive) {
.longPressWithFeedback(isEnabled: !isMessageSelectionActive) {
context.send(viewAction: .displayTimelineItemMenu(itemID: timelineItem.id))
}
.swipeRightAction {
@@ -221,13 +220,13 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
.foregroundColor(.compound.iconPrimary)
.accessibilityHidden(true)
} shouldStartAction: {
!isSelectionActive && timelineItem.canBeRepliedTo
!isMessageSelectionActive && timelineItem.canBeRepliedTo
} action: {
context.send(viewAction: .handleTimelineItemMenuAction(itemID: timelineItem.id,
action: .reply(isThread: timelineItem.properties.isThreaded)))
}
.contextMenu {
if !isSelectionActive {
if !isMessageSelectionActive {
macContextMenu
}
}
@@ -245,7 +244,6 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
pinnedEventIDs: context.viewState.pinnedEventIDs,
isViewSourceEnabled: context.viewState.isViewSourceEnabled,
areThreadsEnabled: context.viewState.areThreadsEnabled,
isMultiSelectEnabled: context.viewState.canSelectMessages,
timelineKind: context.viewState.timelineKind,
emojiProvider: context.viewState.emojiProvider)
TimelineItemMacContextMenu(item: timelineItem, actionProvider: provider) { action in
@@ -298,8 +296,8 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
}
private func toggleSelection() {
guard timelineItem.isBulkSelectable else { return }
context.send(viewAction: .toggleSelection(itemID: timelineItem.id))
guard timelineItem.isForwardable else { return }
context.send(viewAction: .toggleMessageSelection(itemID: timelineItem.id))
}
private var messageBubbleTopPadding: CGFloat {
@@ -478,7 +476,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider, TestablePreview
emojiProvider: EmojiProvider(appSettings: appSettings),
linkMetadataProvider: LinkMetadataProvider(),
timelineControllerFactory: TimelineControllerFactoryMock(.init()))
viewModel.state.selection.selectedEventIDs = ["selected"]
viewModel.state.messageSelection.selectedEventIDs = ["selected"]
return viewModel
}()
@@ -0,0 +1,40 @@
//
// Copyright 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.
//
import Compound
import SwiftUI
/// Replaces the composer while messages are being selected, offering the action to take on them.
struct TimelineMessageSelectionActionBar: View {
@ObservedObject var context: TimelineViewModelType.Context
var body: some View {
Button {
context.send(viewAction: .forwardMessageSelection)
} label: {
Label(L10n.actionForwardMessages(context.viewState.messageSelection.count), icon: \.forward)
}
.buttonStyle(.compound(.primary))
.padding(16)
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
}
}
// MARK: - Previews
struct TimelineMessageSelectionActionBar_Previews: PreviewProvider, TestablePreview {
static let viewModel: TimelineViewModel = {
let viewModel = TimelineViewModel.mock() // A fresh instance so the shared mock isn't left selecting.
viewModel.state.messageSelection.selectedEventIDs = ["$1", "$2", "$3"]
return viewModel
}()
static var previews: some View {
TimelineMessageSelectionActionBar(context: viewModel.context)
.previewLayout(.sizeThatFits)
}
}
@@ -0,0 +1,19 @@
//
// Copyright 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.
//
import SwiftUI
/// The trailing navigation bar item that cancels the selection of messages in a timeline.
struct TimelineMessageSelectionToolbar: ToolbarContent {
let onCancel: () -> Void
var body: some ToolbarContent {
ToolbarItem(placement: .primaryAction) {
ToolbarButton(role: .cancel, action: onCancel)
}
}
}
@@ -1,27 +0,0 @@
//
// Copyright 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.
//
import Compound
import SwiftUI
/// The navigation bar content shown while messages are being selected in a timeline.
struct TimelineSelectionToolbar: ToolbarContent {
let count: Int
let onCancel: () -> Void
var body: some ToolbarContent {
ToolbarItem(placement: .cancellationAction) {
Button(L10n.actionCancel, role: .cancel, action: onCancel)
}
ToolbarItem(placement: .principal) {
Text(L10n.screenRoomSelectionCount(count))
.font(.compound.bodyLGSemibold)
.foregroundStyle(.compound.textPrimary)
}
}
}
@@ -41,7 +41,6 @@ struct TimelineView: View {
pinnedEventIDs: timelineContext.viewState.pinnedEventIDs,
isViewSourceEnabled: timelineContext.viewState.isViewSourceEnabled,
areThreadsEnabled: timelineContext.viewState.areThreadsEnabled,
isMultiSelectEnabled: timelineContext.viewState.canSelectMessages,
timelineKind: timelineContext.viewState.timelineKind,
emojiProvider: timelineContext.viewState.emojiProvider)
.makeActions()