From 52f479a0b1a075e28d4631b944855de26ba9d219 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 17 Jun 2019 13:52:17 +1000 Subject: [PATCH] Implement fancy avatars --- Podfile | 6 +++--- Podfile.lock | 6 +++++- Signal.xcodeproj/project.pbxproj | 16 ++++++++++++++++ SignalMessaging/Loki/Identicon+ObjC.swift | 9 +++++++++ SignalMessaging/utils/OWSAvatarBuilder.m | 6 ++---- SignalMessaging/utils/OWSContactAvatarBuilder.m | 5 ++++- 6 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 SignalMessaging/Loki/Identicon+ObjC.swift diff --git a/Podfile b/Podfile index 0c18e171f..5fae6548f 100644 --- a/Podfile +++ b/Podfile @@ -39,7 +39,7 @@ def shared_pods pod 'SQLCipher', ">= 4.0.1" # Forked for performance optimizations that are not likely to be upstreamed as they are specific - # to our limited use of Mantle + # to our limited use of Mantle pod 'Mantle', git: 'https://github.com/signalapp/Mantle', branch: 'signal-master' # pod 'Mantle', path: '../Mantle' @@ -63,13 +63,14 @@ def shared_pods pod 'Reachability', :inhibit_warnings => true pod 'YYImage', :inhibit_warnings => true pod 'CryptoSwift', :inhibit_warnings => true + pod 'IGIdenticon', :inhibit_warnings => true end target 'Signal' do project 'Signal' shared_pods pod 'SSZipArchive', :inhibit_warnings => true - + # Loki pod 'GCDWebServer', '~> 3.0' @@ -104,4 +105,3 @@ def enable_extension_support_for_purelayout(installer) end end end - diff --git a/Podfile.lock b/Podfile.lock index 08ccc0a45..bee3c5cdb 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -46,6 +46,7 @@ PODS: - HKDFKit/Tests (0.0.4): - CocoaLumberjack - SignalCoreKit + - IGIdenticon (0.6) - libPhoneNumber-iOS (0.9.13) - Mantle (2.1.0): - Mantle/extobjc (= 2.1.0) @@ -201,6 +202,7 @@ DEPENDENCIES: - GRKOpenSSLFramework (from `https://github.com/signalapp/GRKOpenSSLFramework`) - HKDFKit (from `https://github.com/signalapp/HKDFKit.git`) - HKDFKit/Tests (from `https://github.com/signalapp/HKDFKit.git`) + - IGIdenticon - Mantle (from `https://github.com/signalapp/Mantle`, branch `signal-master`) - PromiseKit (= 6.5.3) - PureLayout @@ -223,6 +225,7 @@ SPEC REPOS: - CocoaLumberjack - CryptoSwift - GCDWebServer + - IGIdenticon - libPhoneNumber-iOS - PromiseKit - PureLayout @@ -297,6 +300,7 @@ SPEC CHECKSUMS: GCDWebServer: ead88cd14596dd4eae4f5830b8877c87c8728990 GRKOpenSSLFramework: 8a3735ad41e7dc1daff460467bccd32ca5d6ae3e HKDFKit: 3b6dbbb9d59c221cc6c52c3aa915700cbf24e376 + IGIdenticon: 5790befde4fe56296927c72c0efed3d07b21de8e libPhoneNumber-iOS: e444379ac18bbfbdefad571da735b2cd7e096caa Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b PromiseKit: c609029bdd801f792551a504c695c7d3098b42cd @@ -313,6 +317,6 @@ SPEC CHECKSUMS: YapDatabase: b418a4baa6906e8028748938f9159807fd039af4 YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54 -PODFILE CHECKSUM: 708b5bc644a63e9bc55c409ac292c88c8ee78fad +PODFILE CHECKSUM: d7c222f400892f5c056cb2ec3517da1ac1e10238 COCOAPODS: 1.5.3 diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index ce391098e..3e3082d35 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -560,6 +560,7 @@ B8162F0522892C5F00D46544 /* FriendRequestViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8162F0422892C5F00D46544 /* FriendRequestViewDelegate.swift */; }; B821F2F82272CED3002C88C0 /* OnboardingAccountDetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B821F2F72272CED3002C88C0 /* OnboardingAccountDetailsViewController.swift */; }; B821F2FA2272CEEE002C88C0 /* OnboardingKeyPairViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B821F2F92272CEEE002C88C0 /* OnboardingKeyPairViewController.swift */; }; + B846365B22B7418B00AF1514 /* Identicon+ObjC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */; }; B90418E6183E9DD40038554A /* DateUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = B90418E5183E9DD40038554A /* DateUtil.m */; }; B9EB5ABD1884C002007CBB57 /* MessageUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9EB5ABC1884C002007CBB57 /* MessageUI.framework */; }; BFF3FB9730634F37D25903F4 /* Pods_Signal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D17BB5C25D615AB49813100C /* Pods_Signal.framework */; }; @@ -1347,6 +1348,7 @@ B8162F0422892C5F00D46544 /* FriendRequestViewDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendRequestViewDelegate.swift; sourceTree = ""; }; B821F2F72272CED3002C88C0 /* OnboardingAccountDetailsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingAccountDetailsViewController.swift; sourceTree = ""; }; B821F2F92272CEEE002C88C0 /* OnboardingKeyPairViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingKeyPairViewController.swift; sourceTree = ""; }; + B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Identicon+ObjC.swift"; sourceTree = ""; }; B90418E4183E9DD40038554A /* DateUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DateUtil.h; sourceTree = ""; }; B90418E5183E9DD40038554A /* DateUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DateUtil.m; sourceTree = ""; }; B97940251832BD2400BD66CB /* UIUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIUtil.h; sourceTree = ""; }; @@ -2233,6 +2235,7 @@ 346129A11FD1F09100532771 /* contacts */, 3461293F1FD1D74B00532771 /* environment */, 453518951FC63DBF00210559 /* Info.plist */, + B846365922B7417900AF1514 /* Loki */, 45194F911FD7214600333B2C /* Models */, 346129B01FD1F7E800532771 /* profiles */, 34480B5A1FD0A7E300BC14EF /* SignalMessaging-Prefix.pch */, @@ -2610,6 +2613,14 @@ path = Loki; sourceTree = ""; }; + B846365922B7417900AF1514 /* Loki */ = { + isa = PBXGroup; + children = ( + B846365A22B7418B00AF1514 /* Identicon+ObjC.swift */, + ); + path = Loki; + sourceTree = ""; + }; D221A07E169C9E5E00537ABF = { isa = PBXGroup; children = ( @@ -3260,6 +3271,7 @@ "${BUILT_PRODUCTS_DIR}/GCDWebServer/GCDWebServer.framework", "${PODS_ROOT}/GRKOpenSSLFramework/OpenSSL-iOS/bin/openssl.framework", "${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework", + "${BUILT_PRODUCTS_DIR}/IGIdenticon/IGIdenticon.framework", "${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework", "${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework", "${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework", @@ -3286,6 +3298,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GCDWebServer.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/IGIdenticon.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework", @@ -3339,6 +3352,7 @@ "${BUILT_PRODUCTS_DIR}/Curve25519Kit/Curve25519Kit.framework", "${PODS_ROOT}/GRKOpenSSLFramework/OpenSSL-iOS/bin/openssl.framework", "${BUILT_PRODUCTS_DIR}/HKDFKit/HKDFKit.framework", + "${BUILT_PRODUCTS_DIR}/IGIdenticon/IGIdenticon.framework", "${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework", "${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework", "${BUILT_PRODUCTS_DIR}/PureLayout/PureLayout.framework", @@ -3363,6 +3377,7 @@ "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Curve25519Kit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HKDFKit.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/IGIdenticon.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PureLayout.framework", @@ -3558,6 +3573,7 @@ 340872D622397E6800CB25B0 /* AttachmentCaptionToolbar.swift in Sources */, 34ABB2C42090C59700C727A6 /* OWSResaveCollectionDBMigration.m in Sources */, 4C948FF72146EB4800349F0D /* BlockListCache.swift in Sources */, + B846365B22B7418B00AF1514 /* Identicon+ObjC.swift in Sources */, 4551DB5A205C562300C8AE75 /* Collection+OWS.swift in Sources */, 34BBC84F220B8A0100857249 /* ImageEditorCropViewController.swift in Sources */, 34AC09ED211B39B100997B47 /* ContactFieldView.swift in Sources */, diff --git a/SignalMessaging/Loki/Identicon+ObjC.swift b/SignalMessaging/Loki/Identicon+ObjC.swift new file mode 100644 index 000000000..f616f09ab --- /dev/null +++ b/SignalMessaging/Loki/Identicon+ObjC.swift @@ -0,0 +1,9 @@ +import IGIdenticon + +@objc(LKIdenticon) +final class Identicon : NSObject { + + @objc static func generateIcon(string: String, size: CGSize) -> UIImage { + return IGIdenticon.Identicon().icon(from: string, size: size)! + } +} diff --git a/SignalMessaging/utils/OWSAvatarBuilder.m b/SignalMessaging/utils/OWSAvatarBuilder.m index bed4d510f..85644ce6a 100644 --- a/SignalMessaging/utils/OWSAvatarBuilder.m +++ b/SignalMessaging/utils/OWSAvatarBuilder.m @@ -11,6 +11,7 @@ #import "UIColor+OWS.h" #import "UIFont+OWS.h" #import "UIView+OWS.h" +#import NS_ASSUME_NONNULL_BEGIN @@ -29,10 +30,7 @@ typedef void (^OWSAvatarDrawBlock)(CGContextRef context); OWSAvatarBuilder *avatarBuilder; if ([thread isKindOfClass:[TSContactThread class]]) { TSContactThread *contactThread = (TSContactThread *)thread; - ConversationColorName colorName = thread.conversationColorName; - avatarBuilder = [[OWSContactAvatarBuilder alloc] initWithSignalId:contactThread.contactIdentifier - colorName:colorName - diameter:diameter]; + return [LKIdenticon generateIconWithString:contactThread.contactIdentifier size:CGSizeMake(diameter, diameter)]; } else if ([thread isKindOfClass:[TSGroupThread class]]) { avatarBuilder = [[OWSGroupAvatarBuilder alloc] initWithThread:(TSGroupThread *)thread diameter:diameter]; } else { diff --git a/SignalMessaging/utils/OWSContactAvatarBuilder.m b/SignalMessaging/utils/OWSContactAvatarBuilder.m index beedd12fc..dc6ff3216 100644 --- a/SignalMessaging/utils/OWSContactAvatarBuilder.m +++ b/SignalMessaging/utils/OWSContactAvatarBuilder.m @@ -127,6 +127,7 @@ NS_ASSUME_NONNULL_BEGIN return cachedAvatar; } + /** NSMutableString *initials = [NSMutableString string]; NSRange rangeOfLetters = [self.contactName rangeOfCharacterFromSet:[NSCharacterSet letterCharacterSet]]; @@ -178,7 +179,9 @@ NS_ASSUME_NONNULL_BEGIN OWSFailDebug(@"Could not generate avatar."); return nil; } - + */ + + UIImage *image = [LKIdenticon generateIconWithString:self.signalId size:CGSizeMake(self.diameter, self.diameter)]; [OWSContactAvatarBuilder.contactsManager.avatarCache setImage:image forKey:self.cacheKey diameter:self.diameter]; return image; }