diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index de1eaa635..e10cb3b11 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -97,6 +97,8 @@ 34F3089F1ECA580B00BB7697 /* OWSUnreadIndicatorCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 34F3089E1ECA580B00BB7697 /* OWSUnreadIndicatorCell.m */; }; 34F308A21ECB469700BB7697 /* OWSBezierPathView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34F308A11ECB469700BB7697 /* OWSBezierPathView.m */; }; 34FD93701E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 34FD936F1E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.m */; }; + 450449391F45EE7D002D1ADA /* NSString+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = 450449381F45EE7D002D1ADA /* NSString+OWS.m */; }; + 4504493A1F45EE7D002D1ADA /* NSString+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = 450449381F45EE7D002D1ADA /* NSString+OWS.m */; }; 450573FE1E78A06D00615BB4 /* OWS103EnableVideoCalling.m in Sources */ = {isa = PBXBuildFile; fileRef = 450573FD1E78A06D00615BB4 /* OWS103EnableVideoCalling.m */; }; 4505C2BF1E648EA300CEBF41 /* ExperienceUpgrade.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4505C2BE1E648EA300CEBF41 /* ExperienceUpgrade.swift */; }; 4505C2C01E648EA300CEBF41 /* ExperienceUpgrade.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4505C2BE1E648EA300CEBF41 /* ExperienceUpgrade.swift */; }; @@ -548,6 +550,8 @@ 34F308A11ECB469700BB7697 /* OWSBezierPathView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSBezierPathView.m; sourceTree = ""; }; 34FD936E1E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWSAnyTouchGestureRecognizer.h; path = views/OWSAnyTouchGestureRecognizer.h; sourceTree = ""; }; 34FD936F1E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSAnyTouchGestureRecognizer.m; path = views/OWSAnyTouchGestureRecognizer.m; sourceTree = ""; }; + 450449371F45EE7D002D1ADA /* NSString+OWS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSString+OWS.h"; path = "util/NSString+OWS.h"; sourceTree = ""; }; + 450449381F45EE7D002D1ADA /* NSString+OWS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSString+OWS.m"; path = "util/NSString+OWS.m"; sourceTree = ""; }; 450573FC1E78A06D00615BB4 /* OWS103EnableVideoCalling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWS103EnableVideoCalling.h; path = Migrations/OWS103EnableVideoCalling.h; sourceTree = ""; }; 450573FD1E78A06D00615BB4 /* OWS103EnableVideoCalling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWS103EnableVideoCalling.m; path = Migrations/OWS103EnableVideoCalling.m; sourceTree = ""; }; 4505C2BE1E648EA300CEBF41 /* ExperienceUpgrade.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ExperienceUpgrade.swift; path = ExperienceUpgrades/ExperienceUpgrade.swift; sourceTree = ""; }; @@ -1775,6 +1779,8 @@ 45C0DC1A1E68FE9000E04C47 /* UIApplication+OWS.swift */, 45C0DC1D1E69011F00E04C47 /* UIStoryboard+OWS.swift */, 45638BDE1F3DDB2200128435 /* MessageSender+Promise.swift */, + 450449371F45EE7D002D1ADA /* NSString+OWS.h */, + 450449381F45EE7D002D1ADA /* NSString+OWS.m */, ); name = "UI Categories"; path = ..; @@ -2223,6 +2229,7 @@ 45638BDC1F3DD0D400128435 /* DebugUICalling.swift in Sources */, 76EB058218170B33006006FC /* Environment.m in Sources */, 34B3F8921E8DF1710035BE1A /* SignalAttachment.swift in Sources */, + 450449391F45EE7D002D1ADA /* NSString+OWS.m in Sources */, 45464DBC1DFA041F001D3FD6 /* DataChannelMessage.swift in Sources */, 34E3E5681EC4B19400495BAC /* AudioProgressView.swift in Sources */, 3448BFCF1EDF0EA7005B2D69 /* OWSMessagesComposerTextView.m in Sources */, @@ -2367,6 +2374,7 @@ 45F170AF1E2F0393003FC1F2 /* CallAudioSessionTest.swift in Sources */, 34B3F8991E8DF1B90035BE1A /* TSMessageAdapterTest.m in Sources */, 456F6E231E24133500FD2210 /* Platform.swift in Sources */, + 4504493A1F45EE7D002D1ADA /* NSString+OWS.m in Sources */, 45843D201D2236B30013E85A /* OWSContactsSearcher.m in Sources */, 45AE48521E0732D6004D96C2 /* TurnServerInfo.swift in Sources */, 450873C41D9D5149006B54F2 /* OWSExpirationTimerView.m in Sources */, diff --git a/Signal/src/Profiles/OWSProfileManager.m b/Signal/src/Profiles/OWSProfileManager.m index 2517d11f1..280a9b5e3 100644 --- a/Signal/src/Profiles/OWSProfileManager.m +++ b/Signal/src/Profiles/OWSProfileManager.m @@ -4,6 +4,7 @@ #import "OWSProfileManager.h" #import "Environment.h" +#import "NSString+OWS.h" #import "Signal-Swift.h" #import #import @@ -59,6 +60,11 @@ NS_ASSUME_NONNULL_BEGIN return self; } +- (void)setProfileName:(nullable NSString *)profileName +{ + _profileName = [profileName ows_stripped]; +} + #pragma mark - NSObject - (BOOL)isEqual:(UserProfile *)other @@ -1161,7 +1167,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; { OWSAssert(filename.length > 0); - NSString *filePath = [self.profileAvatarsDirPath stringByAppendingPathComponent:filename]; UIImage *_Nullable image = [UIImage imageWithData:[self loadProfileDataWithFilename:filename]]; return image; } diff --git a/Signal/src/contact/OWSContactsManager.m b/Signal/src/contact/OWSContactsManager.m index 1e88e1ae0..49ebc5ae0 100644 --- a/Signal/src/contact/OWSContactsManager.m +++ b/Signal/src/contact/OWSContactsManager.m @@ -413,10 +413,14 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account - (nullable NSString *)formattedProfileNameForRecipientId:(NSString *)recipientId { NSString *_Nullable profileName = [self.profileManager profileNameForRecipientId:recipientId]; - if (profileName == nil) { + if (profileName.length == 0) { return nil; } - return [@"~" stringByAppendingString:profileName]; + + NSString *profileNameFormatString = NSLocalizedString(@"PROFILE_NAME_LABEL_FORMAT", + @"Prepend a simple marker to differentiate the profile name, embeds the contact's {{profile name}}."); + + return [NSString stringWithFormat:profileNameFormatString, profileName]; } - (NSString *_Nonnull)displayNameForPhoneIdentifier:(NSString *_Nullable)recipientId @@ -530,9 +534,15 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account return [[NSAttributedString alloc] initWithString:savedContactName]; } - NSString *_Nullable formattedProfileName = [self formattedProfileNameForRecipientId:recipientId]; - if (formattedProfileName.length > 0) { - NSString *numberAndProfileName = [NSString stringWithFormat:@"%@ %@", recipientId, formattedProfileName]; + NSString *_Nullable profileName = [self.profileManager profileNameForRecipientId:recipientId]; + if (profileName.length > 0) { + NSString *numberAndProfileNameFormat = NSLocalizedString(@"PROFILE_NAME_AND_PHONE_NUMBER_LABEL_FORMAT", + @"Label text combining the phone number and profile name separated by a simple demarcation character. " + @"Phone number should be most prominent. '%1$@' is replaced with {{phone number}} and '%2$@' is replaced " + @"with {{profile name}}"); + + NSString *numberAndProfileName = + [NSString stringWithFormat:numberAndProfileNameFormat, recipientId, profileName]; return [[NSAttributedString alloc] initWithString:numberAndProfileName]; } diff --git a/Signal/src/util/NSString+OWS.h b/Signal/src/util/NSString+OWS.h new file mode 100644 index 000000000..1f897763d --- /dev/null +++ b/Signal/src/util/NSString+OWS.h @@ -0,0 +1,11 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import + +@interface NSString (OWS) + +- (NSString *)ows_stripped; + +@end diff --git a/Signal/src/util/NSString+OWS.m b/Signal/src/util/NSString+OWS.m new file mode 100644 index 000000000..71a092d4d --- /dev/null +++ b/Signal/src/util/NSString+OWS.m @@ -0,0 +1,14 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "NSString+OWS.h" + +@implementation NSString (OWS) + +- (NSString *)ows_stripped +{ + return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; +} + +@end diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index f532ed780..4b924e6ea 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -1060,6 +1060,12 @@ /* No comment provided by engineer. */ "PROCEED_BUTTON" = "Proceed"; +/* Label text combining the phone number and profile name separated by a simple demarcation character. Phone number should be most prominent. '%1$@' is replaced with {{phone number}} and '%2$@' is replaced with {{profile name}} */ +"PROFILE_NAME_AND_PHONE_NUMBER_LABEL_FORMAT" = "%1$@ ~%2$@"; + +/* Prepend a simple marker to differentiate the profile name, embeds the contact's {{profile name}}. */ +"PROFILE_NAME_LABEL_FORMAT" = "~%@"; + /* Action Sheet title prompting the user for a profile avatar */ "PROFILE_VIEW_AVATAR_ACTIONSHEET_TITLE" = "Set Profile Avatar";