pr suggestions

This commit is contained in:
Mauro Romito
2025-03-20 19:33:17 +01:00
committed by Mauro
parent 9e0e5bbb13
commit 8e439bc8f5
11 changed files with 31 additions and 25 deletions
@@ -105,14 +105,14 @@ extension UNMutableNotificationContent {
forcePlaceholder: Bool = false) async throws -> UNMutableNotificationContent { forcePlaceholder: Bool = false) async throws -> UNMutableNotificationContent {
var fetchedImage: INImage? var fetchedImage: INImage?
let image: INImage let image: INImage
if !forcePlaceholder, let mediaSource = icon.mediaSource { if !forcePlaceholder,
switch await mediaProvider?.loadThumbnailForSource(source: mediaSource, size: .init(width: 100, height: 100)) { let mediaProvider,
let mediaSource = icon.mediaSource {
switch await mediaProvider.loadThumbnailForSource(source: mediaSource, size: .init(width: 100, height: 100)) {
case .success(let data): case .success(let data):
fetchedImage = INImage(imageData: data) fetchedImage = INImage(imageData: data)
case .failure(let error): case .failure(let error):
MXLog.error("Couldn't add sender icon: \(error)") MXLog.error("Couldn't add sender icon: \(error)")
case .none:
break
} }
} }
@@ -13,6 +13,15 @@ enum RoomAvatar: Equatable {
case room(id: String, name: String?, avatarURL: URL?) case room(id: String, name: String?, avatarURL: URL?)
/// An avatar generated from the room's heroes. /// An avatar generated from the room's heroes.
case heroes([UserProfileProxy]) case heroes([UserProfileProxy])
var removingAvatar: RoomAvatar {
switch self {
case let .room(id, name, _):
return .room(id: id, name: name, avatarURL: nil)
case let .heroes(users):
return .heroes(users.map { .init(userID: $0.userID, displayName: $0.displayName, avatarURL: nil) })
}
}
} }
/// A view that shows the avatar for a room, or a cluster of heroes if provided. /// A view that shows the avatar for a room, or a cluster of heroes if provided.
+1 -1
View File
@@ -30,7 +30,7 @@ final class UserPreference<T: Codable> {
/// - key: The key used to store and retrieve the value. /// - key: The key used to store and retrieve the value.
/// - defaultValue: The default value to use if no stored value exists or if `forceDefault` is `true`. /// - defaultValue: The default value to use if no stored value exists or if `forceDefault` is `true`.
/// - keyedStorage: The storage instance where the value is saved. /// - keyedStorage: The storage instance where the value is saved.
/// - forceDefault: A publisher that determines whether the default value should always be used. Defaults to publish`false`. Useful in the context of MDM settings. /// - forceDefault: A publisher that determines whether the default value should always be used. Defaults to publish `false`. Useful in the context of remote settings.
init(key: String, init(key: String,
defaultValue: @autoclosure @escaping () -> T, defaultValue: @autoclosure @escaping () -> T,
keyedStorage: any KeyedStorage<T>, keyedStorage: any KeyedStorage<T>,
@@ -18,7 +18,7 @@ struct HomeScreenInviteCell: View {
let hideInviteAvatars: Bool let hideInviteAvatars: Bool
private var avatar: RoomAvatar { private var avatar: RoomAvatar {
hideInviteAvatars ? .room(id: room.id, name: room.name, avatarURL: nil) : room.avatar hideInviteAvatars ? room.avatar.removingAvatar : room.avatar
} }
var body: some View { var body: some View {
@@ -156,7 +156,7 @@ struct HomeScreenInviteCell_Previews: PreviewProvider, TestablePreview {
HomeScreenInviteCell(room: .roomInvite(alias: "#footest:somewhere.org", avatarURL: .mockMXCAvatar), HomeScreenInviteCell(room: .roomInvite(alias: "#footest:somewhere.org", avatarURL: .mockMXCAvatar),
context: viewModel().context, hideInviteAvatars: false) context: viewModel().context, hideInviteAvatars: false)
HomeScreenInviteCell(room: .roomInvite(alias: "#footest:somewhere.org", avatarURL: .mockMXCAvatar), HomeScreenInviteCell(room: .roomInvite(alias: "#footest-hidden-avatars:somewhere.org", avatarURL: .mockMXCAvatar),
context: viewModel(hideInviteAvatars: true).context, hideInviteAvatars: true) context: viewModel(hideInviteAvatars: true).context, hideInviteAvatars: true)
HomeScreenInviteCell(room: .roomInvite(alias: "#footest:somewhere.org"), HomeScreenInviteCell(room: .roomInvite(alias: "#footest:somewhere.org"),
context: viewModel().context, hideInviteAvatars: false) context: viewModel().context, hideInviteAvatars: false)
@@ -82,10 +82,11 @@ struct JoinRoomScreenViewState: BindableState {
} }
var avatar: RoomAvatar? { var avatar: RoomAvatar? {
// DM invites avatars are broken, this is a workaround
if isDMInvite, let inviter = roomDetails?.inviter { if isDMInvite, let inviter = roomDetails?.inviter {
return .room(id: roomID, name: inviter.displayName, avatarURL: hideInviteAvatars ? nil : inviter.avatarURL) return .room(id: roomID, name: inviter.displayName, avatarURL: hideInviteAvatars ? nil : inviter.avatarURL)
} else if let roomDetails, let avatar = roomDetails.avatar { } else if let roomDetails, let avatar = roomDetails.avatar {
return shouldHideAvatars ? .room(id: roomID, name: roomDetails.name, avatarURL: nil) : avatar return shouldHideAvatars ? avatar.removingAvatar : avatar
} else if let name = roomDetails?.name { } else if let name = roomDetails?.name {
return .room(id: roomID, name: name, avatarURL: nil) return .room(id: roomID, name: name, avatarURL: nil)
} else { } else {
@@ -33,10 +33,8 @@ struct RoomInfoProxy: BaseRoomInfoProxyProtocol {
var avatarURL: URL? { roomInfo.avatarUrl.flatMap(URL.init) } var avatarURL: URL? { roomInfo.avatarUrl.flatMap(URL.init) }
/// The room's avatar info for use in a ``RoomAvatarImage``. /// The room's avatar info for use in a ``RoomAvatarImage``.
var avatar: RoomAvatar { var avatar: RoomAvatar {
if isDirect, avatarURL == nil { if isDirect, avatarURL == nil, heroes.count == 1 {
if heroes.count == 1 { return .heroes(heroes.map(UserProfileProxy.init))
return .heroes(heroes.map(UserProfileProxy.init))
}
} }
return .room(id: id, name: displayName, avatarURL: avatarURL) return .room(id: id, name: displayName, avatarURL: avatarURL)
@@ -127,12 +125,9 @@ struct RoomPreviewInfoProxy: BaseRoomInfoProxyProtocol {
/// The room's avatar info for use in a ``RoomAvatarImage``. /// The room's avatar info for use in a ``RoomAvatarImage``.
var avatar: RoomAvatar { var avatar: RoomAvatar {
if isDirect, avatarURL == nil { if isDirect, avatarURL == nil, heroes.count == 1 {
if heroes.count == 1 { return .heroes(heroes.map(UserProfileProxy.init))
return .heroes(heroes.map(UserProfileProxy.init))
}
} }
return .room(id: id, name: displayName, avatarURL: avatarURL) return .room(id: id, name: displayName, avatarURL: avatarURL)
} }
} }
@@ -109,6 +109,7 @@ extension RoomSummary {
isFavourite = false isFavourite = false
} }
// This doesn't have to work properly for DM invites, the heroes are always empty
var avatar: RoomAvatar { var avatar: RoomAvatar {
if isDirect, avatarURL == nil, heroes.count == 1 { if isDirect, avatarURL == nil, heroes.count == 1 {
.heroes(heroes) .heroes(heroes)
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:3d675d9e609a6c653409fd340cb93307ea2a06d1f3603d4bac8cd5f48b47db7b oid sha256:a2afcba709e9e534cdd62168d6957db70cef57703a6033c0bdc8bb1ff491e974
size 312144 size 317756
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:3e55fbb94a46655b7ca88aef7dd71c88447de3383c695b5b35169c3480045a7d oid sha256:d38436f84b344252e929f15075a5219260b5454c223c77fb1f41c88322adda02
size 331760 size 337324
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:4f75c56f0788459cf6e26aed0c3cab9f05265b27e5e3a751221bb0c70c6e04ab oid sha256:2994fc2ce1f3a12e0b1fd60c27f7649de7e69027d4c57f941211f6e268344fd3
size 251916 size 259148
@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:5c434f5efdb18dd5cb3158342736a076286583e05dc9c6348e9256573a1c03a2 oid sha256:7b07fc5ed7e4355332558a45b7117b3825e3d61bf9a6cde9c38e967e0bfd78d1
size 333485 size 341431