Fix incorrect diffing behavior on replacement in both the timelineProvider and the roomSummaryProvider
This commit is contained in:
committed by
Stefan Ceriu
parent
0bb8688100
commit
b1ab22ca7e
@@ -141,8 +141,13 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
|
||||
fileprivate func updateRoomsWithDiffs(_ diffs: [SlidingSyncViewRoomsListDiff]) {
|
||||
rooms = diffs
|
||||
.compactMap(buildDiff)
|
||||
.reduce(rooms) { $0.applying($1) ?? $0 }
|
||||
.reduce(rooms) { partialResult, diff in
|
||||
guard let collectionDiff = buildDiff(from: diff, on: partialResult) else {
|
||||
return partialResult
|
||||
}
|
||||
|
||||
return partialResult.applying(collectionDiff) ?? partialResult
|
||||
}
|
||||
}
|
||||
|
||||
private func buildEmptyRoomSummary(forIdentifier identifier: String = UUID().uuidString) -> RoomSummary {
|
||||
@@ -186,7 +191,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
private func buildDiff(from diff: SlidingSyncViewRoomsListDiff) -> CollectionDifference<RoomSummary>? {
|
||||
private func buildDiff(from diff: SlidingSyncViewRoomsListDiff, on rooms: [RoomSummary]) -> CollectionDifference<RoomSummary>? {
|
||||
// Invalidations are a no-op for the moment
|
||||
if diff.isInvalidation {
|
||||
return nil
|
||||
@@ -217,12 +222,9 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
changes.append(.remove(offset: index, element: summary, associatedWith: nil))
|
||||
}
|
||||
|
||||
values
|
||||
.reversed()
|
||||
.map { buildSummaryForRoomListEntry($0) }
|
||||
.forEach { summary in
|
||||
changes.append(.insert(offset: 0, element: summary, associatedWith: nil))
|
||||
}
|
||||
for (index, value) in values.enumerated() {
|
||||
changes.append(.insert(offset: index, element: buildSummaryForRoomListEntry(value), associatedWith: nil))
|
||||
}
|
||||
}
|
||||
|
||||
return CollectionDifference(changes)
|
||||
|
||||
@@ -105,15 +105,20 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
|
||||
private func updateItemsWithDiffs(_ diffs: [TimelineDiff]) {
|
||||
itemProxies = diffs
|
||||
.compactMap(buildDiff)
|
||||
.reduce(itemProxies) { $0.applying($1) ?? $0 }
|
||||
.reduce(itemProxies) { partialResult, diff in
|
||||
guard let collectionDiff = buildDiff(from: diff, on: partialResult) else {
|
||||
return partialResult
|
||||
}
|
||||
|
||||
return partialResult.applying(collectionDiff) ?? partialResult
|
||||
}
|
||||
}
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
private func buildDiff(from diff: TimelineDiff) -> CollectionDifference<TimelineItemProxy>? {
|
||||
private func buildDiff(from diff: TimelineDiff, on itemProxies: [TimelineItemProxy]) -> CollectionDifference<TimelineItemProxy>? {
|
||||
var changes = [CollectionDifference<TimelineItemProxy>.Change]()
|
||||
|
||||
switch diff.change() {
|
||||
@@ -150,12 +155,9 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
|
||||
changes.append(.remove(offset: index, element: itemProxy, associatedWith: nil))
|
||||
}
|
||||
|
||||
items
|
||||
.reversed()
|
||||
.map { TimelineItemProxy(item: $0) }
|
||||
.forEach { itemProxy in
|
||||
changes.append(.insert(offset: 0, element: itemProxy, associatedWith: nil))
|
||||
}
|
||||
for (index, item) in items.enumerated() {
|
||||
changes.append(.insert(offset: index, element: TimelineItemProxy(item: item), associatedWith: nil))
|
||||
}
|
||||
}
|
||||
case .clear:
|
||||
for (index, itemProxy) in itemProxies.enumerated() {
|
||||
|
||||
Reference in New Issue
Block a user