|
|
@ -3,6 +3,8 @@
|
|
|
|
public final class ProfilePictureView : UIView {
|
|
|
|
public final class ProfilePictureView : UIView {
|
|
|
|
private var imageViewWidthConstraint: NSLayoutConstraint!
|
|
|
|
private var imageViewWidthConstraint: NSLayoutConstraint!
|
|
|
|
private var imageViewHeightConstraint: NSLayoutConstraint!
|
|
|
|
private var imageViewHeightConstraint: NSLayoutConstraint!
|
|
|
|
|
|
|
|
private var additionalImageViewWidthConstraint: NSLayoutConstraint!
|
|
|
|
|
|
|
|
private var additionalImageViewHeightConstraint: NSLayoutConstraint!
|
|
|
|
@objc public var size: CGFloat = 0 // Not an implicitly unwrapped optional due to Obj-C limitations
|
|
|
|
@objc public var size: CGFloat = 0 // Not an implicitly unwrapped optional due to Obj-C limitations
|
|
|
|
@objc public var isRSSFeed = false
|
|
|
|
@objc public var isRSSFeed = false
|
|
|
|
@objc public var hexEncodedPublicKey: String!
|
|
|
|
@objc public var hexEncodedPublicKey: String!
|
|
|
@ -37,8 +39,8 @@ public final class ProfilePictureView : UIView {
|
|
|
|
additionalImageView.pin(.trailing, to: .trailing, of: self)
|
|
|
|
additionalImageView.pin(.trailing, to: .trailing, of: self)
|
|
|
|
additionalImageView.pin(.bottom, to: .bottom, of: self)
|
|
|
|
additionalImageView.pin(.bottom, to: .bottom, of: self)
|
|
|
|
let additionalImageViewSize = CGFloat(Values.smallProfilePictureSize)
|
|
|
|
let additionalImageViewSize = CGFloat(Values.smallProfilePictureSize)
|
|
|
|
additionalImageView.set(.width, to: additionalImageViewSize)
|
|
|
|
additionalImageViewWidthConstraint = additionalImageView.set(.width, to: additionalImageViewSize)
|
|
|
|
additionalImageView.set(.height, to: additionalImageViewSize)
|
|
|
|
additionalImageViewHeightConstraint = additionalImageView.set(.height, to: additionalImageViewSize)
|
|
|
|
additionalImageView.layer.cornerRadius = additionalImageViewSize / 2
|
|
|
|
additionalImageView.layer.cornerRadius = additionalImageViewSize / 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -46,16 +48,16 @@ public final class ProfilePictureView : UIView {
|
|
|
|
@objc(updateForThread:)
|
|
|
|
@objc(updateForThread:)
|
|
|
|
public func update(for thread: TSThread) {
|
|
|
|
public func update(for thread: TSThread) {
|
|
|
|
openGroupProfilePicture = nil
|
|
|
|
openGroupProfilePicture = nil
|
|
|
|
if thread.isGroupThread() {
|
|
|
|
if let thread = thread as? TSGroupThread {
|
|
|
|
if thread.name() == "Loki Public Chat"
|
|
|
|
if thread.name() == "Loki Public Chat"
|
|
|
|
|| thread.name() == "Session Public Chat" { // Override the profile picture for the Loki Public Chat and the Session Public Chat
|
|
|
|
|| thread.name() == "Session Public Chat" { // Override the profile picture for the Loki Public Chat and the Session Public Chat
|
|
|
|
hexEncodedPublicKey = ""
|
|
|
|
hexEncodedPublicKey = ""
|
|
|
|
isRSSFeed = true
|
|
|
|
isRSSFeed = true
|
|
|
|
} else if let openGroupProfilePicture = (thread as! TSGroupThread).groupModel.groupImage { // An open group with a profile picture
|
|
|
|
} else if let openGroupProfilePicture = thread.groupModel.groupImage { // An open group with a profile picture
|
|
|
|
self.openGroupProfilePicture = openGroupProfilePicture
|
|
|
|
self.openGroupProfilePicture = openGroupProfilePicture
|
|
|
|
isRSSFeed = false
|
|
|
|
isRSSFeed = false
|
|
|
|
} else if (thread as! TSGroupThread).groupModel.groupType == .openGroup
|
|
|
|
} else if thread.groupModel.groupType == .openGroup
|
|
|
|
|| (thread as! TSGroupThread).groupModel.groupType == .rssFeed { // An open group without a profile picture or an RSS feed
|
|
|
|
|| thread.groupModel.groupType == .rssFeed { // An open group without a profile picture or an RSS feed
|
|
|
|
hexEncodedPublicKey = ""
|
|
|
|
hexEncodedPublicKey = ""
|
|
|
|
isRSSFeed = true
|
|
|
|
isRSSFeed = true
|
|
|
|
} else { // A closed group
|
|
|
|
} else { // A closed group
|
|
|
@ -66,7 +68,7 @@ public final class ProfilePictureView : UIView {
|
|
|
|
additionalHexEncodedPublicKey = randomUsers.count >= 2 ? randomUsers[1] : ""
|
|
|
|
additionalHexEncodedPublicKey = randomUsers.count >= 2 ? randomUsers[1] : ""
|
|
|
|
isRSSFeed = false
|
|
|
|
isRSSFeed = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { // A one-on-one chat
|
|
|
|
} else { // A one-to-one chat
|
|
|
|
hexEncodedPublicKey = thread.contactIdentifier()!
|
|
|
|
hexEncodedPublicKey = thread.contactIdentifier()!
|
|
|
|
additionalHexEncodedPublicKey = nil
|
|
|
|
additionalHexEncodedPublicKey = nil
|
|
|
|
isRSSFeed = false
|
|
|
|
isRSSFeed = false
|
|
|
@ -78,13 +80,26 @@ public final class ProfilePictureView : UIView {
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
func getProfilePicture(of size: CGFloat, for hexEncodedPublicKey: String) -> UIImage? {
|
|
|
|
func getProfilePicture(of size: CGFloat, for hexEncodedPublicKey: String) -> UIImage? {
|
|
|
|
guard !hexEncodedPublicKey.isEmpty else { return nil }
|
|
|
|
guard !hexEncodedPublicKey.isEmpty else { return nil }
|
|
|
|
return OWSProfileManager.shared().profileAvatar(forRecipientId: hexEncodedPublicKey) ?? Identicon.generatePlaceholderIcon(seed: hexEncodedPublicKey, text: OWSProfileManager.shared().profileNameForRecipient(withID: hexEncodedPublicKey) ?? hexEncodedPublicKey, size: size)
|
|
|
|
if let profilePicture = OWSProfileManager.shared().profileAvatar(forRecipientId: hexEncodedPublicKey) {
|
|
|
|
|
|
|
|
return profilePicture
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let displayName = OWSProfileManager.shared().profileNameForRecipient(withID: hexEncodedPublicKey) ?? hexEncodedPublicKey
|
|
|
|
|
|
|
|
return Identicon.generatePlaceholderIcon(seed: hexEncodedPublicKey, text: displayName, size: size)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let size: CGFloat
|
|
|
|
let size: CGFloat
|
|
|
|
if let additionalHexEncodedPublicKey = additionalHexEncodedPublicKey, !isRSSFeed, openGroupProfilePicture == nil {
|
|
|
|
if let additionalHexEncodedPublicKey = additionalHexEncodedPublicKey, !isRSSFeed, openGroupProfilePicture == nil {
|
|
|
|
size = Values.smallProfilePictureSize
|
|
|
|
if self.size == 40 {
|
|
|
|
|
|
|
|
size = 32
|
|
|
|
|
|
|
|
} else if self.size == Values.largeProfilePictureSize {
|
|
|
|
|
|
|
|
size = 56
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
size = Values.smallProfilePictureSize
|
|
|
|
|
|
|
|
}
|
|
|
|
imageViewWidthConstraint.constant = size
|
|
|
|
imageViewWidthConstraint.constant = size
|
|
|
|
imageViewHeightConstraint.constant = size
|
|
|
|
imageViewHeightConstraint.constant = size
|
|
|
|
|
|
|
|
additionalImageViewWidthConstraint.constant = size
|
|
|
|
|
|
|
|
additionalImageViewHeightConstraint.constant = size
|
|
|
|
additionalImageView.isHidden = false
|
|
|
|
additionalImageView.isHidden = false
|
|
|
|
additionalImageView.image = getProfilePicture(of: size, for: additionalHexEncodedPublicKey)
|
|
|
|
additionalImageView.image = getProfilePicture(of: size, for: additionalHexEncodedPublicKey)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -98,9 +113,14 @@ public final class ProfilePictureView : UIView {
|
|
|
|
imageView.image = isRSSFeed ? nil : (openGroupProfilePicture ?? getProfilePicture(of: size, for: hexEncodedPublicKey))
|
|
|
|
imageView.image = isRSSFeed ? nil : (openGroupProfilePicture ?? getProfilePicture(of: size, for: hexEncodedPublicKey))
|
|
|
|
imageView.backgroundColor = isRSSFeed ? UIColor(rgbHex: 0x353535) : Colors.unimportant
|
|
|
|
imageView.backgroundColor = isRSSFeed ? UIColor(rgbHex: 0x353535) : Colors.unimportant
|
|
|
|
imageView.layer.cornerRadius = size / 2
|
|
|
|
imageView.layer.cornerRadius = size / 2
|
|
|
|
|
|
|
|
additionalImageView.layer.cornerRadius = size / 2
|
|
|
|
imageView.contentMode = isRSSFeed ? .center : .scaleAspectFit
|
|
|
|
imageView.contentMode = isRSSFeed ? .center : .scaleAspectFit
|
|
|
|
if isRSSFeed {
|
|
|
|
if isRSSFeed {
|
|
|
|
imageView.image = (size == 45) ? #imageLiteral(resourceName: "SessionWhite24") : #imageLiteral(resourceName: "SessionWhite40")
|
|
|
|
switch size {
|
|
|
|
|
|
|
|
case Values.smallProfilePictureSize..<Values.mediumProfilePictureSize: imageView.image = #imageLiteral(resourceName: "SessionWhite16")
|
|
|
|
|
|
|
|
case Values.mediumProfilePictureSize..<Values.largeProfilePictureSize: imageView.image = #imageLiteral(resourceName: "SessionWhite24")
|
|
|
|
|
|
|
|
default: imageView.image = #imageLiteral(resourceName: "SessionWhite40")
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|