mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Replace old visible rooms range with subscriptions in the room list. (#3014)
* Add a SubscriptionTracker actor to RoomProxy. * Request subscriptions when scrolling rooms. * Stop unsubscribing in preparation for Simplified Sliding Sync.
This commit is contained in:
@@ -21,8 +21,6 @@ import UIKit
|
||||
import MatrixRustSDK
|
||||
|
||||
class RoomProxy: RoomProxyProtocol {
|
||||
private static var subscriptionCountPerRoom: [String: Int] = [:]
|
||||
|
||||
private let roomListItem: RoomListItemProtocol
|
||||
private let room: RoomProtocol
|
||||
let timeline: TimelineProxyProtocol
|
||||
@@ -145,15 +143,10 @@ class RoomProxy: RoomProxyProtocol {
|
||||
}
|
||||
|
||||
subscribedForUpdates = true
|
||||
let settings = RoomSubscription(requiredState: [RequiredState(key: "m.room.name", value: ""),
|
||||
RequiredState(key: "m.room.topic", value: ""),
|
||||
RequiredState(key: "m.room.avatar", value: ""),
|
||||
RequiredState(key: "m.room.canonical_alias", value: ""),
|
||||
RequiredState(key: "m.room.join_rules", value: "")],
|
||||
timelineLimit: UInt32(SlidingSyncConstants.defaultTimelineLimit),
|
||||
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)
|
||||
Self.subscriptionCountPerRoom[roomListItem.id()] = (Self.subscriptionCountPerRoom[roomListItem.id()] ?? 0) + 1
|
||||
|
||||
await timeline.subscribeForUpdates()
|
||||
|
||||
@@ -162,14 +155,6 @@ class RoomProxy: RoomProxyProtocol {
|
||||
subscribeToTypingNotifications()
|
||||
}
|
||||
|
||||
func unsubscribeFromUpdates() {
|
||||
Self.subscriptionCountPerRoom[roomListItem.id()] = max(0, (Self.subscriptionCountPerRoom[roomListItem.id()] ?? 0) - 1)
|
||||
|
||||
if Self.subscriptionCountPerRoom[roomListItem.id()] ?? 0 <= 0 {
|
||||
roomListItem.unsubscribe()
|
||||
}
|
||||
}
|
||||
|
||||
func timelineFocusedOnEvent(eventID: String, numberOfEvents: UInt16) async -> Result<TimelineProxyProtocol, RoomProxyError> {
|
||||
do {
|
||||
let timeline = try await room.timelineFocusedOnEvent(eventId: eventID, numContextEvents: numberOfEvents, internalIdPrefix: UUID().uuidString)
|
||||
|
||||
@@ -66,8 +66,6 @@ protocol RoomProxyProtocol {
|
||||
|
||||
func subscribeForUpdates() async
|
||||
|
||||
func unsubscribeFromUpdates()
|
||||
|
||||
func timelineFocusedOnEvent(eventID: String, numberOfEvents: UInt16) async -> Result<TimelineProxyProtocol, RoomProxyError>
|
||||
|
||||
func redact(_ eventID: String) async -> Result<Void, RoomProxyError>
|
||||
|
||||
@@ -58,7 +58,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
|
||||
/// Build a new summary provider with the given parameters
|
||||
/// - Parameters:
|
||||
/// - shouldUpdateVisibleRange: whether this summary provider should foward visible ranges
|
||||
/// - shouldUpdateVisibleRange: whether this summary provider should forward visible ranges
|
||||
/// to the room list service through the `applyInput(input: .viewport(ranges` api. Only useful for
|
||||
/// lists that need to update the visible range on Sliding Sync
|
||||
init(roomListService: RoomListServiceProtocol,
|
||||
@@ -124,6 +124,25 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
guard shouldUpdateVisibleRange else {
|
||||
return
|
||||
}
|
||||
|
||||
// The scroll view content size based visible range calculations might create large ranges
|
||||
// This is just a safety check to not overload the backend
|
||||
var range = range
|
||||
if range.upperBound - range.lowerBound > SlidingSyncConstants.maximumVisibleRangeSize {
|
||||
let upperBound = range.lowerBound + SlidingSyncConstants.maximumVisibleRangeSize
|
||||
range = range.lowerBound..<upperBound
|
||||
}
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
func setFilter(_ filter: RoomSummaryProviderFilter) {
|
||||
|
||||
Reference in New Issue
Block a user