Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent 4dcb8e18b6
commit 39eac9129b

@ -83,6 +83,9 @@ typedef NS_ENUM(NSUInteger, OWSMessageGestureLocation) {
- (void)prepareForReuse; - (void)prepareForReuse;
+ (NSDictionary *)senderNamePrimaryAttributes;
+ (NSDictionary *)senderNameSecondaryAttributes;
#pragma mark - Gestures #pragma mark - Gestures
- (OWSMessageGestureLocation)gestureLocationForLocation:(CGPoint)locationInMessageBubble; - (OWSMessageGestureLocation)gestureLocationForLocation:(CGPoint)locationInMessageBubble;

@ -683,12 +683,33 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(self.senderNameLabel); OWSAssert(self.senderNameLabel);
OWSAssert(self.shouldShowSenderName); OWSAssert(self.shouldShowSenderName);
self.senderNameLabel.text = self.viewItem.senderName.uppercaseString;
self.senderNameLabel.textColor = self.bodyTextColor; self.senderNameLabel.textColor = self.bodyTextColor;
self.senderNameLabel.font = UIFont.ows_dynamicTypeCaption2Font; self.senderNameLabel.font = OWSMessageBubbleView.senderNameFont;
self.senderNameLabel.attributedText = self.viewItem.senderName;
self.senderNameLabel.lineBreakMode = NSLineBreakByTruncatingTail; self.senderNameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
} }
+ (UIFont *)senderNameFont
{
return UIFont.ows_dynamicTypeCaption2Font;
}
+ (NSDictionary *)senderNamePrimaryAttributes
{
return @{
NSFontAttributeName : self.senderNameFont,
NSForegroundColorAttributeName : ConversationStyle.bubbleTextColorIncoming,
};
}
+ (NSDictionary *)senderNameSecondaryAttributes
{
return @{
NSFontAttributeName : self.senderNameFont,
NSForegroundColorAttributeName : [ConversationStyle.bubbleTextColorIncoming colorWithAlphaComponent:0.75f],
};
}
- (BOOL)hasTapForMore - (BOOL)hasTapForMore
{ {
if (!self.hasBodyText) { if (!self.hasBodyText) {

@ -1206,8 +1206,8 @@ typedef enum : NSUInteger {
} }
} else { } else {
OWSAssert(self.thread.contactIdentifier); OWSAssert(self.thread.contactIdentifier);
name = [self.contactsManager name =
attributedStringForConversationTitleWithPhoneIdentifier:self.thread.contactIdentifier [self.contactsManager attributedContactOrProfileNameForPhoneIdentifier:self.thread.contactIdentifier
primaryFont:self.headerView.titlePrimaryFont primaryFont:self.headerView.titlePrimaryFont
secondaryFont:self.headerView.titleSecondaryFont]; secondaryFont:self.headerView.titleSecondaryFont];
} }
@ -4856,7 +4856,7 @@ typedef enum : NSUInteger {
ConversationViewItem *_Nullable nextViewItem = (i + 1 < viewItems.count ? viewItems[i + 1] : nil); ConversationViewItem *_Nullable nextViewItem = (i + 1 < viewItems.count ? viewItems[i + 1] : nil);
BOOL shouldShowSenderAvatar = NO; BOOL shouldShowSenderAvatar = NO;
BOOL shouldHideFooter = NO; BOOL shouldHideFooter = NO;
NSString *_Nullable senderName = nil; NSAttributedString *_Nullable senderName = nil;
OWSInteractionType interactionType = viewItem.interaction.interactionType; OWSInteractionType interactionType = viewItem.interaction.interactionType;
NSString *timestampText = [DateUtil formatTimestampShort:viewItem.interaction.timestamp]; NSString *timestampText = [DateUtil formatTimestampShort:viewItem.interaction.timestamp];
@ -4910,7 +4910,12 @@ typedef enum : NSUInteger {
|| viewItem.shouldShowDate); || viewItem.shouldShowDate);
} }
if (shouldShowSenderName) { if (shouldShowSenderName) {
senderName = [self.contactsManager contactOrProfileNameForPhoneIdentifier:incomingSenderId]; senderName = [self.contactsManager
attributedContactOrProfileNameForPhoneIdentifier:incomingSenderId
primaryAttributes:[OWSMessageBubbleView
senderNamePrimaryAttributes]
secondaryAttributes:[OWSMessageBubbleView
senderNameSecondaryAttributes]];
} }
// Show the sender avatar for incoming group messages unless // Show the sender avatar for incoming group messages unless

