vector-im/element-x-ios/issues/53 - Converted most callback based methods to async/await

This commit is contained in:
Stefan Ceriu
2022-05-24 16:59:01 +03:00
committed by Stefan Ceriu
parent f2fe39eca7
commit dde7786152
23 changed files with 407 additions and 454 deletions
@@ -65,19 +65,21 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
roomUpdateListeners.removeAll()
roomList.forEach({ roomSummary in
roomSummary.callbacks.sink { [weak self] callback in
guard let self = self else {
return
}
switch callback {
case .updatedData:
if let index = self.state.rooms.firstIndex(where: { $0.id == roomSummary.id }) {
self.state.rooms[index] = self.buildOrUpdateRoomFromSummary(roomSummary)
roomSummary.callbacks
.receive(on: DispatchQueue.main)
.sink { [weak self] callback in
guard let self = self else {
return
}
switch callback {
case .updatedData:
if let index = self.state.rooms.firstIndex(where: { $0.id == roomSummary.id }) {
self.state.rooms[index] = self.buildOrUpdateRoomFromSummary(roomSummary)
}
}
}
}
.store(in: &roomUpdateListeners)
.store(in: &roomUpdateListeners)
})
}
@@ -98,7 +100,9 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
return
}
roomSummary.loadData()
Task {
await roomSummary.loadDetails()
}
}
private func buildOrUpdateRoomFromSummary(_ roomSummary: RoomSummaryProtocol) -> HomeScreenRoom {