Use the room heroes when computing a DM avatar. (#2900)

* Use room heroes for DM avatar content ID.

* Use RoomAvatar.heroes for the DM Details stack.
This commit is contained in:
Doug
2024-06-19 11:27:10 +01:00
committed by GitHub
parent 17d96b0f4b
commit 834260c144
55 changed files with 524 additions and 198 deletions
@@ -26,6 +26,7 @@ struct RoomSummaryDetails {
let name: String
let isDirect: Bool
let avatarURL: URL?
let heroes: [UserProfileProxy]
let lastMessage: AttributedString?
let lastMessageFormattedTimestamp: String?
let unreadMessagesCount: UInt
@@ -64,6 +65,7 @@ extension RoomSummaryDetails {
name = string
isDirect = true
avatarURL = nil
heroes = []
lastMessage = AttributedString(string)
lastMessageFormattedTimestamp = "Now"
unreadMessagesCount = hasUnreadMessages ? 1 : 0
@@ -78,4 +80,12 @@ extension RoomSummaryDetails {
isMarkedUnread = false
isFavourite = false
}
var avatar: RoomAvatar {
if isDirect, avatarURL == nil, heroes.count == 1 {
.heroes(heroes)
} else {
.room(id: id, name: name, avatarURL: avatarURL)
}
}
}
@@ -252,6 +252,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
name: roomInfo.displayName ?? roomInfo.id,
isDirect: roomInfo.isDirect,
avatarURL: roomInfo.avatarUrl.flatMap(URL.init(string:)),
heroes: roomInfo.heroes.map(UserProfileProxy.init),
lastMessage: attributedLastMessage,
lastMessageFormattedTimestamp: lastMessageFormattedTimestamp,
unreadMessagesCount: UInt(roomInfo.numUnreadMessages),