Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent 0316a98eb8
commit 1520422b29

@ -31,12 +31,12 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) BOOL isGroupUpdate; @property (nonatomic, readonly) BOOL isGroupUpdate;
@property (nonatomic, readonly) BOOL isExpirationTimerUpdate; @property (nonatomic, readonly) BOOL isExpirationTimerUpdate;
@property (nonatomic, readonly) BOOL isEndSessionMessage; @property (nonatomic, readonly) BOOL isEndSessionMessage;
@property (nullable, nonatomic, readonly) NSData *groupId; @property (nonatomic, readonly, nullable) NSData *groupId;
@property (nonatomic, readonly) NSString *body; @property (nonatomic, readonly) NSString *body;
@property (nonatomic, readonly) NSArray<OWSSignalServiceProtosAttachmentPointer *> *attachmentPointerProtos; @property (nonatomic, readonly) NSArray<OWSSignalServiceProtosAttachmentPointer *> *attachmentPointerProtos;
@property (nonatomic, readonly) TSThread *thread; @property (nonatomic, readonly) TSThread *thread;
@property (nonatomic, readonly) TSQuotedMessage *quotedMessage; @property (nonatomic, readonly, nullable) TSQuotedMessage *quotedMessage;
@property (nonatomic, readonly) OWSContact *contact; @property (nonatomic, readonly, nullable) OWSContact *contact;
@end @end

