Introduce back custom room list item identifiers for invalidated rooms

This commit is contained in:
Stefan Ceriu
2023-02-01 14:07:01 +02:00
committed by Stefan Ceriu
parent 3775569f48
commit a9c24abcdf
@@ -31,8 +31,6 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
private let visibleItemRangePublisher = CurrentValueSubject<Range<Int>, Never>(0..<0) private let visibleItemRangePublisher = CurrentValueSubject<Range<Int>, Never>(0..<0)
private var roomsForIdentifiers = [String: HomeScreenRoom]()
var callback: ((HomeScreenViewModelAction) -> Void)? var callback: ((HomeScreenViewModelAction) -> Void)?
// swiftlint:disable:next function_body_length cyclomatic_complexity // swiftlint:disable:next function_body_length cyclomatic_complexity
@@ -202,7 +200,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
case .empty, .invalidated: case .empty, .invalidated:
guard let allRoomsRoomSummary = allRoomsSummaryProvider?.roomListPublisher.value[safe: index] else { guard let allRoomsRoomSummary = allRoomsSummaryProvider?.roomListPublisher.value[safe: index] else {
if case let .invalidated(details) = summary { if case let .invalidated(details) = summary {
rooms.append(buildRoom(with: details)) rooms.append(buildRoom(with: details, invalidated: true))
} else { } else {
rooms.append(HomeScreenRoom.placeholder()) rooms.append(HomeScreenRoom.placeholder())
} }
@@ -213,10 +211,10 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
case .empty: case .empty:
rooms.append(HomeScreenRoom.placeholder()) rooms.append(HomeScreenRoom.placeholder())
case .filled(let details), .invalidated(let details): case .filled(let details), .invalidated(let details):
rooms.append(buildRoom(with: details)) rooms.append(buildRoom(with: details, invalidated: false))
} }
case .filled(let details): case .filled(let details):
rooms.append(buildRoom(with: details)) rooms.append(buildRoom(with: details, invalidated: false))
} }
} }
@@ -225,23 +223,16 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
MXLog.info("Finished updating rooms") MXLog.info("Finished updating rooms")
} }
private func buildRoom(with details: RoomSummaryDetails) -> HomeScreenRoom { private func buildRoom(with details: RoomSummaryDetails, invalidated: Bool) -> HomeScreenRoom {
var room: HomeScreenRoom! = roomsForIdentifiers[details.id] let identifier = invalidated ? "invalidated-" + details.id : details.id
if room == nil { return HomeScreenRoom(id: identifier,
room = HomeScreenRoom(id: details.id, roomId: details.id,
roomId: details.id, name: details.name,
avatarURL: details.avatarURL) hasUnreads: details.unreadNotificationCount > 0,
} timestamp: details.lastMessageFormattedTimestamp,
lastMessage: details.lastMessage,
room.name = details.name avatarURL: details.avatarURL)
room.hasUnreads = details.unreadNotificationCount > 0
room.lastMessage = details.lastMessage
room.timestamp = details.lastMessageFormattedTimestamp
roomsForIdentifiers[details.id] = room
return room
} }
private func updateVisibleRange(_ range: Range<Int>, timelineLimit: UInt) { private func updateVisibleRange(_ range: Range<Int>, timelineLimit: UInt) {