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
@@ -157,7 +157,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
let id: String
/// The real room identifier this item points to
let roomId: String?
let roomID: String?
let type: RoomType
@@ -181,7 +181,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
let lastMessage: AttributedString?
let avatarURL: URL?
let avatar: RoomAvatar
let inviter: InviterDetails?
@@ -189,7 +189,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
static func placeholder() -> HomeScreenRoom {
HomeScreenRoom(id: UUID().uuidString,
roomId: nil,
roomID: nil,
type: .placeholder,
badges: .init(isDotShown: false, isMentionShown: false, isMuteShown: false, isCallShown: false),
name: "Placeholder room name",
@@ -198,7 +198,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
isFavourite: false,
timestamp: "Now",
lastMessage: placeholderLastMessage,
avatarURL: nil,
avatar: .room(id: "", name: "", avatarURL: nil),
inviter: nil,
canonicalAlias: nil)
}
@@ -224,7 +224,7 @@ extension HomeScreenRoom {
}
self.init(id: identifier,
roomId: details.id,
roomID: details.id,
type: details.isInvite ? .invite : .room,
badges: .init(isDotShown: isDotShown,
isMentionShown: isMentionShown,
@@ -236,7 +236,7 @@ extension HomeScreenRoom {
isFavourite: details.isFavourite,
timestamp: details.lastMessageFormattedTimestamp,
lastMessage: details.lastMessage,
avatarURL: details.avatarURL,
avatar: details.avatar,
inviter: inviter,
canonicalAlias: details.canonicalAlias)
}
@@ -15,6 +15,7 @@
//
import Combine
import Compound
import SwiftUI
@MainActor
@@ -27,11 +28,9 @@ struct HomeScreenInviteCell: View {
var body: some View {
HStack(alignment: .top, spacing: 16) {
if dynamicTypeSize < .accessibility3 {
LoadableAvatarImage(url: room.avatarURL,
name: title,
contentID: room.id,
avatarSize: .custom(52),
imageProvider: context.imageProvider)
RoomAvatarImage(avatar: room.avatar,
avatarSize: .custom(52),
imageProvider: context.imageProvider)
.dynamicTypeSize(dynamicTypeSize < .accessibility1 ? dynamicTypeSize : .accessibility1)
.accessibilityHidden(true)
}
@@ -48,8 +47,8 @@ struct HomeScreenInviteCell: View {
.padding(.top, 12)
.padding(.leading, 16)
.onTapGesture {
if let roomId = room.roomId {
context.send(viewAction: .selectRoom(roomIdentifier: roomId))
if let roomID = room.roomID {
context.send(viewAction: .selectRoom(roomIdentifier: roomID))
}
}
}
@@ -214,6 +213,7 @@ private extension HomeScreenRoom {
name: "Some Guy",
isDirect: true,
avatarURL: nil,
heroes: [.init(userID: "@someone:somewhere.com")],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
@@ -240,6 +240,7 @@ private extension HomeScreenRoom {
name: "Awesome Room",
isDirect: false,
avatarURL: avatarURL,
heroes: [.init(userID: "@someone:somewhere.com")],
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadMessagesCount: 0,
@@ -31,8 +31,8 @@ struct HomeScreenRoomCell: View {
var body: some View {
Button {
if let roomId = room.roomId {
context.send(viewAction: .selectRoom(roomIdentifier: roomId))
if let roomID = room.roomID {
context.send(viewAction: .selectRoom(roomIdentifier: roomID))
}
} label: {
HStack(spacing: 16.0) {
@@ -57,11 +57,9 @@ struct HomeScreenRoomCell: View {
@ViewBuilder @MainActor
private var avatar: some View {
if dynamicTypeSize < .accessibility3 {
LoadableAvatarImage(url: room.avatarURL,
name: room.name,
contentID: room.roomId,
avatarSize: .room(on: .home),
imageProvider: context.imageProvider)
RoomAvatarImage(avatar: room.avatar,
avatarSize: .room(on: .home),
imageProvider: context.imageProvider)
.dynamicTypeSize(dynamicTypeSize < .accessibility1 ? dynamicTypeSize : .accessibility1)
.accessibilityHidden(true)
}