mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Guard against large visible room list ranges
This commit is contained in:
committed by
Stefan Ceriu
parent
2ccf9de9b8
commit
5f55796b7f
@@ -49,6 +49,7 @@ enum ClientProxyError: Error {
|
||||
|
||||
enum SlidingSyncConstants {
|
||||
static let defaultTimelineLimit: UInt = 20
|
||||
static let maximumVisibleRangeSize = 30
|
||||
}
|
||||
|
||||
/// This struct represents the configuration that we are using to register the application through Pusher to Sygnal
|
||||
|
||||
@@ -108,8 +108,16 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
func updateVisibleRange(_ range: Range<Int>) {
|
||||
Task {
|
||||
do {
|
||||
MXLog.info("\(name): Setting visible range to \(range)")
|
||||
try await roomListService.applyInput(input: .viewport(ranges: [.init(start: UInt32(range.lowerBound), endInclusive: UInt32(range.upperBound))]))
|
||||
// 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 upperBound = range.upperBound
|
||||
if range.upperBound - range.lowerBound > SlidingSyncConstants.maximumVisibleRangeSize {
|
||||
upperBound = range.lowerBound + SlidingSyncConstants.maximumVisibleRangeSize
|
||||
}
|
||||
|
||||
MXLog.info("\(name): Setting visible range to \(range.lowerBound)...\(upperBound)")
|
||||
|
||||
try await roomListService.applyInput(input: .viewport(ranges: [.init(start: UInt32(range.lowerBound), endInclusive: UInt32(upperBound))]))
|
||||
} catch {
|
||||
MXLog.error("Failed updating visible range with error: \(error)")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user