mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +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:
parent
bf9e1d614f
commit
a1329d9d54
@ -680,8 +680,6 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
navigationStackCoordinator.setRootCoordinator(nil, animated: false)
|
||||
}
|
||||
|
||||
roomProxy?.unsubscribeFromUpdates()
|
||||
|
||||
timelineController = nil
|
||||
|
||||
actionsSubject.send(.finished)
|
||||
|
@ -8259,41 +8259,6 @@ class RoomProxyMock: RoomProxyProtocol {
|
||||
subscribeForUpdatesCallsCount += 1
|
||||
await subscribeForUpdatesClosure?()
|
||||
}
|
||||
//MARK: - unsubscribeFromUpdates
|
||||
|
||||
var unsubscribeFromUpdatesUnderlyingCallsCount = 0
|
||||
var unsubscribeFromUpdatesCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return unsubscribeFromUpdatesUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = unsubscribeFromUpdatesUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
unsubscribeFromUpdatesUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
unsubscribeFromUpdatesUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var unsubscribeFromUpdatesCalled: Bool {
|
||||
return unsubscribeFromUpdatesCallsCount > 0
|
||||
}
|
||||
var unsubscribeFromUpdatesClosure: (() -> Void)?
|
||||
|
||||
func unsubscribeFromUpdates() {
|
||||
unsubscribeFromUpdatesCallsCount += 1
|
||||
unsubscribeFromUpdatesClosure?()
|
||||
}
|
||||
//MARK: - timelineFocusedOnEvent
|
||||
|
||||
var timelineFocusedOnEventEventIDNumberOfEventsUnderlyingCallsCount = 0
|
||||
|
@ -46,7 +46,15 @@ enum ClientProxyError: Error {
|
||||
}
|
||||
|
||||
enum SlidingSyncConstants {
|
||||
static let defaultTimelineLimit: UInt = 20
|
||||
static let defaultTimelineLimit: UInt32 = 20
|
||||
static let maximumVisibleRangeSize = 30
|
||||
static let defaultRequiredState = [
|
||||
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: "")
|
||||
]
|
||||
}
|
||||
|
||||
/// This struct represents the configuration that we are using to register the application through Pusher to Sygnal
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user