Skip to content
Snippets Groups Projects
Commit 8e439bc8 authored by Mauro Romito's avatar Mauro Romito Committed by Mauro
Browse files

pr suggestions

parent 9e0e5bbb
No related branches found
No related tags found
No related merge requests found
Showing
with 31 additions and 25 deletions
...@@ -105,14 +105,14 @@ extension UNMutableNotificationContent { ...@@ -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 { ...@@ -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.
......
...@@ -30,7 +30,7 @@ final class UserPreference<T: Codable> { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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)
......
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-en-GB-0.png

131 B | W: | H:

PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-en-GB-0.png

131 B | W: | H:

PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-en-GB-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-en-GB-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-en-GB-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-en-GB-0.png
  • 2-up
  • Swipe
  • Onion skin
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-pseudo-0.png

131 B | W: | H:

PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-pseudo-0.png

131 B | W: | H:

PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-pseudo-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-pseudo-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-pseudo-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPad-pseudo-0.png
  • 2-up
  • Swipe
  • Onion skin
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-en-GB-0.png

131 B | W: | H:

PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-en-GB-0.png

131 B | W: | H:

PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-en-GB-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-en-GB-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-en-GB-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-en-GB-0.png
  • 2-up
  • Swipe
  • Onion skin
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-pseudo-0.png

131 B | W: | H:

PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-pseudo-0.png

131 B | W: | H:

PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-pseudo-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-pseudo-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-pseudo-0.png
PreviewTests/Sources/__Snapshots__/PreviewTests/homeScreenInviteCell.iPhone-16-pseudo-0.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment