mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 15:45:11 +00:00
Add back custom identifiers for invalidated room, avoid duplicates and gaps on the room list
This commit is contained in:
committed by
Stefan Ceriu
parent
ee643f7a69
commit
d120a53ebd
@@ -215,8 +215,11 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
|||||||
switch summary {
|
switch summary {
|
||||||
case .empty:
|
case .empty:
|
||||||
rooms.append(HomeScreenRoom.placeholder())
|
rooms.append(HomeScreenRoom.placeholder())
|
||||||
|
case .invalidated(let details):
|
||||||
|
let room = buildRoom(with: details, invalidated: true)
|
||||||
|
rooms.append(room)
|
||||||
case .filled(let details):
|
case .filled(let details):
|
||||||
let room = buildRoom(with: details)
|
let room = buildRoom(with: details, invalidated: false)
|
||||||
rooms.append(room)
|
rooms.append(room)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,14 +229,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 {
|
||||||
HomeScreenRoom(id: details.id,
|
let identifier = invalidated ? "invalidated-" + details.id : details.id
|
||||||
roomId: details.id,
|
|
||||||
name: details.name,
|
return HomeScreenRoom(id: identifier,
|
||||||
hasUnreads: details.unreadNotificationCount > 0,
|
roomId: details.id,
|
||||||
timestamp: details.lastMessageFormattedTimestamp,
|
name: details.name,
|
||||||
lastMessage: .init(attributedString: details.lastMessage, isLoading: false),
|
hasUnreads: details.unreadNotificationCount > 0,
|
||||||
avatarURL: details.avatarURL)
|
timestamp: details.lastMessageFormattedTimestamp,
|
||||||
|
lastMessage: .init(attributedString: details.lastMessage, isLoading: false),
|
||||||
|
avatarURL: details.avatarURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateVisibleRange(_ range: Range<Int>) {
|
private func updateVisibleRange(_ range: Range<Int>) {
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ struct HomeScreenRoomCell_Previews: PreviewProvider {
|
|||||||
switch summary {
|
switch summary {
|
||||||
case .empty:
|
case .empty:
|
||||||
return nil
|
return nil
|
||||||
case .filled(let details):
|
case .invalidated(let details), .filled(let details):
|
||||||
return HomeScreenRoom(id: UUID().uuidString,
|
return HomeScreenRoom(id: UUID().uuidString,
|
||||||
roomId: details.id,
|
roomId: details.id,
|
||||||
name: details.name,
|
name: details.name,
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class MockClientProxy: ClientProxyProtocol {
|
|||||||
func uploadMedia(_ media: MediaInfo) async -> Result<String, ClientProxyError> {
|
func uploadMedia(_ media: MediaInfo) async -> Result<String, ClientProxyError> {
|
||||||
.failure(.failedUploadingMedia(.unknown))
|
.failure(.failedUploadingMedia(.unknown))
|
||||||
}
|
}
|
||||||
|
|
||||||
var roomForIdentifierMocks: [String: RoomProxyMock] = .init()
|
var roomForIdentifierMocks: [String: RoomProxyMock] = .init()
|
||||||
@MainActor
|
@MainActor
|
||||||
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? {
|
func roomForIdentifier(_ identifier: String) async -> RoomProxyProtocol? {
|
||||||
@@ -77,7 +77,7 @@ class MockClientProxy: ClientProxyProtocol {
|
|||||||
switch room {
|
switch room {
|
||||||
case .empty:
|
case .empty:
|
||||||
return RoomProxyMock(with: .init(displayName: "Empty room"))
|
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))
|
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" })")
|
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 {
|
guard let roomListItem = try? roomListService.room(roomId: identifier) else {
|
||||||
MXLog.error("\(name): Failed finding room with id: \(identifier)")
|
MXLog.error("\(name): Failed finding room with id: \(identifier)")
|
||||||
return .empty
|
return .empty
|
||||||
@@ -167,7 +167,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
|||||||
unreadNotificationCount: UInt(roomListItem.unreadNotifications().notificationCount()),
|
unreadNotificationCount: UInt(roomListItem.unreadNotifications().notificationCount()),
|
||||||
canonicalAlias: room.canonicalAlias())
|
canonicalAlias: room.canonicalAlias())
|
||||||
|
|
||||||
return .filled(details: details)
|
return invalidated ? .invalidated(details: details) : .filled(details: details)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func buildSummaryForRoomListEntry(_ entry: RoomListEntry) -> RoomSummary {
|
private func buildSummaryForRoomListEntry(_ entry: RoomListEntry) -> RoomSummary {
|
||||||
@@ -175,9 +175,9 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
|||||||
case .empty:
|
case .empty:
|
||||||
return .empty
|
return .empty
|
||||||
case .filled(let roomId):
|
case .filled(let roomId):
|
||||||
return buildRoomSummaryForIdentifier(roomId)
|
return buildRoomSummaryForIdentifier(roomId, invalidated: false)
|
||||||
case .invalidated(let roomId):
|
case .invalidated(let roomId):
|
||||||
return buildRoomSummaryForIdentifier(roomId)
|
return buildRoomSummaryForIdentifier(roomId, invalidated: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,13 @@ enum RoomSummaryProviderState {
|
|||||||
enum RoomSummary: CustomStringConvertible {
|
enum RoomSummary: CustomStringConvertible {
|
||||||
case empty
|
case empty
|
||||||
case filled(details: RoomSummaryDetails)
|
case filled(details: RoomSummaryDetails)
|
||||||
|
case invalidated(details: RoomSummaryDetails)
|
||||||
|
|
||||||
var id: String? {
|
var id: String? {
|
||||||
switch self {
|
switch self {
|
||||||
case .empty:
|
case .empty:
|
||||||
return nil
|
return nil
|
||||||
case .filled(let details):
|
case .invalidated(let details), .filled(let details):
|
||||||
return details.id
|
return details.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +43,7 @@ enum RoomSummary: CustomStringConvertible {
|
|||||||
switch self {
|
switch self {
|
||||||
case .empty:
|
case .empty:
|
||||||
return nil
|
return nil
|
||||||
case .filled(let details):
|
case .invalidated(let details), .filled(let details):
|
||||||
return details.name
|
return details.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,6 +52,8 @@ enum RoomSummary: CustomStringConvertible {
|
|||||||
switch self {
|
switch self {
|
||||||
case .empty:
|
case .empty:
|
||||||
return "\(String(describing: Self.self)): Empty"
|
return "\(String(describing: Self.self)): Empty"
|
||||||
|
case .invalidated(let details):
|
||||||
|
return "\(String(describing: Self.self)): Invalidated(\(details.id))"
|
||||||
case .filled(let details):
|
case .filled(let details):
|
||||||
return "\(String(describing: Self.self)): Filled(\(details.id))"
|
return "\(String(describing: Self.self)): Filled(\(details.id))"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user