mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
f91b7441e7
* Suggest recently visited rooms when forwarding messages The Forward to screen now shows up to 5 recently visited rooms in a Suggestions section, above a Chats section that lists every room. The suggestions are never searched: while searching, only the Chats section is shown and filtered. The source room, invites, spaces and upgraded rooms are never suggested, and the section is hidden when there is nothing to suggest. The suggestions are resolved from the room summaries rather than room proxies, so they show up without holding back the list, and they are re-resolved as the room list loads after a cold start. ClientProxy now exposes the recently visited room IDs for this. The recently visited rooms filter is now async, so callers choose its isolation instead of asserting it at runtime. * Apply review suggestions to the forwarding suggestions Rooms: - Each room is listed once. Suggested rooms are left out of Chats unless searching, where Chats lists every result. This also removes the duplicated row whose selection changed without the tapped row's animation. - The Chats header is hidden when the section has no rooms. Suggestions: - Resolve them once when the screen opens instead of on every room list update.
87 lines
2.5 KiB
Swift
87 lines
2.5 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
// Copyright 2022-2025 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.
|
|
//
|
|
|
|
import Foundation
|
|
import MatrixRustSDK
|
|
|
|
enum MessageForwardingScreenViewModelAction {
|
|
case dismiss
|
|
case sent(roomIDs: [String])
|
|
}
|
|
|
|
struct MessageForwardingScreenViewState: BindableState {
|
|
/// The recently visited rooms, never filtered by the search query.
|
|
var suggestedRooms: [MessageForwardingRoom] = []
|
|
var rooms: [MessageForwardingRoom] = []
|
|
var selectedRoomIDs: Set<String> = []
|
|
let maxRoomSelectionCount = 5
|
|
var bindings = MessageForwardingScreenViewStateBindings()
|
|
|
|
var showsSuggestions: Bool {
|
|
bindings.searchQuery.isEmpty && !suggestedRooms.isEmpty
|
|
}
|
|
|
|
/// Every room appears once: the suggested ones are left out unless searching.
|
|
var chats: [MessageForwardingRoom] {
|
|
guard showsSuggestions else { return rooms }
|
|
|
|
let suggestedRoomIDs = Set(suggestedRooms.map(\.id))
|
|
return rooms.filter { !suggestedRoomIDs.contains($0.id) }
|
|
}
|
|
|
|
var isAtRoomSelectionLimit: Bool {
|
|
selectedRoomIDs.count >= maxRoomSelectionCount
|
|
}
|
|
}
|
|
|
|
struct MessageForwardingScreenViewStateBindings {
|
|
var searchQuery = ""
|
|
}
|
|
|
|
enum MessageForwardingScreenViewAction {
|
|
case cancel
|
|
case send
|
|
case selectRoom(roomID: String)
|
|
case reachedTop
|
|
case reachedBottom
|
|
}
|
|
|
|
struct MessageForwardingRoom: Identifiable, Equatable {
|
|
let id: String
|
|
let title: String
|
|
let description: String
|
|
let avatar: RoomAvatar
|
|
}
|
|
|
|
extension MessageForwardingRoom {
|
|
init(summary: RoomSummary) {
|
|
self.init(id: summary.id,
|
|
title: summary.name,
|
|
description: summary.roomListDescription,
|
|
avatar: summary.avatar)
|
|
}
|
|
}
|
|
|
|
struct MessageForwardingPayload: Hashable {
|
|
/// The source items' timeline IDs. Only necessary for a rough Hashable conformance.
|
|
let ids: [TimelineItemIdentifier]
|
|
/// The source items' room ID.
|
|
let roomID: String
|
|
/// The contents to be forwarded, in timeline order.
|
|
let contents: [RoomMessageEventContentWithoutRelation]
|
|
|
|
static func == (lhs: MessageForwardingPayload, rhs: MessageForwardingPayload) -> Bool {
|
|
lhs.ids == rhs.ids && lhs.roomID == rhs.roomID
|
|
}
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
hasher.combine(ids)
|
|
hasher.combine(roomID)
|
|
}
|
|
}
|