diff --git a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift index 47b9bdb7a6..891e0fdc8e 100644 --- a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift @@ -680,8 +680,6 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { navigationStackCoordinator.setRootCoordinator(nil, animated: false) } - roomProxy?.unsubscribeFromUpdates() - timelineController = nil actionsSubject.send(.finished) diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index 8cf4415aa7..c091ecabef 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -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 diff --git a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift index 963b680cfe..fbe7960a37 100644 --- a/ElementX/Sources/Services/Client/ClientProxyProtocol.swift +++ b/ElementX/Sources/Services/Client/ClientProxyProtocol.swift @@ -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 diff --git a/ElementX/Sources/Services/Room/RoomProxy.swift b/ElementX/Sources/Services/Room/RoomProxy.swift index 94bf834eec..dbb27ce847 100644 --- a/ElementX/Sources/Services/Room/RoomProxy.swift +++ b/ElementX/Sources/Services/Room/RoomProxy.swift @@ -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 { do { let timeline = try await room.timelineFocusedOnEvent(eventId: eventID, numContextEvents: numberOfEvents, internalIdPrefix: UUID().uuidString) diff --git a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift index 011896b18a..bcba50ca10 100644 --- a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift @@ -66,8 +66,6 @@ protocol RoomProxyProtocol { func subscribeForUpdates() async - func unsubscribeFromUpdates() - func timelineFocusedOnEvent(eventID: String, numberOfEvents: UInt16) async -> Result func redact(_ eventID: String) async -> Result diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift index 6562382994..c1e42cee31 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift @@ -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..