Use a static room summary provider to resolve room summaries through id and aliases (#3863)

* trying to debug why sometimes the value

is missing even if it appears in the room list

* static room provider implementation

* set the page size through the init

* removed reset filters on .cancel

since using the sop function is safer
This commit is contained in:
Mauro
2025-03-04 14:08:15 +01:00
committed by GitHub
parent 56d8af1d2e
commit 319441d527
16 changed files with 179 additions and 60 deletions
@@ -46,6 +46,8 @@ class ClientProxy: ClientProxyProtocol {
private(set) var roomSummaryProvider: RoomSummaryProviderProtocol?
private(set) var alternateRoomSummaryProvider: RoomSummaryProviderProtocol?
private(set) var staticRoomSummaryProvider: StaticRoomSummaryProviderProtocol?
let notificationSettings: NotificationSettingsProxyProtocol
let secureBackupController: SecureBackupControllerProtocol
@@ -523,14 +525,32 @@ class ClientProxy: ClientProxyProtocol {
func roomSummaryForIdentifier(_ identifier: String) -> RoomSummary? {
// the alternate room summary provider is not impacted by filtering
alternateRoomSummaryProvider?.roomListPublisher.value.first { $0.id == identifier }
guard let provider = staticRoomSummaryProvider else {
MXLog.verbose("Missing room summary provider")
return nil
}
guard let roomSummary = provider.roomListPublisher.value.first(where: { $0.id == identifier }) else {
MXLog.verbose("Missing room summary, count: \(provider.roomListPublisher.value.count)")
return nil
}
return roomSummary
}
func roomSummaryForAlias(_ alias: String) -> RoomSummary? {
// the alternate room summary provider is not impacted by filtering
alternateRoomSummaryProvider?.roomListPublisher.value.first { roomSummary in
roomSummary.canonicalAlias == alias || roomSummary.alternativeAliases.contains(alias)
guard let provider = staticRoomSummaryProvider else {
MXLog.verbose("Missing room summary provider")
return nil
}
guard let roomSummary = provider.roomListPublisher.value.first(where: { $0.canonicalAlias == alias || $0.alternativeAliases.contains(alias) }) else {
MXLog.verbose("Missing room summary, count: \(provider.roomListPublisher.value.count)")
return nil
}
return roomSummary
}
func loadUserDisplayName() async -> Result<Void, ClientProxyError> {
@@ -846,6 +866,14 @@ class ClientProxy: ClientProxyProtocol {
notificationSettings: notificationSettings,
appSettings: appSettings)
try await alternateRoomSummaryProvider?.setRoomList(roomListService.allRooms())
staticRoomSummaryProvider = RoomSummaryProvider(roomListService: roomListService,
eventStringBuilder: eventStringBuilder,
name: "StaticAllRooms",
roomListPageSize: .max,
notificationSettings: notificationSettings,
appSettings: appSettings)
try await staticRoomSummaryProvider?.setRoomList(roomListService.allRooms())
self.syncService = syncService
self.roomListService = roomListService
@@ -96,11 +96,16 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
var roomSummaryProvider: RoomSummaryProviderProtocol? { get }
var roomsToAwait: Set<String> { get set }
/// Used for listing rooms that shouldn't be affected by the main `roomSummaryProvider` filtering
/// But can still be filtered by queries, since this may be shared across multiple views, remember to reset
/// The filtering state when you are done with it
var alternateRoomSummaryProvider: RoomSummaryProviderProtocol? { get }
/// Used for listing rooms, can't be filtered nor its state observed
var staticRoomSummaryProvider: StaticRoomSummaryProviderProtocol? { get }
var roomsToAwait: Set<String> { get set }
var notificationSettings: NotificationSettingsProxyProtocol { get }
var secureBackupController: SecureBackupControllerProtocol { get }