From 6460493669c198e578fe36537963a6e388d40c7d Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 10 May 2018 11:50:13 -0400 Subject: [PATCH] Surface organization name in contact view. --- .../ContactViewController.swift | 8 ++++++++ .../attachments/ContactFieldView.swift | 6 ++++++ .../src/Messages/Interactions/OWSContact.h | 7 +++++++ .../src/Messages/Interactions/OWSContact.m | 19 +++++++++++++------ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Signal/src/ViewControllers/ContactViewController.swift b/Signal/src/ViewControllers/ContactViewController.swift index df50db5ab..f820c0ac6 100644 --- a/Signal/src/ViewControllers/ContactViewController.swift +++ b/Signal/src/ViewControllers/ContactViewController.swift @@ -355,6 +355,14 @@ class ContactViewController: OWSViewController, ContactShareViewHelperDelegate { // action:#selector(didPressShareContact))) // } + if let organizationName = contactShare.name.organizationName?.ows_stripped() { + if (contactShare.name.hasAnyNamePart() && + organizationName.count > 0) { + rows.append(ContactFieldView.contactFieldView(forOrganizationName: organizationName, + layoutMargins: UIEdgeInsets(top: 5, left: hMargin, bottom: 5, right: hMargin))) + } + } + for phoneNumber in contactShare.phoneNumbers { rows.append(ContactFieldView.contactFieldView(forPhoneNumber: phoneNumber, layoutMargins: UIEdgeInsets(top: 5, left: hMargin, bottom: 5, right: hMargin), diff --git a/SignalMessaging/attachments/ContactFieldView.swift b/SignalMessaging/attachments/ContactFieldView.swift index 0a64b0f63..68bd2d7de 100644 --- a/SignalMessaging/attachments/ContactFieldView.swift +++ b/SignalMessaging/attachments/ContactFieldView.swift @@ -61,6 +61,12 @@ public class ContactFieldView: UIView { lastRow?.autoPinEdge(toSuperviewEdge: .bottom, withInset: 0) } + public class func contactFieldView(forOrganizationName organizationName: String, layoutMargins: UIEdgeInsets) -> UIView { + return simpleFieldView(name: NSLocalizedString("CONTACT_FIELD_ORGANIZATION_NAME", comment: "Label for the 'organization name' field of a contact."), + value: organizationName, + layoutMargins: layoutMargins, actionBlock: nil) + } + public class func contactFieldView(forPhoneNumber phoneNumber: OWSContactPhoneNumber, layoutMargins: UIEdgeInsets, actionBlock : (() -> Void)?) -> UIView { let formattedPhoneNumber = PhoneNumber.bestEffortLocalizedPhoneNumber(withE164: phoneNumber.phoneNumber) return simpleFieldView(name: phoneNumber.localizedLabel(), value: formattedPhoneNumber, layoutMargins: layoutMargins, actionBlock: actionBlock) diff --git a/SignalServiceKit/src/Messages/Interactions/OWSContact.h b/SignalServiceKit/src/Messages/Interactions/OWSContact.h index 98621b341..1a7856afe 100644 --- a/SignalServiceKit/src/Messages/Interactions/OWSContact.h +++ b/SignalServiceKit/src/Messages/Interactions/OWSContact.h @@ -103,14 +103,21 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value); @interface OWSContactName : MTLModel +// The "name parts". @property (nonatomic, nullable) NSString *givenName; @property (nonatomic, nullable) NSString *familyName; @property (nonatomic, nullable) NSString *nameSuffix; @property (nonatomic, nullable) NSString *namePrefix; @property (nonatomic, nullable) NSString *middleName; + @property (nonatomic, nullable) NSString *organizationName; + @property (nonatomic) NSString *displayName; +// Returns true if any of the name parts (which doesn't include +// organization name) is non-empty. +- (BOOL)hasAnyNamePart; + @end #pragma mark - diff --git a/SignalServiceKit/src/Messages/Interactions/OWSContact.m b/SignalServiceKit/src/Messages/Interactions/OWSContact.m index 874b0cf7f..64df4513e 100644 --- a/SignalServiceKit/src/Messages/Interactions/OWSContact.m +++ b/SignalServiceKit/src/Messages/Interactions/OWSContact.m @@ -339,16 +339,23 @@ NSString *NSStringForContactAddressType(OWSContactAddressType value) - (nullable CNContact *)systemContactForName { CNMutableContact *systemContact = [CNMutableContact new]; - systemContact.givenName = self.givenName; - systemContact.middleName = self.middleName; - systemContact.familyName = self.familyName; - systemContact.namePrefix = self.namePrefix; - systemContact.nameSuffix = self.nameSuffix; + systemContact.givenName = self.givenName.ows_stripped; + systemContact.middleName = self.middleName.ows_stripped; + systemContact.familyName = self.familyName.ows_stripped; + systemContact.namePrefix = self.namePrefix.ows_stripped; + systemContact.nameSuffix = self.nameSuffix.ows_stripped; // We don't need to set display name, it's implicit for system contacts. - systemContact.organizationName = self.organizationName; + systemContact.organizationName = self.organizationName.ows_stripped; return systemContact; } +- (BOOL)hasAnyNamePart +{ + return (self.givenName.ows_stripped.length > 0 || self.middleName.ows_stripped.length > 0 + || self.familyName.ows_stripped.length > 0 || self.namePrefix.ows_stripped.length > 0 + || self.nameSuffix.ows_stripped.length > 0); +} + @end #pragma mark -