@ -28,7 +28,7 @@ typedef NS_ENUM(NSUInteger, OWSContactPhoneType) {
@property (nonatomic, readonly) NSString *phoneNumber; @property (nonatomic, readonly) NSString *phoneNumber;
- (BOOL)isValid; - (BOOL)ows_isValid;
@end @end
@ -49,7 +49,7 @@ typedef NS_ENUM(NSUInteger, OWSContactEmailType) {
@property (nonatomic, readonly) NSString *email; @property (nonatomic, readonly) NSString *email;
- (BOOL)isValid; - (BOOL)ows_isValid;
@end @end
@ -75,7 +75,7 @@ typedef NS_ENUM(NSUInteger, OWSContactAddressType) {
@property (nonatomic, readonly, nullable) NSString *postcode; @property (nonatomic, readonly, nullable) NSString *postcode;
@property (nonatomic, readonly, nullable) NSString *country; @property (nonatomic, readonly, nullable) NSString *country;
- (BOOL)isValid; - (BOOL)ows_isValid;
@end @end
@ -102,7 +102,7 @@ typedef NS_ENUM(NSUInteger, OWSContactAddressType) {
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
- (BOOL)isValid; - (BOOL)ows_isValid;
@end @end

@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSContactPhoneNumber @implementation OWSContactPhoneNumber
- (BOOL)isValid - (BOOL)ows_isValid
{ {
if (![PhoneNumber tryParsePhoneNumberFromE164:self.phoneNumber]) { if (![PhoneNumber tryParsePhoneNumberFromE164:self.phoneNumber]) {
return NO; return NO;
@ -37,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
case OWSContactPhoneType_Mobile: case OWSContactPhoneType_Mobile:
case OWSContactPhoneType_Work: case OWSContactPhoneType_Work:
return YES; return YES;
default: case OWSContactPhoneType_Custom:
return self.label.ows_stripped.length > 0; return self.label.ows_stripped.length > 0;
} }
} }
@ -59,7 +59,7 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSContactEmail @implementation OWSContactEmail
- (BOOL)isValid - (BOOL)ows_isValid
{ {
if (self.email.ows_stripped.length < 1) { if (self.email.ows_stripped.length < 1) {
return NO; return NO;
@ -69,7 +69,7 @@ NS_ASSUME_NONNULL_BEGIN
case OWSContactEmailType_Mobile: case OWSContactEmailType_Mobile:
case OWSContactEmailType_Work: case OWSContactEmailType_Work:
return YES; return YES;
default: case OWSContactEmailType_Custom:
return self.label.ows_stripped.length > 0; return self.label.ows_stripped.length > 0;
} }
} }
@ -97,7 +97,7 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSContactAddress @implementation OWSContactAddress
- (BOOL)isValid - (BOOL)ows_isValid
{ {
if (self.street.ows_stripped.length < 1 && self.pobox.ows_stripped.length < 1 if (self.street.ows_stripped.length < 1 && self.pobox.ows_stripped.length < 1
&& self.neighborhood.ows_stripped.length < 1 && self.city.ows_stripped.length < 1 && self.neighborhood.ows_stripped.length < 1 && self.city.ows_stripped.length < 1
@ -109,7 +109,7 @@ NS_ASSUME_NONNULL_BEGIN
case OWSContactAddressType_Home: case OWSContactAddressType_Home:
case OWSContactAddressType_Work: case OWSContactAddressType_Work:
return YES; return YES;
default: case OWSContactAddressType_Custom:
return self.label.ows_stripped.length > 0; return self.label.ows_stripped.length > 0;
} }
} }
@ -141,24 +141,24 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSContact @implementation OWSContact
- (BOOL)isValid - (BOOL)ows_isValid
{ {
if (self.givenName.ows_stripped.length < 1 && self.familyName.ows_stripped.length) { if (self.displayName.ows_stripped.length) {
return NO; return NO;
} }
// Contact is valid if at least one entry is valid.
for (OWSContactPhoneNumber *phoneNumber in self.phoneNumbers) { for (OWSContactPhoneNumber *phoneNumber in self.phoneNumbers) {
if (phoneNumber.isValid) { if (phoneNumber.ows_isValid) {
return YES; return YES;
} }
} }
for (OWSContactEmail *email in self.emails) { for (OWSContactEmail *email in self.emails) {
if (email.isValid) { if (email.ows_isValid) {
return YES; return YES;
} }
} }
for (OWSContactAddress *address in self.addresses) { for (OWSContactAddress *address in self.addresses) {
if (address.isValid) { if (address.ows_isValid) {
return YES; return YES;
} }
} }
@ -246,7 +246,7 @@ NS_ASSUME_NONNULL_BEGIN
phoneNumber.phoneType = OWSContactPhoneType_Custom; phoneNumber.phoneType = OWSContactPhoneType_Custom;
phoneNumber.label = phoneNumberField.label; phoneNumber.label = phoneNumberField.label;
} }
if (phoneNumber.isValid) { if (phoneNumber.ows_isValid) {
[phoneNumbers addObject:phoneNumber]; [phoneNumbers addObject:phoneNumber];
} }
} }
@ -264,7 +264,7 @@ NS_ASSUME_NONNULL_BEGIN
email.emailType = OWSContactEmailType_Custom; email.emailType = OWSContactEmailType_Custom;
email.label = emailField.label; email.label = emailField.label;
} }
if (email.isValid) { if (email.ows_isValid) {
[emails addObject:email]; [emails addObject:email];
} }
} }
@ -292,7 +292,7 @@ NS_ASSUME_NONNULL_BEGIN
address.addressType = OWSContactAddressType_Custom; address.addressType = OWSContactAddressType_Custom;
address.label = addressField.label; address.label = addressField.label;
} }
if (address.isValid) { if (address.ows_isValid) {
[addresses addObject:address]; [addresses addObject:address];
} }
} }
@ -303,7 +303,7 @@ NS_ASSUME_NONNULL_BEGIN
// @property (readonly, copy, nullable, NS_NONATOMIC_IOSONLY) NSData *imageData; // @property (readonly, copy, nullable, NS_NONATOMIC_IOSONLY) NSData *imageData;
// @property (readonly, copy, nullable, NS_NONATOMIC_IOSONLY) NSData *thumbnailImageData; // @property (readonly, copy, nullable, NS_NONATOMIC_IOSONLY) NSData *thumbnailImageData;
if (contact.isValid) { if (contact.ows_isValid) {
return contact; return contact;
} else { } else {
return nil; return nil;
@ -316,7 +316,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSProdLogAndFail(@"%@ Missing contact.", self.logTag); OWSProdLogAndFail(@"%@ Missing contact.", self.logTag);
return nil; return nil;
} }
if (!contact.isValid) { if (!contact.ows_isValid) {
OWSProdLogAndFail(@"%@ Invalid contact.", self.logTag); OWSProdLogAndFail(@"%@ Invalid contact.", self.logTag);
return nil; return nil;
} }
@ -332,7 +332,7 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableArray<CNLabeledValue<CNPhoneNumber *> *> *systemPhoneNumbers = [NSMutableArray new]; NSMutableArray<CNLabeledValue<CNPhoneNumber *> *> *systemPhoneNumbers = [NSMutableArray new];
for (OWSContactPhoneNumber *phoneNumber in contact.phoneNumbers) { for (OWSContactPhoneNumber *phoneNumber in contact.phoneNumbers) {
if (!phoneNumber.isValid) { if (!phoneNumber.ows_isValid) {
OWSProdLogAndFail(@"%@ invalid phone number.", self.logTag); OWSProdLogAndFail(@"%@ invalid phone number.", self.logTag);
continue; continue;
} }
@ -358,7 +358,7 @@ NS_ASSUME_NONNULL_BEGIN
value:[CNPhoneNumber value:[CNPhoneNumber
phoneNumberWithStringValue:phoneNumber.phoneNumber]]]; phoneNumberWithStringValue:phoneNumber.phoneNumber]]];
break; break;
default: case OWSContactPhoneType_Custom:
[systemPhoneNumbers [systemPhoneNumbers
addObject:[CNLabeledValue addObject:[CNLabeledValue
labeledValueWithLabel:phoneNumber.label labeledValueWithLabel:phoneNumber.label
@ -371,7 +371,7 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableArray<CNLabeledValue<NSString *> *> *systemEmails = [NSMutableArray new]; NSMutableArray<CNLabeledValue<NSString *> *> *systemEmails = [NSMutableArray new];
for (OWSContactEmail *email in contact.emails) { for (OWSContactEmail *email in contact.emails) {
if (!email.isValid) { if (!email.ows_isValid) {
OWSProdLogAndFail(@"%@ invalid email.", self.logTag); OWSProdLogAndFail(@"%@ invalid email.", self.logTag);
continue; continue;
} }
@ -385,7 +385,7 @@ NS_ASSUME_NONNULL_BEGIN
case OWSContactEmailType_Work: case OWSContactEmailType_Work:
[systemEmails addObject:[CNLabeledValue labeledValueWithLabel:CNLabelWork value:email.email]]; [systemEmails addObject:[CNLabeledValue labeledValueWithLabel:CNLabelWork value:email.email]];
break; break;
default: case OWSContactEmailType_Custom:
[systemEmails addObject:[CNLabeledValue labeledValueWithLabel:email.label value:email.email]]; [systemEmails addObject:[CNLabeledValue labeledValueWithLabel:email.label value:email.email]];
break; break;
} }
@ -394,7 +394,7 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableArray<CNLabeledValue<CNPostalAddress *> *> *systemAddresses = [NSMutableArray new]; NSMutableArray<CNLabeledValue<CNPostalAddress *> *> *systemAddresses = [NSMutableArray new];
for (OWSContactAddress *address in contact.addresses) { for (OWSContactAddress *address in contact.addresses) {
if (!address.isValid) { if (!address.ows_isValid) {
OWSProdLogAndFail(@"%@ invalid address.", self.logTag); OWSProdLogAndFail(@"%@ invalid address.", self.logTag);
continue; continue;
} }
@ -417,7 +417,7 @@ NS_ASSUME_NONNULL_BEGIN
case OWSContactAddressType_Work: case OWSContactAddressType_Work:
[systemAddresses addObject:[CNLabeledValue labeledValueWithLabel:CNLabelWork value:systemAddress]]; [systemAddresses addObject:[CNLabeledValue labeledValueWithLabel:CNLabelWork value:systemAddress]];
break; break;
default: case OWSContactAddressType_Custom:
[systemAddresses addObject:[CNLabeledValue labeledValueWithLabel:address.label value:systemAddress]]; [systemAddresses addObject:[CNLabeledValue labeledValueWithLabel:address.label value:systemAddress]];
break; break;
} }
@ -462,7 +462,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
OWSAssert(contact); OWSAssert(contact);
if (!contact.isValid) { if (!contact.ows_isValid) {
OWSProdLogAndFail(@"%@ contact share is invalid.", self.logTag); OWSProdLogAndFail(@"%@ contact share is invalid.", self.logTag);
return nil; return nil;
} }
@ -470,7 +470,6 @@ NS_ASSUME_NONNULL_BEGIN
OWSSignalServiceProtosDataMessageContactBuilder *contactBuilder = OWSSignalServiceProtosDataMessageContactBuilder *contactBuilder =
[OWSSignalServiceProtosDataMessageContactBuilder new]; [OWSSignalServiceProtosDataMessageContactBuilder new];
// TODO: Should we normalize/validate values here?
OWSSignalServiceProtosDataMessageContactNameBuilder *nameBuilder = OWSSignalServiceProtosDataMessageContactNameBuilder *nameBuilder =
[OWSSignalServiceProtosDataMessageContactNameBuilder new]; [OWSSignalServiceProtosDataMessageContactNameBuilder new];
if (contact.givenName.ows_stripped.length > 0) { if (contact.givenName.ows_stripped.length > 0) {
@ -491,7 +490,7 @@ NS_ASSUME_NONNULL_BEGIN
[contactBuilder setNameBuilder:nameBuilder]; [contactBuilder setNameBuilder:nameBuilder];
for (OWSContactPhoneNumber *phoneNumber in contact.phoneNumbers) { for (OWSContactPhoneNumber *phoneNumber in contact.phoneNumbers) {
if (!phoneNumber.isValid) { if (!phoneNumber.ows_isValid) {
OWSProdLogAndFail(@"%@ phone number is invalid.", self.logTag); OWSProdLogAndFail(@"%@ phone number is invalid.", self.logTag);
continue; continue;
} }
@ -511,7 +510,7 @@ NS_ASSUME_NONNULL_BEGIN
case OWSContactPhoneType_Work: case OWSContactPhoneType_Work:
phoneBuilder.type = OWSSignalServiceProtosDataMessageContactPhoneTypeWork; phoneBuilder.type = OWSSignalServiceProtosDataMessageContactPhoneTypeWork;
break; break;
default: case OWSContactPhoneType_Custom:
phoneBuilder.type = OWSSignalServiceProtosDataMessageContactPhoneTypeCustom; phoneBuilder.type = OWSSignalServiceProtosDataMessageContactPhoneTypeCustom;
break; break;
} }
@ -519,7 +518,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
for (OWSContactEmail *email in contact.emails) { for (OWSContactEmail *email in contact.emails) {
if (!email.isValid) { if (!email.ows_isValid) {
OWSProdLogAndFail(@"%@ email is invalid.", self.logTag); OWSProdLogAndFail(@"%@ email is invalid.", self.logTag);
continue; continue;
} }
@ -539,7 +538,7 @@ NS_ASSUME_NONNULL_BEGIN
case OWSContactEmailType_Work: case OWSContactEmailType_Work:
emailBuilder.type = OWSSignalServiceProtosDataMessageContactEmailTypeWork; emailBuilder.type = OWSSignalServiceProtosDataMessageContactEmailTypeWork;
break; break;
default: case OWSContactEmailType_Custom:
emailBuilder.type = OWSSignalServiceProtosDataMessageContactEmailTypeCustom; emailBuilder.type = OWSSignalServiceProtosDataMessageContactEmailTypeCustom;
break; break;
} }
@ -547,7 +546,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
for (OWSContactAddress *address in contact.addresses) { for (OWSContactAddress *address in contact.addresses) {
if (!address.isValid) { if (!address.ows_isValid) {
OWSProdLogAndFail(@"%@ address is invalid.", self.logTag); OWSProdLogAndFail(@"%@ address is invalid.", self.logTag);
continue; continue;
} }
@ -689,7 +688,7 @@ NS_ASSUME_NONNULL_BEGIN
} else { } else {
return nil; return nil;
} }
if (!result.isValid) { if (!result.ows_isValid) {
return nil; return nil;
} }
return result; return result;
@ -722,7 +721,7 @@ NS_ASSUME_NONNULL_BEGIN
} else { } else {
return nil; return nil;
} }
if (!result.isValid) { if (!result.ows_isValid) {
return nil; return nil;
} }
return result; return result;
@ -768,7 +767,7 @@ NS_ASSUME_NONNULL_BEGIN
if (addressProto.hasCountry) { if (addressProto.hasCountry) {
result.country = addressProto.country.ows_stripped; result.country = addressProto.country.ows_stripped;
} }
if (!result.isValid) { if (!result.ows_isValid) {
return nil; return nil;
} }
return result; return result;

Loading…
Cancel
Save