mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Fix message details screen crash
This commit is contained in:
parent
2f6fe36907
commit
1b9d49e828
|
@ -235,84 +235,32 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
|
|||
// Recipient(s)
|
||||
if let outgoingMessage = message as? TSOutgoingMessage {
|
||||
|
||||
let isGroupThread = thread.isGroupThread()
|
||||
func getSeparator() -> UIView {
|
||||
let result = UIView()
|
||||
result.set(.height, to: Values.separatorThickness)
|
||||
result.backgroundColor = Colors.separator
|
||||
return result
|
||||
}
|
||||
|
||||
let recipientStatusGroups: [MessageReceiptStatus] = [
|
||||
.read,
|
||||
.uploading,
|
||||
.delivered,
|
||||
.sent,
|
||||
.sending,
|
||||
.failed,
|
||||
.skipped
|
||||
]
|
||||
for recipientStatusGroup in recipientStatusGroups {
|
||||
var groupRows = [UIView]()
|
||||
if !outgoingMessage.recipientIds().isEmpty {
|
||||
rows += [ getSeparator() ]
|
||||
}
|
||||
|
||||
// TODO: It'd be nice to inset these dividers from the edge of the screen.
|
||||
let addDivider = {
|
||||
let divider = UIView()
|
||||
divider.backgroundColor = Theme.hairlineColor
|
||||
divider.autoSetDimension(.height, toSize: CGHairlineWidth())
|
||||
groupRows.append(divider)
|
||||
}
|
||||
rows += outgoingMessage.recipientIds().flatMap { publicKey -> [UIView] in
|
||||
// We use ContactCellView, not ContactTableViewCell.
|
||||
// Table view cells don't layout properly outside the
|
||||
// context of a table view.
|
||||
let cellView = ContactCellView()
|
||||
cellView.configure(withRecipientId: publicKey)
|
||||
let wrapper = UIView()
|
||||
wrapper.layoutMargins = UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 20)
|
||||
wrapper.addSubview(cellView)
|
||||
cellView.autoPinEdgesToSuperviewMargins()
|
||||
return [ wrapper, getSeparator() ]
|
||||
}
|
||||
|
||||
let messageRecipientIds = outgoingMessage.recipientIds()
|
||||
|
||||
for recipientId in messageRecipientIds {
|
||||
guard let recipientState = outgoingMessage.recipientState(forRecipientId: recipientId) else {
|
||||
owsFailDebug("no message status for recipient: \(recipientId).")
|
||||
continue
|
||||
}
|
||||
|
||||
// We use the "short" status message to avoid being redundant with the section title.
|
||||
let (recipientStatus, shortStatusMessage, _) = MessageRecipientStatusUtils.recipientStatusAndStatusMessage(outgoingMessage: outgoingMessage, recipientState: recipientState)
|
||||
|
||||
guard recipientStatus == recipientStatusGroup else {
|
||||
continue
|
||||
}
|
||||
|
||||
if groupRows.count < 1 {
|
||||
if isGroupThread {
|
||||
groupRows.append(valueRow(name: string(for: recipientStatusGroup),
|
||||
value: ""))
|
||||
}
|
||||
|
||||
addDivider()
|
||||
}
|
||||
|
||||
// We use ContactCellView, not ContactTableViewCell.
|
||||
// Table view cells don't layout properly outside the
|
||||
// context of a table view.
|
||||
let cellView = ContactCellView()
|
||||
if self.shouldShowUD, recipientState.wasSentByUD {
|
||||
let udAccessoryView = self.buildUDAccessoryView(text: shortStatusMessage)
|
||||
cellView.setAccessory(udAccessoryView)
|
||||
} else {
|
||||
cellView.accessoryMessage = shortStatusMessage
|
||||
}
|
||||
cellView.configure(withRecipientId: recipientId)
|
||||
|
||||
let wrapper = UIView()
|
||||
wrapper.layoutMargins = UIEdgeInsets(top: 8, left: 20, bottom: 8, right: 20)
|
||||
wrapper.addSubview(cellView)
|
||||
cellView.autoPinEdgesToSuperviewMargins()
|
||||
groupRows.append(wrapper)
|
||||
}
|
||||
|
||||
if groupRows.count > 0 {
|
||||
addDivider()
|
||||
|
||||
let spacer = UIView()
|
||||
spacer.autoSetDimension(.height, toSize: 10)
|
||||
groupRows.append(spacer)
|
||||
}
|
||||
|
||||
Logger.verbose("\(groupRows.count) rows for \(recipientStatusGroup)")
|
||||
guard groupRows.count > 0 else {
|
||||
continue
|
||||
}
|
||||
rows += groupRows
|
||||
if !outgoingMessage.recipientIds().isEmpty {
|
||||
rows += [ UIView.vSpacer(10) ]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,15 @@ public final class ProfilePictureView : UIView {
|
|||
}
|
||||
|
||||
// MARK: Updating
|
||||
@objc(updateForContact:)
|
||||
public func update(for publicKey: String) {
|
||||
openGroupProfilePicture = nil
|
||||
hexEncodedPublicKey = publicKey
|
||||
additionalHexEncodedPublicKey = nil
|
||||
isRSSFeed = false
|
||||
update()
|
||||
}
|
||||
|
||||
@objc(updateForThread:)
|
||||
public func update(for thread: TSThread) {
|
||||
openGroupProfilePicture = nil
|
||||
|
@ -71,23 +80,21 @@ public final class ProfilePictureView : UIView {
|
|||
additionalHexEncodedPublicKey = randomUsers.count >= 2 ? randomUsers[1] : ""
|
||||
isRSSFeed = false
|
||||
}
|
||||
update()
|
||||
} else { // A one-to-one chat
|
||||
hexEncodedPublicKey = thread.contactIdentifier()!
|
||||
additionalHexEncodedPublicKey = nil
|
||||
isRSSFeed = false
|
||||
update(for: thread.contactIdentifier()!)
|
||||
}
|
||||
update()
|
||||
}
|
||||
|
||||
@objc public func update() {
|
||||
AssertIsOnMainThread()
|
||||
func getProfilePicture(of size: CGFloat, for hexEncodedPublicKey: String) -> UIImage? {
|
||||
guard !hexEncodedPublicKey.isEmpty else { return nil }
|
||||
if let profilePicture = OWSProfileManager.shared().profileAvatar(forRecipientId: hexEncodedPublicKey) {
|
||||
func getProfilePicture(of size: CGFloat, for publicKey: String) -> UIImage? {
|
||||
guard !publicKey.isEmpty else { return nil }
|
||||
if let profilePicture = OWSProfileManager.shared().profileAvatar(forRecipientId: publicKey) {
|
||||
return profilePicture
|
||||
} else {
|
||||
let displayName = OWSProfileManager.shared().profileNameForRecipient(withID: hexEncodedPublicKey) ?? hexEncodedPublicKey
|
||||
return Identicon.generatePlaceholderIcon(seed: hexEncodedPublicKey, text: displayName, size: size)
|
||||
let displayName = OWSProfileManager.shared().profileNameForRecipient(withID: publicKey) ?? publicKey
|
||||
return Identicon.generatePlaceholderIcon(seed: publicKey, text: displayName, size: size)
|
||||
}
|
||||
}
|
||||
let size: CGFloat
|
||||
|
|
|
@ -211,7 +211,11 @@ const CGFloat kContactCellAvatarTextMargin = 12;
|
|||
|
||||
- (void)updateAvatar
|
||||
{
|
||||
[self.profilePictureView updateForThread:self.thread];
|
||||
if (self.thread != nil) {
|
||||
[self.profilePictureView updateForThread:self.thread];
|
||||
} else {
|
||||
[self.profilePictureView updateForContact:self.recipientId];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateProfileName
|
||||
|
|
Loading…
Reference in a new issue