@ -56,7 +56,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
@property (nonatomic) BOOL shouldShowDate; @property (nonatomic) BOOL shouldShowDate;
@property (nonatomic) BOOL shouldShowSenderAvatar; @property (nonatomic) BOOL shouldShowSenderAvatar;
@property (nonatomic, nullable) NSString *senderName; @property (nonatomic, nullable) NSAttributedString *senderName;
@property (nonatomic) BOOL shouldHideFooter; @property (nonatomic) BOOL shouldHideFooter;
@property (nonatomic, readonly) ConversationStyle *conversationStyle; @property (nonatomic, readonly) ConversationStyle *conversationStyle;

@ -160,7 +160,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
[self clearCachedLayoutState]; [self clearCachedLayoutState];
} }
- (void)setSenderName:(nullable NSString *)senderName - (void)setSenderName:(nullable NSAttributedString *)senderName
{ {
if ([NSObject isNullableObject:senderName equalTo:_senderName]) { if ([NSObject isNullableObject:senderName equalTo:_senderName]) {
return; return;

@ -470,7 +470,7 @@ NS_ASSUME_NONNULL_BEGIN
name = [[NSAttributedString alloc] initWithString:thread.name]; name = [[NSAttributedString alloc] initWithString:thread.name];
} }
} else { } else {
name = [contactsManager attributedStringForConversationTitleWithPhoneIdentifier:thread.contactIdentifier name = [contactsManager attributedContactOrProfileNameForPhoneIdentifier:thread.contactIdentifier
primaryFont:self.nameFont primaryFont:self.nameFont
secondaryFont:self.nameSecondaryFont]; secondaryFont:self.nameSecondaryFont];
} }

