diff --git a/ElementX/Sources/Other/Extensions/UNNotificationContent.swift b/ElementX/Sources/Other/Extensions/UNNotificationContent.swift index 3833ce03a4927f464d21db19ef11036f7d0ac934..a15be70283323f28508776d82e4b5944df7c82ab 100644 --- a/ElementX/Sources/Other/Extensions/UNNotificationContent.swift +++ b/ElementX/Sources/Other/Extensions/UNNotificationContent.swift @@ -105,14 +105,14 @@ extension UNMutableNotificationContent { forcePlaceholder: Bool = false) async throws -> UNMutableNotificationContent { var fetchedImage: INImage? let image: INImage - if !forcePlaceholder, let mediaSource = icon.mediaSource { - switch await mediaProvider?.loadThumbnailForSource(source: mediaSource, size: .init(width: 100, height: 100)) { + if !forcePlaceholder, + let mediaProvider, + let mediaSource = icon.mediaSource { + switch await mediaProvider.loadThumbnailForSource(source: mediaSource, size: .init(width: 100, height: 100)) { case .success(let data): fetchedImage = INImage(imageData: data) case .failure(let error): MXLog.error("Couldn't add sender icon: \(error)") - case .none: - break } } diff --git a/ElementX/Sources/Other/SwiftUI/Views/RoomAvatarImage.swift b/ElementX/Sources/Other/SwiftUI/Views/RoomAvatarImage.swift index 3c53e967fa450aafd0edac15f06e78fbd0dddc31..6be9d20df124f7e7b1d860143999b27d5a5ae3d5 100644 --- a/ElementX/Sources/Other/SwiftUI/Views/RoomAvatarImage.swift +++ b/ElementX/Sources/Other/SwiftUI/Views/RoomAvatarImage.swift @@ -13,6 +13,15 @@ enum RoomAvatar: Equatable { case room(id: String, name: String?, avatarURL: URL?) /// An avatar generated from the room's heroes. 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. diff --git a/ElementX/Sources/Other/UserPreference.swift b/ElementX/Sources/Other/UserPreference.swift index d3881c9d27f3f7b5b2bdf399105aa6cb96b76583..11d4e1a5bdf0c5e7fd88c073187631c544225ddf 100644 --- a/ElementX/Sources/Other/UserPreference.swift +++ b/ElementX/Sources/Other/UserPreference.swift @@ -30,7 +30,7 @@ final class UserPreference<T: Codable> { /// - 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`. /// - 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, defaultValue: @autoclosure @escaping () -> T, keyedStorage: any KeyedStorage<T>, diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift index c16aab145995dbfc92aa0f5f21220c4e04503a3b..ee83be2c2e6adb0af9d668cb97299cc2b17b4572 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenInviteCell.swift @@ -18,7 +18,7 @@ struct HomeScreenInviteCell: View { let hideInviteAvatars: Bool 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 { @@ -156,7 +156,7 @@ struct HomeScreenInviteCell_Previews: PreviewProvider, TestablePreview { HomeScreenInviteCell(room: .roomInvite(alias: "#footest:somewhere.org", avatarURL: .mockMXCAvatar), 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) HomeScreenInviteCell(room: .roomInvite(alias: "#footest:somewhere.org"), context: viewModel().context, hideInviteAvatars: false) diff --git a/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenModels.swift b/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenModels.swift index 9c3d1777f0079ed3e449bdfd34f90f9e148d6c98..dca41ca9b53bb04e48bfcd8b1f0ae970079a11bb 100644 --- a/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenModels.swift +++ b/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenModels.swift @@ -82,10 +82,11 @@ struct JoinRoomScreenViewState: BindableState { } var avatar: RoomAvatar? { + // DM invites avatars are broken, this is a workaround if isDMInvite, let inviter = roomDetails?.inviter { return .room(id: roomID, name: inviter.displayName, avatarURL: hideInviteAvatars ? nil : inviter.avatarURL) } 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 { return .room(id: roomID, name: name, avatarURL: nil) } else { diff --git a/ElementX/Sources/Services/Room/RoomInfoProxy.swift b/ElementX/Sources/Services/Room/RoomInfoProxy.swift index 8254820d542d8d2b713f30ff2d09462025414b47..89fb1e93569185892e2098ef37d6ff64a0bfd801 100644 --- a/ElementX/Sources/Services/Room/RoomInfoProxy.swift +++ b/ElementX/Sources/Services/Room/RoomInfoProxy.swift @@ -33,10 +33,8 @@ struct RoomInfoProxy: BaseRoomInfoProxyProtocol { var avatarURL: URL? { roomInfo.avatarUrl.flatMap(URL.init) } /// The room's avatar info for use in a ``RoomAvatarImage``. var avatar: RoomAvatar { - if isDirect, avatarURL == nil { - if heroes.count == 1 { - return .heroes(heroes.map(UserProfileProxy.init)) - } + if isDirect, avatarURL == nil, heroes.count == 1 { + return .heroes(heroes.map(UserProfileProxy.init)) } 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``. var avatar: RoomAvatar { - if isDirect, avatarURL == nil { - if heroes.count == 1 { - return .heroes(heroes.map(UserProfileProxy.init)) - } + if isDirect, avatarURL == nil, heroes.count == 1 { + return .heroes(heroes.map(UserProfileProxy.init)) } - return .room(id: id, name: displayName, avatarURL: avatarURL) } } diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift index e4453b0e12c901ffcf29ba88057382488e8bddc9..0baa9a16f3ddac09fae44bbe30de02ffdf223bcb 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummary.swift @@ -109,6 +109,7 @@ extension RoomSummary { isFavourite = false } + // This doesn't have to work properly for DM invites, the heroes are always empty var avatar: RoomAvatar { if isDirect, avatarURL == nil, heroes.count == 1 { .heroes(heroes) diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-en-GB-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-en-GB-0.png index e2ddf921d322ace02c537beb36ec055bf80d0cbc..e3445c409b0dbca987974f2c255fb41102494682 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-en-GB-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-en-GB-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3d675d9e609a6c653409fd340cb93307ea2a06d1f3603d4bac8cd5f48b47db7b -size 312144 +oid sha256:a2afcba709e9e534cdd62168d6957db70cef57703a6033c0bdc8bb1ff491e974 +size 317756 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-pseudo-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-pseudo-0.png index 50fc99a3875eb581b3ccbc63489d89832c7c99b1..60975ed4ed50751e4d486e33367d8d86cf8d64b0 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-pseudo-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-pseudo-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3e55fbb94a46655b7ca88aef7dd71c88447de3383c695b5b35169c3480045a7d -size 331760 +oid sha256:d38436f84b344252e929f15075a5219260b5454c223c77fb1f41c88322adda02 +size 337324 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-en-GB-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-en-GB-0.png index dc0200727dcd520d98d12404396543eb90021f16..a40b4d6872c80c478407301556788065d4e5bfca 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-en-GB-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-en-GB-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4f75c56f0788459cf6e26aed0c3cab9f05265b27e5e3a751221bb0c70c6e04ab -size 251916 +oid sha256:2994fc2ce1f3a12e0b1fd60c27f7649de7e69027d4c57f941211f6e268344fd3 +size 259148 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-pseudo-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-pseudo-0.png index abc25a406b99618fe029ced01bd1d92cf7750d89..72cf9afc30376555900e1180b3268fa1d2e3917f 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-pseudo-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-pseudo-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5c434f5efdb18dd5cb3158342736a076286583e05dc9c6348e9256573a1c03a2 -size 333485 +oid sha256:7b07fc5ed7e4355332558a45b7117b3825e3d61bf9a6cde9c38e967e0bfd78d1 +size 341431