mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
This commit is contained in:
@@ -205,16 +205,33 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
MXLog.info("Updating rooms")
|
||||
|
||||
var rooms = [HomeScreenRoom]()
|
||||
var createdRoomIdentifiers = [String: Bool]()
|
||||
|
||||
#warning("This works around duplicated room list items coming out of the SDK, remove once fixed")
|
||||
func appendRoom(_ room: HomeScreenRoom, allRoomsProvider: Bool) {
|
||||
guard createdRoomIdentifiers[room.id] == nil else {
|
||||
MXLog.error("Built duplicated room for identifier: \(room.id). AllRoomsSummaryProvider: \(allRoomsProvider). Ignoring")
|
||||
return
|
||||
}
|
||||
|
||||
createdRoomIdentifiers[room.id] = true
|
||||
rooms.append(room)
|
||||
}
|
||||
|
||||
// Try merging together results from both the visibleRoomsSummaryProvider and the allRoomsSummaryProvider
|
||||
// Empty or invalidated items in the visibleRoomsSummaryProvider might have more details in the allRoomsSummaryProvider
|
||||
// If items are unavailable in the allRoomsSummaryProvider (hasn't be added to SS yet / cold cache) then use what's available
|
||||
for (index, summary) in visibleRoomsSummaryProvider.roomListPublisher.value.enumerated() {
|
||||
switch summary {
|
||||
case .filled(let details):
|
||||
let room = buildRoom(with: details, invalidated: false, isLoading: false)
|
||||
appendRoom(room, allRoomsProvider: false)
|
||||
case .empty, .invalidated:
|
||||
// Try getting details from the allRoomsSummaryProvider
|
||||
guard let allRoomsRoomSummary = allRoomsSummaryProvider?.roomListPublisher.value[safe: index] else {
|
||||
if case let .invalidated(details) = summary {
|
||||
rooms.append(buildRoom(with: details, invalidated: true, isLoading: false))
|
||||
let room = buildRoom(with: details, invalidated: true, isLoading: false)
|
||||
appendRoom(room, allRoomsProvider: true)
|
||||
} else {
|
||||
rooms.append(HomeScreenRoom.placeholder())
|
||||
}
|
||||
@@ -224,11 +241,13 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
switch allRoomsRoomSummary {
|
||||
case .empty:
|
||||
rooms.append(HomeScreenRoom.placeholder())
|
||||
case .filled(let details), .invalidated(let details):
|
||||
rooms.append(buildRoom(with: details, invalidated: false, isLoading: true))
|
||||
case .filled(let details):
|
||||
let room = buildRoom(with: details, invalidated: false, isLoading: true)
|
||||
appendRoom(room, allRoomsProvider: true)
|
||||
case .invalidated(let details):
|
||||
let room = buildRoom(with: details, invalidated: true, isLoading: true)
|
||||
appendRoom(room, allRoomsProvider: true)
|
||||
}
|
||||
case .filled(let details):
|
||||
rooms.append(buildRoom(with: details, invalidated: false, isLoading: false))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user