Respond to CR.
This commit is contained in:
parent
4dcb8e18b6
commit
39eac9129b
|
@ -83,6 +83,9 @@ typedef NS_ENUM(NSUInteger, OWSMessageGestureLocation) {
|
|||
|
||||
- (void)prepareForReuse;
|
||||
|
||||
+ (NSDictionary *)senderNamePrimaryAttributes;
|
||||
+ (NSDictionary *)senderNameSecondaryAttributes;
|
||||
|
||||
#pragma mark - Gestures
|
||||
|
||||
- (OWSMessageGestureLocation)gestureLocationForLocation:(CGPoint)locationInMessageBubble;
|
||||
|
|
|
@ -683,12 +683,33 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSAssert(self.senderNameLabel);
|
||||
OWSAssert(self.shouldShowSenderName);
|
||||
|
||||
self.senderNameLabel.text = self.viewItem.senderName.uppercaseString;
|
||||
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;
|
||||
}
|
||||
|
||||
+ (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
|
||||
{
|
||||
if (!self.hasBodyText) {
|
||||
|
|
|
@ -1206,10 +1206,10 @@ typedef enum : NSUInteger {
|
|||
}
|
||||
} else {
|
||||
OWSAssert(self.thread.contactIdentifier);
|
||||
name = [self.contactsManager
|
||||
attributedStringForConversationTitleWithPhoneIdentifier:self.thread.contactIdentifier
|
||||
primaryFont:self.headerView.titlePrimaryFont
|
||||
secondaryFont:self.headerView.titleSecondaryFont];
|
||||
name =
|
||||
[self.contactsManager attributedContactOrProfileNameForPhoneIdentifier:self.thread.contactIdentifier
|
||||
primaryFont:self.headerView.titlePrimaryFont
|
||||
secondaryFont:self.headerView.titleSecondaryFont];
|
||||
}
|
||||
self.title = nil;
|
||||
|
||||
|
@ -4856,7 +4856,7 @@ typedef enum : NSUInteger {
|
|||
ConversationViewItem *_Nullable nextViewItem = (i + 1 < viewItems.count ? viewItems[i + 1] : nil);
|
||||
BOOL shouldShowSenderAvatar = NO;
|
||||
BOOL shouldHideFooter = NO;
|
||||
NSString *_Nullable senderName = nil;
|
||||
NSAttributedString *_Nullable senderName = nil;
|
||||
|
||||
OWSInteractionType interactionType = viewItem.interaction.interactionType;
|
||||
NSString *timestampText = [DateUtil formatTimestampShort:viewItem.interaction.timestamp];
|
||||
|
@ -4910,7 +4910,12 @@ typedef enum : NSUInteger {
|
|||
|| viewItem.shouldShowDate);
|
||||
}
|
||||
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
|
||||
|
|
|
@ -56,7 +56,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
|
|||
|
||||
@property (nonatomic) BOOL shouldShowDate;
|
||||
@property (nonatomic) BOOL shouldShowSenderAvatar;
|
||||
@property (nonatomic, nullable) NSString *senderName;
|
||||
@property (nonatomic, nullable) NSAttributedString *senderName;
|
||||
@property (nonatomic) BOOL shouldHideFooter;
|
||||
|
||||
@property (nonatomic, readonly) ConversationStyle *conversationStyle;
|
||||
|
|
|
@ -160,7 +160,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|||
[self clearCachedLayoutState];
|
||||
}
|
||||
|
||||
- (void)setSenderName:(nullable NSString *)senderName
|
||||
- (void)setSenderName:(nullable NSAttributedString *)senderName
|
||||
{
|
||||
if ([NSObject isNullableObject:senderName equalTo:_senderName]) {
|
||||
return;
|
||||
|
|
|
@ -470,9 +470,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
name = [[NSAttributedString alloc] initWithString:thread.name];
|
||||
}
|
||||
} else {
|
||||
name = [contactsManager attributedStringForConversationTitleWithPhoneIdentifier:thread.contactIdentifier
|
||||
primaryFont:self.nameFont
|
||||
secondaryFont:self.nameSecondaryFont];
|
||||
name = [contactsManager attributedContactOrProfileNameForPhoneIdentifier:thread.contactIdentifier
|
||||
primaryFont:self.nameFont
|
||||
secondaryFont:self.nameSecondaryFont];
|
||||
}
|
||||
|
||||
self.nameLabel.attributedText = name;
|
||||
|
|
|
@ -90,9 +90,12 @@ extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification;
|
|||
- (NSAttributedString *)formattedFullNameForRecipientId:(NSString *)recipientId font:(UIFont *)font;
|
||||
- (NSString *)contactOrProfileNameForPhoneIdentifier:(NSString *)recipientId;
|
||||
- (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId;
|
||||
- (NSAttributedString *)attributedStringForConversationTitleWithPhoneIdentifier:(NSString *)recipientId
|
||||
primaryFont:(UIFont *)primaryFont
|
||||
secondaryFont:(UIFont *)secondaryFont;
|
||||
- (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId
|
||||
primaryFont:(UIFont *)primaryFont
|
||||
secondaryFont:(UIFont *)secondaryFont;
|
||||
- (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId
|
||||
primaryAttributes:(NSDictionary *)primaryAttributes
|
||||
secondaryAttributes:(NSDictionary *)secondaryAttributes;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#import "OWSContactsManager.h"
|
||||
#import "Environment.h"
|
||||
#import "NSAttributedString+OWS.h"
|
||||
#import "OWSFormat.h"
|
||||
#import "OWSProfileManager.h"
|
||||
#import "OWSUserProfile.h"
|
||||
|
@ -737,37 +738,49 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
|
|||
return [[NSAttributedString alloc] initWithString:[self contactOrProfileNameForPhoneIdentifier:recipientId]];
|
||||
}
|
||||
|
||||
- (NSAttributedString *)attributedStringForConversationTitleWithPhoneIdentifier:(NSString *)recipientId
|
||||
primaryFont:(UIFont *)primaryFont
|
||||
secondaryFont:(UIFont *)secondaryFont
|
||||
- (NSAttributedString *)attributedContactOrProfileNameForPhoneIdentifier:(NSString *)recipientId
|
||||
primaryFont:(UIFont *)primaryFont
|
||||
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
|
||||
NSString *_Nullable savedContactName = [self cachedContactNameForRecipientId:recipientId];
|
||||
if (savedContactName.length > 0) {
|
||||
return [[NSAttributedString alloc] initWithString:savedContactName];
|
||||
return [[NSAttributedString alloc] initWithString:savedContactName attributes:primaryAttributes];
|
||||
}
|
||||
|
||||
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];
|
||||
|
||||
NSRange recipientIdRange = [numberAndProfileName rangeOfString:recipientId];
|
||||
NSMutableAttributedString *attributedString =
|
||||
[[NSMutableAttributedString alloc] initWithString:numberAndProfileName
|
||||
attributes:@{ NSFontAttributeName : secondaryFont }];
|
||||
[attributedString addAttribute:NSFontAttributeName value:primaryFont range:recipientIdRange];
|
||||
|
||||
return [attributedString copy];
|
||||
NSAttributedString *result =
|
||||
[[NSAttributedString alloc] initWithString:recipientId attributes:primaryAttributes];
|
||||
result = [result rtlSafeAppend:[[NSAttributedString alloc] initWithString:@" "] referenceView:[UIView new]];
|
||||
result = [result rtlSafeAppend:[[NSAttributedString alloc] initWithString:@"~"] referenceView:[UIView new]];
|
||||
result =
|
||||
[result rtlSafeAppend:[[NSAttributedString alloc] initWithString:profileName attributes:secondaryAttributes]
|
||||
referenceView:[UIView new]];
|
||||
return [result copy];
|
||||
}
|
||||
|
||||
// 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?
|
||||
|
|
|
@ -161,10 +161,13 @@ public class ConversationStyle: NSObject {
|
|||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
public static var bubbleTextColorIncoming = UIColor.ows_white
|
||||
|
||||
@objc
|
||||
public func bubbleTextColor(message: TSMessage) -> UIColor {
|
||||
if message is TSIncomingMessage {
|
||||
return UIColor.ows_white
|
||||
return ConversationStyle.bubbleTextColorIncoming
|
||||
} else if let outgoingMessage = message as? TSOutgoingMessage {
|
||||
switch outgoingMessage.messageState {
|
||||
case .failed:
|
||||
|
|
Loading…
Reference in New Issue