Bump the SDK and handle breaking changes on timeline diffing

- avoid race conditions between when a timeline listener starts publishing to the `updatePublisher` and when they are consumed (and in which order)
- subscribe to the timeline directly in the TimelineProvider and correctly process updates serially
- update the AutoUpdatingRoomTimelineProviderMock to use an SDK TimlineMock and listener to publish updates
This commit is contained in:
Stefan Ceriu
2024-06-13 12:37:49 +03:00
committed by Stefan Ceriu
parent b73e5e9e5d
commit 8b3141ffec
7 changed files with 292 additions and 77 deletions
@@ -20,20 +20,25 @@ import MatrixRustSDK
@MainActor
class AutoUpdatingRoomTimelineProviderMock: RoomTimelineProvider {
private let innerUpdatePublisher: PassthroughSubject<[TimelineDiff], Never>
static var timelineListener: TimelineListener?
private let innerPaginationStatePublisher: PassthroughSubject<PaginationState, Never>
private let innerItems: [TimelineItemProxy] = []
init() {
innerUpdatePublisher = .init()
innerPaginationStatePublisher = .init()
super.init(currentItems: [],
let timelineMock = TimelineSDKMock()
timelineMock.addListenerListenerClosure = { listener in
Self.timelineListener = listener
return TaskHandleSDKMock()
}
super.init(timeline: timelineMock,
isLive: true,
updatePublisher: innerUpdatePublisher.eraseToAnyPublisher(),
paginationStatePublisher: innerPaginationStatePublisher.eraseToAnyPublisher())
Task.detached { [weak self] in
Task.detached {
for _ in 0...100 {
try? await Task.sleep(for: .seconds(1))
@@ -41,7 +46,7 @@ class AutoUpdatingRoomTimelineProviderMock: RoomTimelineProvider {
diff.changeReturnValue = .append
diff.appendReturnValue = [TimelineItemFixtures.messageTimelineItem]
self?.innerUpdatePublisher.send([diff])
await Self.timelineListener?.onUpdate(diff: [diff])
}
}
}