mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Room list searching tweaks (#1800)
* Prevent the room list from flashing previous rooms when searching * Remove reset diff chunking now that the whole list is limited * Bump the Rust SDK to v1.1.19 and fix breaking API changes
This commit is contained in:
@@ -241,9 +241,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
|
||||
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? {
|
||||
// Try fetching the room from the cold cache (if available) first
|
||||
var (roomListItem, room) = await Task.dispatch(on: clientQueue) {
|
||||
self.roomTupleForIdentifier(identifier)
|
||||
}
|
||||
var (roomListItem, room) = await roomTupleForIdentifier(identifier)
|
||||
|
||||
if let roomListItem, let room {
|
||||
return await RoomProxy(roomListItem: roomListItem,
|
||||
@@ -262,9 +260,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
_ = await roomSummaryProvider.statePublisher.values.first(where: { $0.isLoaded })
|
||||
}
|
||||
|
||||
(roomListItem, room) = await Task.dispatch(on: clientQueue) {
|
||||
self.roomTupleForIdentifier(identifier)
|
||||
}
|
||||
(roomListItem, room) = await roomTupleForIdentifier(identifier)
|
||||
|
||||
guard let roomListItem else {
|
||||
MXLog.error("Invalid roomListItem for identifier \(identifier)")
|
||||
@@ -519,10 +515,10 @@ class ClientProxy: ClientProxyProtocol {
|
||||
})
|
||||
}
|
||||
|
||||
private func roomTupleForIdentifier(_ identifier: String) -> (RoomListItem?, Room?) {
|
||||
private func roomTupleForIdentifier(_ identifier: String) async -> (RoomListItem?, Room?) {
|
||||
do {
|
||||
let roomListItem = try roomListService?.room(roomId: identifier)
|
||||
let fullRoom = roomListItem?.fullRoom()
|
||||
let fullRoom = await roomListItem?.fullRoom()
|
||||
|
||||
return (roomListItem, fullRoom)
|
||||
} catch {
|
||||
|
||||
@@ -182,7 +182,7 @@ struct MediaUploadingPreprocessor {
|
||||
case .success(let result):
|
||||
switch await generateThumbnailForVideoAt(result.url) {
|
||||
case .success(let thumbnailResult):
|
||||
let videoSize = ((try? UInt64(FileManager.default.sizeForItem(at: result.url))) ?? 0) ?? 0
|
||||
let videoSize = (try? UInt64(FileManager.default.sizeForItem(at: result.url))) ?? 0
|
||||
let thumbnailSize = (try? UInt64(FileManager.default.sizeForItem(at: thumbnailResult.url))) ?? 0
|
||||
|
||||
let thumbnailInfo = ThumbnailInfo(height: UInt64(thumbnailResult.height),
|
||||
|
||||
@@ -271,7 +271,8 @@ class RoomProxy: RoomProxyProtocol {
|
||||
return await Task.dispatch(on: messageSendingDispatchQueue) {
|
||||
do {
|
||||
if let eventID {
|
||||
try self.room.sendReply(msg: messageContent, inReplyToEventId: eventID, txnId: transactionId)
|
||||
let replyItem = try self.room.getEventTimelineItemByEventId(eventId: eventID)
|
||||
try self.room.sendReply(msg: messageContent, replyItem: replyItem, txnId: transactionId)
|
||||
} else {
|
||||
self.room.send(msg: messageContent, txnId: transactionId)
|
||||
}
|
||||
@@ -662,7 +663,7 @@ class RoomProxy: RoomProxyProtocol {
|
||||
|
||||
do {
|
||||
let data = try Data(contentsOf: imageURL)
|
||||
return try .success(self.room.uploadAvatar(mimeType: mimeType, data: [UInt8](data)))
|
||||
return try .success(self.room.uploadAvatar(mimeType: mimeType, data: [UInt8](data), mediaInfo: nil))
|
||||
} catch {
|
||||
return .failure(.failedUploadingAvatar)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class MockRoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
|
||||
func updateVisibleRange(_ range: Range<Int>) { }
|
||||
|
||||
func updateFilterPattern(_ pattern: String?) { }
|
||||
func setFilter(_ filter: RoomSummaryProviderFilter) { }
|
||||
}
|
||||
|
||||
extension Array where Element == RoomSummary {
|
||||
|
||||
@@ -91,7 +91,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
})
|
||||
|
||||
// Forces the listener above to be called with the current state
|
||||
updateFilterPattern(nil)
|
||||
setFilter(.all)
|
||||
|
||||
listUpdatesTaskHandle = listUpdatesSubscriptionResult?.entriesStream
|
||||
|
||||
@@ -134,13 +134,15 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func updateFilterPattern(_ pattern: String?) {
|
||||
guard let pattern, !pattern.isEmpty else {
|
||||
func setFilter(_ filter: RoomSummaryProviderFilter) {
|
||||
switch filter {
|
||||
case .none:
|
||||
_ = listUpdatesSubscriptionResult?.controller.setFilter(kind: .none)
|
||||
case .all:
|
||||
_ = listUpdatesSubscriptionResult?.controller.setFilter(kind: .all)
|
||||
return
|
||||
case .normalizedMatchRoomName(let query):
|
||||
_ = listUpdatesSubscriptionResult?.controller.setFilter(kind: .normalizedMatchRoomName(pattern: query.lowercased()))
|
||||
}
|
||||
|
||||
_ = listUpdatesSubscriptionResult?.controller.setFilter(kind: .normalizedMatchRoomName(pattern: pattern.lowercased()))
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
@@ -156,23 +158,9 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
|
||||
MXLog.verbose("\(name): Received \(diffs.count) diffs, current room list \(rooms.compactMap { $0.id ?? "Empty" })")
|
||||
|
||||
var updatedItems = rooms
|
||||
for diff in diffs {
|
||||
let resetDiffChunkingThreshhold = 50
|
||||
if case .reset(let values) = diff, values.count > resetDiffChunkingThreshhold {
|
||||
// Special case resets in order to prevent large updates from blocking the UI
|
||||
// Render the first resetDiffChunkingThreshhold as a reset and then append the rest to give the UI time to update
|
||||
updatedItems = processDiff(.reset(values: Array(values[..<resetDiffChunkingThreshhold])), on: updatedItems)
|
||||
|
||||
// Once a reset is chunked dispatch the first part to the UI for rendering
|
||||
rooms = updatedItems
|
||||
|
||||
updatedItems = processDiff(.append(values: Array(values.dropFirst(resetDiffChunkingThreshhold))), on: updatedItems)
|
||||
} else {
|
||||
updatedItems = processDiff(diff, on: updatedItems)
|
||||
}
|
||||
rooms = diffs.reduce(rooms) { currentItems, diff in
|
||||
processDiff(diff, on: currentItems)
|
||||
}
|
||||
rooms = updatedItems
|
||||
|
||||
MXLog.verbose("\(name): Finished applying \(diffs.count) diffs, new room list \(rooms.compactMap { $0.id ?? "Empty" })")
|
||||
|
||||
|
||||
@@ -87,6 +87,12 @@ enum RoomSummary: CustomStringConvertible, Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
enum RoomSummaryProviderFilter {
|
||||
case none
|
||||
case all
|
||||
case normalizedMatchRoomName(String)
|
||||
}
|
||||
|
||||
protocol RoomSummaryProviderProtocol {
|
||||
/// Publishes the currently available room summaries
|
||||
var roomListPublisher: CurrentValuePublisher<[RoomSummary], Never> { get }
|
||||
@@ -100,5 +106,5 @@ protocol RoomSummaryProviderProtocol {
|
||||
|
||||
func updateVisibleRange(_ range: Range<Int>)
|
||||
|
||||
func updateFilterPattern(_ pattern: String?)
|
||||
func setFilter(_ filter: RoomSummaryProviderFilter)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user