@ -90,9 +90,12 @@ extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification;
- (NSAttributedString *)formattedFullNameForRecipientId:(NSString *)recipientId font:(UIFont *)font; - (NSAttributedString *)formattedFullNameForRecipientId:(NSString *)recipientId font:(UIFont *)font;
- (NSString *)contactOrProfileNameForPhoneIdentifier:(NSString *)recipientId; - (NSString *)contactOrProfileNameForPhoneIdentifier:(NSString *)recipientId;
- (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId; - (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId;
- (NSAttributedString *)attributedStringForConversationTitleWithPhoneIdentifier:(NSString *)recipientId - (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId
primaryFont:(UIFont *)primaryFont primaryFont:(UIFont *)primaryFont
secondaryFont:(UIFont *)secondaryFont; secondaryFont:(UIFont *)secondaryFont;
- (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId
primaryAttributes:(NSDictionary *)primaryAttributes
secondaryAttributes:(NSDictionary *)secondaryAttributes;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -4,6 +4,7 @@
#import "OWSContactsManager.h" #import "OWSContactsManager.h"
#import "Environment.h" #import "Environment.h"
#import "NSAttributedString+OWS.h"
#import "OWSFormat.h" #import "OWSFormat.h"
#import "OWSProfileManager.h" #import "OWSProfileManager.h"
#import "OWSUserProfile.h" #import "OWSUserProfile.h"
@ -737,37 +738,49 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
return [[NSAttributedString alloc] initWithString:[self contactOrProfileNameForPhoneIdentifier:recipientId]]; return [[NSAttributedString alloc] initWithString:[self contactOrProfileNameForPhoneIdentifier:recipientId]];
} }
- (NSAttributedString *)attributedStringForConversationTitleWithPhoneIdentifier:(NSString *)recipientId - (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId
primaryFont:(UIFont *)primaryFont primaryFont:(UIFont *)primaryFont
secondaryFont:(UIFont *)secondaryFont secondaryFont:(UIFont *)secondaryFont
{ {
OWSAssert(primaryFont);
OWSAssert(secondaryFont);
return [self attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId
primaryAttributes:@{
NSFontAttributeName : primaryFont,
}
secondaryAttributes:@{
NSFontAttributeName : secondaryFont,
}];
}
- (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId
primaryAttributes:(NSDictionary *)primaryAttributes
secondaryAttributes:(NSDictionary *)secondaryAttributes
{
OWSAssert(primaryAttributes.count > 0);
OWSAssert(secondaryAttributes.count > 0);
// Prefer a saved name from system contacts, if available // Prefer a saved name from system contacts, if available
NSString *_Nullable savedContactName = [self cachedContactNameForRecipientId: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 attributes:primaryAttributes];
} }
NSString *_Nullable profileName = [self.profileManager profileNameForRecipientId:recipientId]; NSString *_Nullable profileName = [self.profileManager profileNameForRecipientId:recipientId];
if (profileName.length > 0) { if (profileName.length > 0) {
NSString *numberAndProfileNameFormat = NSLocalizedString(@"PROFILE_NAME_AND_PHONE_NUMBER_LABEL_FORMAT", NSAttributedString *result =
@"Label text combining the phone number and profile name separated by a simple demarcation character. " [[NSAttributedString alloc] initWithString:recipientId attributes:primaryAttributes];
@"Phone number should be most prominent. '%1$@' is replaced with {{phone number}} and '%2$@' is replaced " result = [result rtlSafeAppend:[[NSAttributedString alloc] initWithString:@" "] referenceView:[UIView new]];
@"with {{profile name}}"); result = [result rtlSafeAppend:[[NSAttributedString alloc] initWithString:@"~"] referenceView:[UIView new]];
result =
NSString *numberAndProfileName = [result rtlSafeAppend:[[NSAttributedString alloc] initWithString:profileName attributes:secondaryAttributes]
[NSString stringWithFormat:numberAndProfileNameFormat, recipientId, profileName]; referenceView:[UIView new]];
return [result copy];
NSRange recipientIdRange = [numberAndProfileName rangeOfString:recipientId];
NSMutableAttributedString *attributedString =
[[NSMutableAttributedString alloc] initWithString:numberAndProfileName
attributes:@{ NSFontAttributeName : secondaryFont }];
[attributedString addAttribute:NSFontAttributeName value:primaryFont range:recipientIdRange];
return [attributedString copy];
} }
// else fall back to recipient id // else fall back to recipient id
return [[NSAttributedString alloc] initWithString:recipientId]; return [[NSAttributedString alloc] initWithString:recipientId attributes:primaryAttributes];
} }
// TODO refactor attributed counterparts to use this as a helper method? // TODO refactor attributed counterparts to use this as a helper method?

@ -161,10 +161,13 @@ public class ConversationStyle: NSObject {
} }
} }
@objc
public static var bubbleTextColorIncoming = UIColor.ows_white
@objc @objc
public func bubbleTextColor(message: TSMessage) -> UIColor { public func bubbleTextColor(message: TSMessage) -> UIColor {
if message is TSIncomingMessage { if message is TSIncomingMessage {
return UIColor.ows_white return ConversationStyle.bubbleTextColorIncoming
} else if let outgoingMessage = message as? TSOutgoingMessage { } else if let outgoingMessage = message as? TSOutgoingMessage {
switch outgoingMessage.messageState { switch outgoingMessage.messageState {
case .failed: case .failed:

Loading…
Cancel
Save