Use profile name in quoted messages, fix "multi account" label

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 6703e1b11d
commit e554884ab3

@ -320,7 +320,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
} else { } else {
OWSContactsManager *contactsManager = Environment.current.contactsManager; OWSContactsManager *contactsManager = Environment.current.contactsManager;
NSString *quotedAuthor = [contactsManager displayNameForPhoneIdentifier:self.quotedMessage.authorId]; NSString *quotedAuthor = [contactsManager contactOrProfileNameForPhoneIdentifier:self.quotedMessage.authorId];
quotedAuthorText = [NSString quotedAuthorText = [NSString
stringWithFormat: stringWithFormat:
NSLocalizedString(@"QUOTED_REPLY_AUTHOR_INDICATOR_FORMAT", NSLocalizedString(@"QUOTED_REPLY_AUTHOR_INDICATOR_FORMAT",

@ -367,12 +367,26 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
return [OWSProfileManager sharedManager]; return [OWSProfileManager sharedManager];
} }
- (NSString *_Nullable)cachedDisplayNameForRecipientId:(NSString *)recipientId - (NSString *_Nullable)cachedContactNameForRecipientId:(NSString *)recipientId
{ {
OWSAssert(recipientId.length > 0); OWSAssert(recipientId.length > 0);
SignalAccount *_Nullable signalAccount = [self signalAccountForRecipientId:recipientId]; SignalAccount *signalAccount = [self signalAccountForRecipientId:recipientId];
return signalAccount.displayName; if (!signalAccount) {
return nil;
}
NSString *fullName = signalAccount.contactFullName;
if (fullName.length == 0) {
return nil;
}
NSString *multipleAccountLabelText = signalAccount.multipleAccountLabelText;
if (multipleAccountLabelText.length == 0) {
return fullName;
}
return [NSString stringWithFormat:@"%@ (%@)", fullName, multipleAccountLabelText];
} }
- (NSString *_Nullable)cachedFirstNameForRecipientId:(NSString *)recipientId - (NSString *_Nullable)cachedFirstNameForRecipientId:(NSString *)recipientId
@ -440,7 +454,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
- (BOOL)hasNameInSystemContactsForRecipientId:(NSString *)recipientId - (BOOL)hasNameInSystemContactsForRecipientId:(NSString *)recipientId
{ {
return [self cachedDisplayNameForRecipientId:recipientId] != nil; return [self cachedContactNameForRecipientId:recipientId].length > 0;
} }
- (NSString *)unknownContactName - (NSString *)unknownContactName
@ -469,7 +483,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
- (nullable NSString *)nameFromSystemContactsForRecipientId:(NSString *)recipientId - (nullable NSString *)nameFromSystemContactsForRecipientId:(NSString *)recipientId
{ {
return [self cachedDisplayNameForRecipientId:recipientId]; return [self cachedContactNameForRecipientId:recipientId];
} }
- (NSString *_Nonnull)displayNameForPhoneIdentifier:(NSString *_Nullable)recipientId - (NSString *_Nonnull)displayNameForPhoneIdentifier:(NSString *_Nullable)recipientId
@ -577,7 +591,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
- (NSString *)contactOrProfileNameForPhoneIdentifier:(NSString *)recipientId - (NSString *)contactOrProfileNameForPhoneIdentifier:(NSString *)recipientId
{ {
// Prefer a saved name from system contacts, if available // Prefer a saved name from system contacts, if available
NSString *_Nullable savedContactName = [self cachedDisplayNameForRecipientId:recipientId]; NSString *_Nullable savedContactName = [self cachedContactNameForRecipientId:recipientId];
if (savedContactName.length > 0) { if (savedContactName.length > 0) {
return savedContactName; return savedContactName;
} }
@ -608,7 +622,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
secondaryFont:(UIFont *)secondaryFont secondaryFont:(UIFont *)secondaryFont
{ {
// Prefer a saved name from system contacts, if available // Prefer a saved name from system contacts, if available
NSString *_Nullable savedContactName = [self cachedDisplayNameForRecipientId:recipientId]; NSString *_Nullable savedContactName = [self cachedContactNameForRecipientId:recipientId];
if (savedContactName.length > 0) { if (savedContactName.length > 0) {
return [[NSAttributedString alloc] initWithString:savedContactName]; return [[NSAttributedString alloc] initWithString:savedContactName];
} }
@ -640,7 +654,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
- (NSString *)stringForConversationTitleWithPhoneIdentifier:(NSString *)recipientId - (NSString *)stringForConversationTitleWithPhoneIdentifier:(NSString *)recipientId
{ {
// Prefer a saved name from system contacts, if available // Prefer a saved name from system contacts, if available
NSString *_Nullable savedContactName = [self cachedDisplayNameForRecipientId:recipientId]; NSString *_Nullable savedContactName = [self cachedContactNameForRecipientId:recipientId];
if (savedContactName.length > 0) { if (savedContactName.length > 0) {
return savedContactName; return savedContactName;
} }

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "TSYapDatabaseObject.h" #import "TSYapDatabaseObject.h"
@ -34,7 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
// this is a label for the account. // this is a label for the account.
@property (nonatomic) NSString *multipleAccountLabelText; @property (nonatomic) NSString *multipleAccountLabelText;
- (NSString *)displayName; - (nullable NSString *)contactFullName;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;

@ -50,16 +50,9 @@ NS_ASSUME_NONNULL_BEGIN
return _recipientId; return _recipientId;
} }
- (NSString *)displayName - (nullable NSString *)contactFullName
{ {
NSString *baseName = (self.contact.fullName.length > 0 ? self.contact.fullName : self.recipientId); return self.contact.fullName.filterStringForDisplay;
OWSAssert(self.hasMultipleAccountContact == (self.multipleAccountLabelText != nil));
NSString *displayName = (self.multipleAccountLabelText
? [NSString stringWithFormat:@"%@ (%@)", baseName, self.multipleAccountLabelText]
: baseName);
return displayName.filterStringForDisplay;
} }
- (NSString *)multipleAccountLabelText - (NSString *)multipleAccountLabelText

Loading…
Cancel
Save