Switch the new bulk room subscription API
This commit is contained in:
committed by
Stefan Ceriu
parent
66922b5edf
commit
c48d99218a
@@ -444,11 +444,17 @@ class ClientProxy: ClientProxyProtocol {
|
||||
}
|
||||
|
||||
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
|
||||
var (roomListItem, room) = await roomTupleForIdentifier(identifier)
|
||||
|
||||
if let roomListItem, let room {
|
||||
return await RoomProxy(roomListItem: roomListItem,
|
||||
return await RoomProxy(roomListService: roomListService,
|
||||
roomListItem: roomListItem,
|
||||
room: room)
|
||||
}
|
||||
|
||||
@@ -475,7 +481,8 @@ class ClientProxy: ClientProxyProtocol {
|
||||
return nil
|
||||
}
|
||||
|
||||
return await RoomProxy(roomListItem: roomListItem,
|
||||
return await RoomProxy(roomListService: roomListService,
|
||||
roomListItem: roomListItem,
|
||||
room: room)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import MatrixRustSDK
|
||||
import UIKit
|
||||
|
||||
class RoomProxy: RoomProxyProtocol {
|
||||
private let roomListService: RoomListServiceProtocol
|
||||
private let roomListItem: RoomListItemProtocol
|
||||
private let room: RoomProtocol
|
||||
let timeline: TimelineProxyProtocol
|
||||
@@ -171,9 +172,11 @@ class RoomProxy: RoomProxyProtocol {
|
||||
var activeMembersCount: Int {
|
||||
Int(room.activeMembersCount())
|
||||
}
|
||||
|
||||
init?(roomListItem: RoomListItemProtocol,
|
||||
|
||||
init?(roomListService: RoomListServiceProtocol,
|
||||
roomListItem: RoomListItemProtocol,
|
||||
room: RoomProtocol) async {
|
||||
self.roomListService = roomListService
|
||||
self.roomListItem = roomListItem
|
||||
self.room = room
|
||||
|
||||
@@ -199,7 +202,11 @@ class RoomProxy: RoomProxyProtocol {
|
||||
let settings = RoomSubscription(requiredState: SlidingSyncConstants.defaultRequiredState,
|
||||
timelineLimit: SlidingSyncConstants.defaultTimelineLimit,
|
||||
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()
|
||||
|
||||
|
||||
@@ -134,13 +134,17 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
|
||||
MXLog.info("\(name): Requesting subscriptions for visible range: \(range)")
|
||||
|
||||
for index in range {
|
||||
guard index < rooms.count else { return }
|
||||
// Note, we must use the item received by the diff. Asking the roomListService to get
|
||||
// a new item instance will result in /sync being called when already subscribed.
|
||||
rooms[index].roomListItem.subscribe(settings: .init(requiredState: SlidingSyncConstants.defaultRequiredState,
|
||||
timelineLimit: SlidingSyncConstants.defaultTimelineLimit,
|
||||
includeHeroes: false))
|
||||
let roomIDs = range
|
||||
.filter { $0 < rooms.count }
|
||||
.map { rooms[$0].id }
|
||||
|
||||
do {
|
||||
try roomListService.subscribeToRooms(roomIds: roomIDs,
|
||||
settings: .init(requiredState: SlidingSyncConstants.defaultRequiredState,
|
||||
timelineLimit: SlidingSyncConstants.defaultTimelineLimit,
|
||||
includeHeroes: false))
|
||||
} catch {
|
||||
MXLog.error("Failed subscribing to rooms with error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user