mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Add back custom identifiers for invalidated room, avoid duplicates and gaps on the room list
This commit is contained in:
parent
ee643f7a69
commit
d120a53ebd
@ -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<Int>) {
|
||||
|
@ -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,
|
||||
|
@ -62,7 +62,7 @@ class MockClientProxy: ClientProxyProtocol {
|
||||
func uploadMedia(_ media: MediaInfo) async -> Result<String, ClientProxyError> {
|
||||
.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))
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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))"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user