From 1b9d49e828712281dc48e96c7f7c1fe544ec1ac4 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Fri, 2 Oct 2020 09:03:06 +1000 Subject: [PATCH] Fix message details screen crash --- .../MessageDetailViewController.swift | 98 +++++-------------- .../Components/ProfilePictureView.swift | 25 +++-- SignalMessaging/Views/ContactCellView.m | 6 +- 3 files changed, 44 insertions(+), 85 deletions(-) diff --git a/Signal/src/ViewControllers/MessageDetailViewController.swift b/Signal/src/ViewControllers/MessageDetailViewController.swift index 293ba46ba..168bac7b2 100644 --- a/Signal/src/ViewControllers/MessageDetailViewController.swift +++ b/Signal/src/ViewControllers/MessageDetailViewController.swift @@ -235,84 +235,32 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele // Recipient(s) if let outgoingMessage = message as? TSOutgoingMessage { - let isGroupThread = thread.isGroupThread() - - let recipientStatusGroups: [MessageReceiptStatus] = [ - .read, - .uploading, - .delivered, - .sent, - .sending, - .failed, - .skipped - ] - for recipientStatusGroup in recipientStatusGroups { - var groupRows = [UIView]() - - // 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) - } - - 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) - } + func getSeparator() -> UIView { + let result = UIView() + result.set(.height, to: Values.separatorThickness) + result.backgroundColor = Colors.separator + return result + } - if groupRows.count > 0 { - addDivider() + if !outgoingMessage.recipientIds().isEmpty { + rows += [ getSeparator() ] + } - let spacer = UIView() - spacer.autoSetDimension(.height, toSize: 10) - groupRows.append(spacer) - } + 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() ] + } - Logger.verbose("\(groupRows.count) rows for \(recipientStatusGroup)") - guard groupRows.count > 0 else { - continue - } - rows += groupRows + if !outgoingMessage.recipientIds().isEmpty { + rows += [ UIView.vSpacer(10) ] } } diff --git a/SignalMessaging/Loki/Redesign/Components/ProfilePictureView.swift b/SignalMessaging/Loki/Redesign/Components/ProfilePictureView.swift index 1192e05fb..91d3596c9 100644 --- a/SignalMessaging/Loki/Redesign/Components/ProfilePictureView.swift +++ b/SignalMessaging/Loki/Redesign/Components/ProfilePictureView.swift @@ -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 diff --git a/SignalMessaging/Views/ContactCellView.m b/SignalMessaging/Views/ContactCellView.m index f3d04abec..179d7a079 100644 --- a/SignalMessaging/Views/ContactCellView.m +++ b/SignalMessaging/Views/ContactCellView.m @@ -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