Switch the new bulk room subscription API

This commit is contained in:
Stefan Ceriu
2024-08-09 13:10:01 +03:00
committed by Stefan Ceriu
parent 65bfd84426
commit 4617d0c255
3 changed files with 30 additions and 12 deletions
@@ -444,11 +444,17 @@ class ClientProxy: ClientProxyProtocol {
} }
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? { func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? {
guard let roomListService else {
MXLog.error("Failed retrieving room, room list service not set up")
return nil
}
// Try fetching the room from the cold cache (if available) first // Try fetching the room from the cold cache (if available) first
var (roomListItem, room) = await roomTupleForIdentifier(identifier) var (roomListItem, room) = await roomTupleForIdentifier(identifier)
if let roomListItem, let room { if let roomListItem, let room {
return await RoomProxy(roomListItem: roomListItem, return await RoomProxy(roomListService: roomListService,
roomListItem: roomListItem,
room: room) room: room)
} }
@@ -475,7 +481,8 @@ class ClientProxy: ClientProxyProtocol {
return nil return nil
} }
return await RoomProxy(roomListItem: roomListItem, return await RoomProxy(roomListService: roomListService,
roomListItem: roomListItem,
room: room) room: room)
} }
+10 -3
View File
@@ -20,6 +20,7 @@ import MatrixRustSDK
import UIKit import UIKit
class RoomProxy: RoomProxyProtocol { class RoomProxy: RoomProxyProtocol {
private let roomListService: RoomListServiceProtocol
private let roomListItem: RoomListItemProtocol private let roomListItem: RoomListItemProtocol
private let room: RoomProtocol private let room: RoomProtocol
let timeline: TimelineProxyProtocol let timeline: TimelineProxyProtocol
@@ -171,9 +172,11 @@ class RoomProxy: RoomProxyProtocol {
var activeMembersCount: Int { var activeMembersCount: Int {
Int(room.activeMembersCount()) Int(room.activeMembersCount())
} }
init?(roomListItem: RoomListItemProtocol, init?(roomListService: RoomListServiceProtocol,
roomListItem: RoomListItemProtocol,
room: RoomProtocol) async { room: RoomProtocol) async {
self.roomListService = roomListService
self.roomListItem = roomListItem self.roomListItem = roomListItem
self.room = room self.room = room
@@ -199,7 +202,11 @@ class RoomProxy: RoomProxyProtocol {
let settings = RoomSubscription(requiredState: SlidingSyncConstants.defaultRequiredState, let settings = RoomSubscription(requiredState: SlidingSyncConstants.defaultRequiredState,
timelineLimit: SlidingSyncConstants.defaultTimelineLimit, timelineLimit: SlidingSyncConstants.defaultTimelineLimit,
includeHeroes: false) // We don't need heroes here as they're already included in the `all_rooms` list includeHeroes: false) // We don't need heroes here as they're already included in the `all_rooms` list
roomListItem.subscribe(settings: settings) do {
try roomListService.subscribeToRooms(roomIds: [id], settings: settings)
} catch {
MXLog.error("Failed subscribing to room with error: \(error)")
}
await timeline.subscribeForUpdates() await timeline.subscribeForUpdates()
@@ -134,13 +134,17 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
MXLog.info("\(name): Requesting subscriptions for visible range: \(range)") MXLog.info("\(name): Requesting subscriptions for visible range: \(range)")
for index in range { let roomIDs = range
guard index < rooms.count else { return } .filter { $0 < rooms.count }
// Note, we must use the item received by the diff. Asking the roomListService to get .map { rooms[$0].id }
// a new item instance will result in /sync being called when already subscribed.
rooms[index].roomListItem.subscribe(settings: .init(requiredState: SlidingSyncConstants.defaultRequiredState, do {
timelineLimit: SlidingSyncConstants.defaultTimelineLimit, try roomListService.subscribeToRooms(roomIds: roomIDs,
includeHeroes: false)) settings: .init(requiredState: SlidingSyncConstants.defaultRequiredState,
timelineLimit: SlidingSyncConstants.defaultTimelineLimit,
includeHeroes: false))
} catch {
MXLog.error("Failed subscribing to rooms with error: \(error)")
} }
} }