diff --git a/src/Contacts/Contact.m b/src/Contacts/Contact.m index e455b8069..b941b8279 100644 --- a/src/Contacts/Contact.m +++ b/src/Contacts/Contact.m @@ -3,6 +3,7 @@ // #import "Contact.h" +#import "Cryptography.h" #import "PhoneNumber.h" #import "SignalRecipient.h" #import "TSAccountManager.h" @@ -281,6 +282,34 @@ NS_ASSUME_NONNULL_BEGIN return value; } +- (NSUInteger)hash +{ + // base hash is some arbitrary number + NSUInteger hash = 1825038313; + + hash = hash ^ self.fullName.hash; + + // base thumbnailHash is some arbitrary number + NSUInteger thumbnailHash = 389201946; + if (self.cnContact.thumbnailImageData) { + NSData *thumbnailHashData = + [Cryptography computeSHA256Digest:self.cnContact.thumbnailImageData truncatedToBytes:sizeof(thumbnailHash)]; + [thumbnailHashData getBytes:&thumbnailHash length:sizeof(thumbnailHash)]; + } + + hash = hash ^ thumbnailHash; + + for (PhoneNumber *phoneNumber in self.parsedPhoneNumbers) { + hash = hash ^ phoneNumber.toE164.hash; + } + + for (NSString *email in self.emails) { + hash = hash ^ email.hash; + } + + return hash; +} + @end NS_ASSUME_NONNULL_END