Skip to content

Commit

Permalink
Process diffs as batches provided by the SDK.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave authored and alfogrillo committed Jul 27, 2023
1 parent 738917d commit 789599f
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
private let stateSubject = CurrentValueSubject<RoomSummaryProviderState, Never>(.notLoaded)
private let countSubject = CurrentValueSubject<UInt, Never>(0)

private let diffPublisher = PassthroughSubject<RoomListEntriesUpdate, Never>()
private let diffsPublisher = PassthroughSubject<[RoomListEntriesUpdate], Never>()

var roomListPublisher: CurrentValuePublisher<[RoomSummary], Never> {
roomListSubject.asCurrentValuePublisher()
Expand All @@ -59,8 +59,8 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
self.eventStringBuilder = eventStringBuilder
self.name = name

diffPublisher
.collect(.byTime(serialDispatchQueue, 0.025))
diffsPublisher
.receive(on: serialDispatchQueue)
.sink { [weak self] in self?.updateRoomsWithDiffs($0) }
.store(in: &cancellables)
}
Expand All @@ -73,10 +73,10 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
self.roomList = roomList

do {
let listUpdatesSubscriptionResult = try roomList.entries(listener: RoomListEntriesListenerProxy { [weak self] update in
let listUpdatesSubscriptionResult = try roomList.entries(listener: RoomListEntriesListenerProxy { [weak self] updates in
guard let self else { return }
MXLog.verbose("\(name): Received list update")
diffPublisher.send(update)
diffsPublisher.send(updates)
})

listUpdatesTaskHandle = listUpdatesSubscriptionResult.entriesStream
Expand Down Expand Up @@ -324,17 +324,14 @@ extension MatrixRustSDK.RoomListEntry {
}

private class RoomListEntriesListenerProxy: RoomListEntriesListener {
private let onUpdateClosure: (RoomListEntriesUpdate) -> Void
private let onUpdateClosure: ([RoomListEntriesUpdate]) -> Void

init(_ onUpdateClosure: @escaping (RoomListEntriesUpdate) -> Void) {
init(_ onUpdateClosure: @escaping ([RoomListEntriesUpdate]) -> Void) {
self.onUpdateClosure = onUpdateClosure
}

func onUpdate(roomEntriesUpdate: [RoomListEntriesUpdate]) {
#warning("Review me")
for update in roomEntriesUpdate {
onUpdateClosure(update)
}
onUpdateClosure(roomEntriesUpdate)
}
}

Expand Down

0 comments on commit 789599f

Please sign in to comment.