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
@@ -106,6 +106,7 @@ extension ClientProxyMock {
unignoreUserReturnValue = .success(())
trackRecentlyVisitedRoomReturnValue = .success(())
recentlyVisitedRoomIDsReturnValue = .success([])
recentlyVisitedRoomsFilterReturnValue = []
recentConversationCounterpartsReturnValue = []
@@ -4225,6 +4225,34 @@ nonisolated class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
return trackRecentlyVisitedRoomReturnValue
}
}
//MARK: - recentlyVisitedRoomIDs
private let recentlyVisitedRoomIDsCallsCountLock = NSLock()
private nonisolated(unsafe) var recentlyVisitedRoomIDsUnderlyingCallsCount = 0
var recentlyVisitedRoomIDsCallsCount: Int {
get { recentlyVisitedRoomIDsCallsCountLock.withLock { recentlyVisitedRoomIDsUnderlyingCallsCount } }
set { recentlyVisitedRoomIDsCallsCountLock.withLock { recentlyVisitedRoomIDsUnderlyingCallsCount = newValue } }
}
var recentlyVisitedRoomIDsCalled: Bool {
return recentlyVisitedRoomIDsCallsCount > 0
}
private let recentlyVisitedRoomIDsReturnValueLock = NSLock()
private nonisolated(unsafe) var recentlyVisitedRoomIDsUnderlyingReturnValue: Result<[String], ClientProxyError>!
var recentlyVisitedRoomIDsReturnValue: Result<[String], ClientProxyError>! {
get { recentlyVisitedRoomIDsReturnValueLock.withLock { recentlyVisitedRoomIDsUnderlyingReturnValue } }
set { recentlyVisitedRoomIDsReturnValueLock.withLock { recentlyVisitedRoomIDsUnderlyingReturnValue = newValue } }
}
nonisolated(unsafe) var recentlyVisitedRoomIDsClosure: (() async -> Result<[String], ClientProxyError>)?
@concurrent func recentlyVisitedRoomIDs() async -> Result<[String], ClientProxyError> {
recentlyVisitedRoomIDsCallsCountLock.withLock { recentlyVisitedRoomIDsUnderlyingCallsCount += 1 }
if let recentlyVisitedRoomIDsClosure = recentlyVisitedRoomIDsClosure {
return await recentlyVisitedRoomIDsClosure()
} else {
return recentlyVisitedRoomIDsReturnValue
}
}
//MARK: - recentlyVisitedRooms
private let recentlyVisitedRoomsFilterCallsCountLock = NSLock()
@@ -4243,9 +4271,9 @@ nonisolated class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
get { recentlyVisitedRoomsFilterReturnValueLock.withLock { recentlyVisitedRoomsFilterUnderlyingReturnValue } }
set { recentlyVisitedRoomsFilterReturnValueLock.withLock { recentlyVisitedRoomsFilterUnderlyingReturnValue = newValue } }
}
nonisolated(unsafe) var recentlyVisitedRoomsFilterClosure: ((@Sendable (JoinedRoomProxyProtocol) -> Bool) async -> [JoinedRoomProxyProtocol])?
nonisolated(unsafe) var recentlyVisitedRoomsFilterClosure: ((@Sendable (JoinedRoomProxyProtocol) async -> Bool) async -> [JoinedRoomProxyProtocol])?
@concurrent func recentlyVisitedRooms(filter: @Sendable (JoinedRoomProxyProtocol) -> Bool) async -> [JoinedRoomProxyProtocol] {
@concurrent func recentlyVisitedRooms(filter: @Sendable (JoinedRoomProxyProtocol) async -> Bool) async -> [JoinedRoomProxyProtocol] {
recentlyVisitedRoomsFilterCallsCountLock.withLock { recentlyVisitedRoomsFilterUnderlyingCallsCount += 1 }
if let recentlyVisitedRoomsFilterClosure = recentlyVisitedRoomsFilterClosure {
return await recentlyVisitedRoomsFilterClosure(filter)
@@ -72,13 +72,14 @@ extension RoomSummaryProviderMock {
extension RoomSummary {
static func mock(id: String,
name: String,
isSpace: Bool = false,
canonicalAlias: String? = nil) -> RoomSummary {
RoomSummary(room: RoomSDKMock(.init()),
id: id,
joinRequestType: nil,
name: name,
isDirect: false,
isSpace: false,
isSpace: isSpace,
avatarURL: nil,
heroes: [],
activeMembersCount: 0,