Suggest recently visited rooms when forwarding messages (#6251)

* 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.
This commit is contained in:
Mauro
2026-10-02 12:04:07 +02:00
committed by GitHub
parent e67a4c388f
commit f91b7441e7
25 changed files with 287 additions and 68 deletions
@@ -12,6 +12,8 @@ import SwiftUI
typealias MessageForwardingScreenViewModelType = StateStoreViewModel<MessageForwardingScreenViewState, MessageForwardingScreenViewAction>
class MessageForwardingScreenViewModel: MessageForwardingScreenViewModelType, MessageForwardingScreenViewModelProtocol {
private static let maxSuggestedRoomCount = 5
private let forwardingPayload: MessageForwardingPayload
private let clientProxy: ClientProxyProtocol
private let roomSummaryProvider: RoomSummaryProviderProtocol
@@ -54,6 +56,8 @@ class MessageForwardingScreenViewModel: MessageForwardingScreenViewModelType, Me
.store(in: &cancellables)
updateRooms()
Task { await loadSuggestedRooms() }
}
override func process(viewAction: MessageForwardingScreenViewAction) {
@@ -83,20 +87,21 @@ class MessageForwardingScreenViewModel: MessageForwardingScreenViewModelType, Me
// MARK: - Private
private func updateRooms() {
var rooms = [MessageForwardingRoom]()
state.rooms = roomSummaryProvider.roomListPublisher.value
.filter { $0.id != forwardingPayload.roomID }
.map(MessageForwardingRoom.init(summary:))
}
/// Built from the room summaries: building room proxies is slow and would shift the list down when the section appears.
private func loadSuggestedRooms() async {
guard case let .success(roomIDs) = await clientProxy.recentlyVisitedRoomIDs() else { return }
for summary in roomSummaryProvider.roomListPublisher.value {
if summary.id == forwardingPayload.roomID {
continue
}
rooms.append(.init(id: summary.id,
title: summary.name,
description: summary.roomListDescription,
avatar: summary.avatar))
}
state.rooms = rooms
state.suggestedRooms = roomIDs
.filter { $0 != forwardingPayload.roomID }
.compactMap(clientProxy.roomSummaryForIdentifier)
.filter { $0.joinRequestType == nil && !$0.isSpace && !$0.isTombstoned }
.prefix(Self.maxSuggestedRoomCount)
.map(MessageForwardingRoom.init(summary:))
}
/// The actual range values don't matter as long as they contain the lower