mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Show the last message state in the room list.
This commit is contained in:
@@ -197,6 +197,9 @@ struct HomeScreenRoom: Identifiable, Equatable {
|
||||
|
||||
let lastMessage: AttributedString?
|
||||
|
||||
enum LastMessageState { case sending, failed }
|
||||
let lastMessageState: LastMessageState?
|
||||
|
||||
let avatar: RoomAvatar
|
||||
|
||||
let canonicalAlias: String?
|
||||
@@ -204,11 +207,13 @@ struct HomeScreenRoom: Identifiable, Equatable {
|
||||
let isTombstoned: Bool
|
||||
|
||||
var displayedLastMessage: AttributedString? {
|
||||
// If the room is tombstoned, show a specific message, regardless of any last message.
|
||||
guard !isTombstoned else {
|
||||
return AttributedString(L10n.screenRoomlistTombstonedRoomDescription)
|
||||
if isTombstoned {
|
||||
AttributedString(L10n.screenRoomlistTombstonedRoomDescription)
|
||||
} else if lastMessageState == .failed {
|
||||
AttributedString(L10n.commonMessageFailedToSend)
|
||||
} else {
|
||||
lastMessage
|
||||
}
|
||||
return lastMessage
|
||||
}
|
||||
|
||||
static func placeholder() -> HomeScreenRoom {
|
||||
@@ -222,6 +227,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
|
||||
isFavourite: false,
|
||||
timestamp: "Now",
|
||||
lastMessage: placeholderLastMessage,
|
||||
lastMessageState: nil,
|
||||
avatar: .room(id: "", name: "", avatarURL: nil),
|
||||
canonicalAlias: nil,
|
||||
isTombstoned: false)
|
||||
@@ -260,8 +266,23 @@ extension HomeScreenRoom {
|
||||
isFavourite: summary.isFavourite,
|
||||
timestamp: summary.lastMessageDate?.formattedMinimal(),
|
||||
lastMessage: summary.lastMessage,
|
||||
lastMessageState: summary.homeScreenLastMessageState,
|
||||
avatar: summary.avatar,
|
||||
canonicalAlias: summary.canonicalAlias,
|
||||
isTombstoned: summary.isTombstoned)
|
||||
}
|
||||
}
|
||||
|
||||
private extension RoomSummary {
|
||||
var homeScreenLastMessageState: HomeScreenRoom.LastMessageState? {
|
||||
if isTombstoned {
|
||||
nil
|
||||
} else {
|
||||
switch lastMessageState {
|
||||
case .sending: .sending
|
||||
case .failed: .failed
|
||||
case .none: .none
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user