mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
4.8 KiB
Swift
116 lines
4.8 KiB
Swift
2 years ago
|
// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
|
||
|
|
||
|
import Foundation
|
||
|
import SessionUIKit
|
||
|
|
||
|
public extension ProfilePictureView {
|
||
|
func update(
|
||
|
publicKey: String,
|
||
|
threadVariant: SessionThread.Variant,
|
||
|
customImageData: Data?,
|
||
|
profile: Profile?,
|
||
2 years ago
|
profileIcon: ProfileIcon = .none,
|
||
|
additionalProfile: Profile? = nil,
|
||
|
additionalProfileIcon: ProfileIcon = .none
|
||
2 years ago
|
) {
|
||
|
// If we are given 'customImageData' then only use that
|
||
|
guard customImageData == nil else { return update(Info(imageData: customImageData)) }
|
||
|
|
||
|
// Otherwise there are conversation-type-specific behaviours
|
||
|
switch threadVariant {
|
||
2 years ago
|
case .community:
|
||
2 years ago
|
let placeholderImage: UIImage = {
|
||
|
switch self.size {
|
||
|
case .navigation, .message: return #imageLiteral(resourceName: "SessionWhite16")
|
||
|
case .list: return #imageLiteral(resourceName: "SessionWhite24")
|
||
|
case .hero: return #imageLiteral(resourceName: "SessionWhite40")
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
update(
|
||
|
Info(
|
||
|
imageData: placeholderImage.pngData(),
|
||
|
inset: UIEdgeInsets(
|
||
|
top: 12,
|
||
|
left: 12,
|
||
|
bottom: 12,
|
||
|
right: 12
|
||
|
),
|
||
2 years ago
|
icon: profileIcon,
|
||
2 years ago
|
forcedBackgroundColor: .theme(.classicDark, color: .borderSeparator)
|
||
|
)
|
||
|
)
|
||
|
|
||
2 years ago
|
case .legacyGroup, .group:
|
||
2 years ago
|
guard !publicKey.isEmpty else { return }
|
||
2 years ago
|
|
||
2 years ago
|
update(
|
||
|
Info(
|
||
|
imageData: (
|
||
|
profile.map { ProfileManager.profileAvatar(profile: $0) } ??
|
||
|
PlaceholderIcon.generate(
|
||
|
seed: publicKey,
|
||
|
text: (profile?.displayName(for: threadVariant))
|
||
|
.defaulting(to: publicKey),
|
||
|
size: (additionalProfile != nil ?
|
||
|
self.size.multiImageSize :
|
||
|
self.size.viewSize
|
||
|
)
|
||
|
).pngData()
|
||
2 years ago
|
),
|
||
|
icon: profileIcon
|
||
2 years ago
|
),
|
||
|
additionalInfo: additionalProfile
|
||
|
.map { otherProfile in
|
||
|
Info(
|
||
|
imageData: (
|
||
|
ProfileManager.profileAvatar(profile: otherProfile) ??
|
||
|
PlaceholderIcon.generate(
|
||
|
seed: otherProfile.id,
|
||
|
text: otherProfile.displayName(for: threadVariant),
|
||
|
size: self.size.multiImageSize
|
||
|
).pngData()
|
||
2 years ago
|
),
|
||
|
icon: additionalProfileIcon
|
||
2 years ago
|
)
|
||
|
}
|
||
|
.defaulting(
|
||
|
to: Info(
|
||
|
imageData: UIImage(systemName: "person.fill")?.pngData(),
|
||
|
renderingMode: .alwaysTemplate,
|
||
|
themeTintColor: .white,
|
||
|
inset: UIEdgeInsets(
|
||
|
top: 3,
|
||
|
left: 0,
|
||
|
bottom: -5,
|
||
|
right: 0
|
||
2 years ago
|
),
|
||
|
icon: additionalProfileIcon
|
||
2 years ago
|
)
|
||
|
)
|
||
|
)
|
||
|
|
||
|
case .contact:
|
||
|
guard !publicKey.isEmpty else { return }
|
||
|
|
||
|
update(
|
||
|
Info(
|
||
|
imageData: (
|
||
|
profile.map { ProfileManager.profileAvatar(profile: $0) } ??
|
||
|
PlaceholderIcon.generate(
|
||
|
seed: publicKey,
|
||
|
text: (profile?.displayName(for: threadVariant))
|
||
|
.defaulting(to: publicKey),
|
||
|
size: (additionalProfile != nil ?
|
||
|
self.size.multiImageSize :
|
||
|
self.size.viewSize
|
||
|
)
|
||
|
).pngData()
|
||
2 years ago
|
),
|
||
|
icon: profileIcon
|
||
2 years ago
|
)
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
}
|