CR: RTL, trim profile names, ensure not empty

- RTL support with localizable format strings
- Trim decrypted profile names
- more rigorous empty check

// FREEBIE
This commit is contained in:
Michael Kirk 2017-08-17 12:18:05 -04:00
parent 4511b4015f
commit 7c386b1d1e
6 changed files with 60 additions and 6 deletions

View file

@ -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 = "<group>"; };
34FD936E1E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWSAnyTouchGestureRecognizer.h; path = views/OWSAnyTouchGestureRecognizer.h; sourceTree = "<group>"; };
34FD936F1E3BD43A00109093 /* OWSAnyTouchGestureRecognizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSAnyTouchGestureRecognizer.m; path = views/OWSAnyTouchGestureRecognizer.m; sourceTree = "<group>"; };
450449371F45EE7D002D1ADA /* NSString+OWS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSString+OWS.h"; path = "util/NSString+OWS.h"; sourceTree = "<group>"; };
450449381F45EE7D002D1ADA /* NSString+OWS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSString+OWS.m"; path = "util/NSString+OWS.m"; sourceTree = "<group>"; };
450573FC1E78A06D00615BB4 /* OWS103EnableVideoCalling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWS103EnableVideoCalling.h; path = Migrations/OWS103EnableVideoCalling.h; sourceTree = "<group>"; };
450573FD1E78A06D00615BB4 /* OWS103EnableVideoCalling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWS103EnableVideoCalling.m; path = Migrations/OWS103EnableVideoCalling.m; sourceTree = "<group>"; };
4505C2BE1E648EA300CEBF41 /* ExperienceUpgrade.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ExperienceUpgrade.swift; path = ExperienceUpgrades/ExperienceUpgrade.swift; sourceTree = "<group>"; };
@ -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 */,

View file

@ -4,6 +4,7 @@
#import "OWSProfileManager.h"
#import "Environment.h"
#import "NSString+OWS.h"
#import "Signal-Swift.h"
#import <SignalServiceKit/Cryptography.h>
#import <SignalServiceKit/NSData+hexString.h>
@ -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;
}

View file

@ -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];
}

View file

@ -0,0 +1,11 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (OWS)
- (NSString *)ows_stripped;
@end

View file

@ -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

View file

@ -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";