diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift index 9eb12144d..18dfd8862 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift @@ -215,8 +215,11 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol switch summary { case .empty: rooms.append(HomeScreenRoom.placeholder()) + case .invalidated(let details): + let room = buildRoom(with: details, invalidated: true) + rooms.append(room) case .filled(let details): - let room = buildRoom(with: details) + let room = buildRoom(with: details, invalidated: false) rooms.append(room) } } @@ -226,14 +229,16 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol MXLog.info("Finished updating rooms") } - private func buildRoom(with details: RoomSummaryDetails) -> HomeScreenRoom { - HomeScreenRoom(id: details.id, - roomId: details.id, - name: details.name, - hasUnreads: details.unreadNotificationCount > 0, - timestamp: details.lastMessageFormattedTimestamp, - lastMessage: .init(attributedString: details.lastMessage, isLoading: false), - avatarURL: details.avatarURL) + private func buildRoom(with details: RoomSummaryDetails, invalidated: Bool) -> HomeScreenRoom { + let identifier = invalidated ? "invalidated-" + details.id : details.id + + return HomeScreenRoom(id: identifier, + roomId: details.id, + name: details.name, + hasUnreads: details.unreadNotificationCount > 0, + timestamp: details.lastMessageFormattedTimestamp, + lastMessage: .init(attributedString: details.lastMessage, isLoading: false), + avatarURL: details.avatarURL) } private func updateVisibleRange(_ range: Range) { diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift index 60ca09f4b..abcf932e2 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift @@ -177,7 +177,7 @@ struct HomeScreenRoomCell_Previews: PreviewProvider { switch summary { case .empty: return nil - case .filled(let details): + case .invalidated(let details), .filled(let details): return HomeScreenRoom(id: UUID().uuidString, roomId: details.id, name: details.name, diff --git a/ElementX/Sources/Services/Client/MockClientProxy.swift b/ElementX/Sources/Services/Client/MockClientProxy.swift index 9c21ddab6..2d99c3349 100644 --- a/ElementX/Sources/Services/Client/MockClientProxy.swift +++ b/ElementX/Sources/Services/Client/MockClientProxy.swift @@ -62,7 +62,7 @@ class MockClientProxy: ClientProxyProtocol { func uploadMedia(_ media: MediaInfo) async -> Result { .failure(.failedUploadingMedia(.unknown)) } - + var roomForIdentifierMocks: [String: RoomProxyMock] = .init() @MainActor func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? { @@ -77,7 +77,7 @@ class MockClientProxy: ClientProxyProtocol { switch room { case .empty: return RoomProxyMock(with: .init(displayName: "Empty room")) - case .filled(let details): + case .filled(let details), .invalidated(let details): return RoomProxyMock(with: .init(displayName: details.name)) } } diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift index a88392b57..58bdc957d 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift @@ -141,7 +141,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { MXLog.verbose("\(name): Finished applying \(diffs.count) diffs, new room list \(rooms.compactMap { $0.id ?? "Empty" })") } - private func buildRoomSummaryForIdentifier(_ identifier: String) -> RoomSummary { + private func buildRoomSummaryForIdentifier(_ identifier: String, invalidated: Bool) -> RoomSummary { guard let roomListItem = try? roomListService.room(roomId: identifier) else { MXLog.error("\(name): Failed finding room with id: \(identifier)") return .empty @@ -167,7 +167,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { unreadNotificationCount: UInt(roomListItem.unreadNotifications().notificationCount()), canonicalAlias: room.canonicalAlias()) - return .filled(details: details) + return invalidated ? .invalidated(details: details) : .filled(details: details) } private func buildSummaryForRoomListEntry(_ entry: RoomListEntry) -> RoomSummary { @@ -175,9 +175,9 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { case .empty: return .empty case .filled(let roomId): - return buildRoomSummaryForIdentifier(roomId) + return buildRoomSummaryForIdentifier(roomId, invalidated: false) case .invalidated(let roomId): - return buildRoomSummaryForIdentifier(roomId) + return buildRoomSummaryForIdentifier(roomId, invalidated: true) } } diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift index 2c355b4c5..a87684254 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift @@ -28,12 +28,13 @@ enum RoomSummaryProviderState { enum RoomSummary: CustomStringConvertible { case empty case filled(details: RoomSummaryDetails) + case invalidated(details: RoomSummaryDetails) var id: String? { switch self { case .empty: return nil - case .filled(let details): + case .invalidated(let details), .filled(let details): return details.id } } @@ -42,7 +43,7 @@ enum RoomSummary: CustomStringConvertible { switch self { case .empty: return nil - case .filled(let details): + case .invalidated(let details), .filled(let details): return details.name } } @@ -51,6 +52,8 @@ enum RoomSummary: CustomStringConvertible { switch self { case .empty: return "\(String(describing: Self.self)): Empty" + case .invalidated(let details): + return "\(String(describing: Self.self)): Invalidated(\(details.id))" case .filled(let details): return "\(String(describing: Self.self)): Filled(\(details.id))" }