|
|
|
@ -2,10 +2,9 @@
|
|
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "InboxTableViewCell.h"
|
|
|
|
|
#import "HomeViewCell.h"
|
|
|
|
|
#import "OWSAvatarBuilder.h"
|
|
|
|
|
#import "Signal-Swift.h"
|
|
|
|
|
#import "ViewControllerUtils.h"
|
|
|
|
|
#import <SignalMessaging/OWSFormat.h>
|
|
|
|
|
#import <SignalMessaging/OWSUserProfile.h>
|
|
|
|
|
#import <SignalServiceKit/OWSMessageManager.h>
|
|
|
|
@ -15,17 +14,16 @@
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
#define ARCHIVE_IMAGE_VIEW_WIDTH 22.0f
|
|
|
|
|
#define DELETE_IMAGE_VIEW_WIDTH 19.0f
|
|
|
|
|
#define TIME_LABEL_SIZE 11
|
|
|
|
|
#define DATE_LABEL_SIZE 13
|
|
|
|
|
#define SWIPE_ARCHIVE_OFFSET -50
|
|
|
|
|
const NSUInteger kHomeViewCellHeight = 72;
|
|
|
|
|
const NSUInteger kHomeViewCellHMargin = 16;
|
|
|
|
|
const NSUInteger kHomeViewCellVMargin = 12;
|
|
|
|
|
const NSUInteger kHomeViewAvatarSize = kHomeViewCellHeight - kHomeViewCellVMargin * 2;
|
|
|
|
|
const NSUInteger kHomeViewAvatarHSpacing = 12;
|
|
|
|
|
|
|
|
|
|
const NSUInteger kAvatarViewDiameter = 52;
|
|
|
|
|
|
|
|
|
|
@interface InboxTableViewCell ()
|
|
|
|
|
@interface HomeViewCell ()
|
|
|
|
|
|
|
|
|
|
@property (nonatomic) AvatarImageView *avatarView;
|
|
|
|
|
@property (nonatomic) UIView *payloadView;
|
|
|
|
|
@property (nonatomic) UILabel *nameLabel;
|
|
|
|
|
@property (nonatomic) UILabel *snippetLabel;
|
|
|
|
|
@property (nonatomic) UILabel *timeLabel;
|
|
|
|
@ -35,11 +33,13 @@ const NSUInteger kAvatarViewDiameter = 52;
|
|
|
|
|
@property (nonatomic) TSThread *thread;
|
|
|
|
|
@property (nonatomic) OWSContactsManager *contactsManager;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, readonly) NSMutableArray<NSLayoutConstraint *> *viewConstraints;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
@implementation InboxTableViewCell
|
|
|
|
|
@implementation HomeViewCell
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier
|
|
|
|
|
{
|
|
|
|
@ -64,64 +64,84 @@ const NSUInteger kAvatarViewDiameter = 52;
|
|
|
|
|
OWSAssert(!self.avatarView);
|
|
|
|
|
|
|
|
|
|
[self setTranslatesAutoresizingMaskIntoConstraints:NO];
|
|
|
|
|
self.preservesSuperviewLayoutMargins = YES;
|
|
|
|
|
self.contentView.preservesSuperviewLayoutMargins = YES;
|
|
|
|
|
self.layoutMargins = UIEdgeInsetsZero;
|
|
|
|
|
self.contentView.layoutMargins = UIEdgeInsetsZero;
|
|
|
|
|
self.preservesSuperviewLayoutMargins = NO;
|
|
|
|
|
self.contentView.preservesSuperviewLayoutMargins = NO;
|
|
|
|
|
|
|
|
|
|
self.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
|
|
|
|
|
_viewConstraints = [NSMutableArray new];
|
|
|
|
|
|
|
|
|
|
self.avatarView = [[AvatarImageView alloc] init];
|
|
|
|
|
[self.contentView addSubview:self.avatarView];
|
|
|
|
|
[self.avatarView autoSetDimension:ALDimensionWidth toSize:self.avatarSize];
|
|
|
|
|
[self.avatarView autoSetDimension:ALDimensionHeight toSize:self.avatarSize];
|
|
|
|
|
[self.avatarView autoPinLeadingToSuperviewMargin];
|
|
|
|
|
[self.avatarView autoSetDimension:ALDimensionWidth toSize:kHomeViewAvatarSize];
|
|
|
|
|
[self.avatarView autoSetDimension:ALDimensionHeight toSize:kHomeViewAvatarSize];
|
|
|
|
|
[self.avatarView autoPinLeadingToSuperviewMarginWithInset:kHomeViewCellHMargin];
|
|
|
|
|
[self.avatarView autoVCenterInSuperview];
|
|
|
|
|
[self.avatarView setContentHuggingHigh];
|
|
|
|
|
[self.avatarView setCompressionResistanceHigh];
|
|
|
|
|
|
|
|
|
|
self.payloadView = [UIView containerView];
|
|
|
|
|
[self.contentView addSubview:self.payloadView];
|
|
|
|
|
[self.payloadView autoPinLeadingToTrailingEdgeOfView:self.avatarView offset:kHomeViewAvatarHSpacing];
|
|
|
|
|
[self.payloadView autoVCenterInSuperview];
|
|
|
|
|
|
|
|
|
|
self.nameLabel = [UILabel new];
|
|
|
|
|
self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
|
self.nameLabel.font = [UIFont ows_boldFontWithSize:14.0f];
|
|
|
|
|
[self.contentView addSubview:self.nameLabel];
|
|
|
|
|
[self.nameLabel autoPinLeadingToTrailingEdgeOfView:self.avatarView offset:13.f];
|
|
|
|
|
[self.nameLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.avatarView];
|
|
|
|
|
self.nameLabel.font = self.nameFont;
|
|
|
|
|
[self.nameLabel setContentHuggingHorizontalLow];
|
|
|
|
|
[self.nameLabel setCompressionResistanceHorizontalLow];
|
|
|
|
|
|
|
|
|
|
self.timeLabel = [UILabel new];
|
|
|
|
|
[self.timeLabel setContentHuggingHorizontalHigh];
|
|
|
|
|
[self.timeLabel setCompressionResistanceHorizontalHigh];
|
|
|
|
|
|
|
|
|
|
UIStackView *topRowView = [[UIStackView alloc] initWithArrangedSubviews:@[
|
|
|
|
|
self.nameLabel,
|
|
|
|
|
self.timeLabel,
|
|
|
|
|
]];
|
|
|
|
|
topRowView.axis = UILayoutConstraintAxisHorizontal;
|
|
|
|
|
topRowView.spacing = 4;
|
|
|
|
|
[self.payloadView addSubview:topRowView];
|
|
|
|
|
[topRowView autoPinLeadingToSuperviewMargin];
|
|
|
|
|
[topRowView autoPinTrailingToSuperviewMargin];
|
|
|
|
|
[topRowView autoPinTopToSuperviewMargin];
|
|
|
|
|
|
|
|
|
|
self.snippetLabel = [UILabel new];
|
|
|
|
|
self.snippetLabel.font = [UIFont ows_regularFontWithSize:14.f];
|
|
|
|
|
self.snippetLabel.font = [self snippetFont];
|
|
|
|
|
self.snippetLabel.numberOfLines = 1;
|
|
|
|
|
self.snippetLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
|
self.snippetLabel.textColor = [UIColor colorWithWhite:2 / 3.f alpha:1.f];
|
|
|
|
|
self.snippetLabel.numberOfLines = 2;
|
|
|
|
|
self.snippetLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
|
[self.contentView addSubview:self.snippetLabel];
|
|
|
|
|
[self.snippetLabel autoPinLeadingToTrailingEdgeOfView:self.avatarView offset:13.f];
|
|
|
|
|
[self.snippetLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.nameLabel withOffset:5.f];
|
|
|
|
|
[self.snippetLabel autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:self.nameLabel];
|
|
|
|
|
[self.payloadView addSubview:self.snippetLabel];
|
|
|
|
|
[self.snippetLabel autoPinLeadingToSuperviewMargin];
|
|
|
|
|
[self.snippetLabel autoPinTrailingToSuperviewMargin];
|
|
|
|
|
[self.snippetLabel autoPinBottomToSuperviewMargin];
|
|
|
|
|
[self.snippetLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topRowView withOffset:5.f];
|
|
|
|
|
[self.snippetLabel setContentHuggingHorizontalLow];
|
|
|
|
|
[self.snippetLabel setCompressionResistanceHorizontalLow];
|
|
|
|
|
|
|
|
|
|
self.timeLabel = [UILabel new];
|
|
|
|
|
self.timeLabel.font = [UIFont ows_lightFontWithSize:14.f];
|
|
|
|
|
[self.contentView addSubview:self.timeLabel];
|
|
|
|
|
[self.timeLabel autoPinTrailingToSuperviewMargin];
|
|
|
|
|
[self.timeLabel autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.nameLabel];
|
|
|
|
|
[self.timeLabel autoPinLeadingToTrailingEdgeOfView:self.nameLabel offset:10.f];
|
|
|
|
|
[self.timeLabel setContentHuggingHorizontalHigh];
|
|
|
|
|
[self.timeLabel setCompressionResistanceHigh];
|
|
|
|
|
self.unreadLabel = [UILabel new];
|
|
|
|
|
self.unreadLabel.font = [UIFont ows_dynamicTypeCaption1Font];
|
|
|
|
|
self.unreadLabel.textColor = [UIColor whiteColor];
|
|
|
|
|
self.unreadLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
|
self.unreadLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
|
|
|
|
|
const int kunreadBadgeSize = 24;
|
|
|
|
|
self.unreadBadge = [[NeverClearView alloc] initWithFrame:CGRectMake(0, 0, kunreadBadgeSize, kunreadBadgeSize)];
|
|
|
|
|
self.unreadBadge.layer.cornerRadius = kunreadBadgeSize / 2;
|
|
|
|
|
self.unreadBadge = [NeverClearView new];
|
|
|
|
|
self.unreadBadge.backgroundColor = [UIColor ows_materialBlueColor];
|
|
|
|
|
[self.contentView addSubview:self.unreadBadge];
|
|
|
|
|
[self.unreadBadge autoSetDimension:ALDimensionWidth toSize:kunreadBadgeSize];
|
|
|
|
|
[self.unreadBadge autoSetDimension:ALDimensionHeight toSize:kunreadBadgeSize];
|
|
|
|
|
[self.unreadBadge autoPinTrailingToSuperviewMargin];
|
|
|
|
|
[self.unreadBadge autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self.avatarView];
|
|
|
|
|
[self.unreadBadge setContentHuggingHorizontalHigh];
|
|
|
|
|
[self.unreadBadge autoPinTrailingToSuperviewMarginWithInset:kHomeViewCellHMargin];
|
|
|
|
|
[self.unreadBadge autoAlignAxis:ALAxisHorizontal toSameAxisOfView:self.timeLabel];
|
|
|
|
|
[self.unreadBadge setContentHuggingHigh];
|
|
|
|
|
[self.unreadBadge setCompressionResistanceHigh];
|
|
|
|
|
|
|
|
|
|
self.unreadLabel = [UILabel new];
|
|
|
|
|
self.unreadLabel.font = [UIFont ows_regularFontWithSize:12.f];
|
|
|
|
|
self.unreadLabel.textColor = [UIColor whiteColor];
|
|
|
|
|
self.unreadLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
|
self.unreadLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
// TODO: Will this localize? It assumes that the worst case
|
|
|
|
|
// unread count (99) will fit horizontally into some multiple
|
|
|
|
|
// N of the font's line height.
|
|
|
|
|
const int unreadBadgeSize = (int)ceil(self.unreadLabel.font.lineHeight * 1.5f);
|
|
|
|
|
self.unreadBadge.layer.cornerRadius = unreadBadgeSize / 2;
|
|
|
|
|
[self.unreadBadge autoSetDimension:ALDimensionWidth toSize:unreadBadgeSize];
|
|
|
|
|
[self.unreadBadge autoSetDimension:ALDimensionHeight toSize:unreadBadgeSize];
|
|
|
|
|
|
|
|
|
|
[self.unreadBadge addSubview:self.unreadLabel];
|
|
|
|
|
[self.unreadLabel autoVCenterInSuperview];
|
|
|
|
|
[self.unreadLabel autoPinWidthToSuperview];
|
|
|
|
@ -134,15 +154,11 @@ const NSUInteger kAvatarViewDiameter = 52;
|
|
|
|
|
|
|
|
|
|
+ (CGFloat)rowHeight
|
|
|
|
|
{
|
|
|
|
|
return 72.f;
|
|
|
|
|
return kHomeViewCellHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (CGFloat)avatarSize
|
|
|
|
|
- (void)initializeLayout
|
|
|
|
|
{
|
|
|
|
|
return 52.f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)initializeLayout {
|
|
|
|
|
self.selectionStyle = UITableViewCellSelectionStyleDefault;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -152,61 +168,21 @@ const NSUInteger kAvatarViewDiameter = 52;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)configureWithThread:(TSThread *)thread
|
|
|
|
|
contactsManager:(OWSContactsManager *)contactsManager
|
|
|
|
|
blockedPhoneNumberSet:(NSSet<NSString *> *)blockedPhoneNumberSet
|
|
|
|
|
contactsManager:(OWSContactsManager *)contactsManager
|
|
|
|
|
blockedPhoneNumberSet:(NSSet<NSString *> *)blockedPhoneNumberSet
|
|
|
|
|
shouldHaveBottomSeparator:(BOOL)shouldHaveBottomSeparator
|
|
|
|
|
{
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
|
OWSAssert(thread);
|
|
|
|
|
OWSAssert(contactsManager);
|
|
|
|
|
OWSAssert(blockedPhoneNumberSet);
|
|
|
|
|
|
|
|
|
|
// TODO: Honor shouldHaveBottomSeparator.
|
|
|
|
|
|
|
|
|
|
self.thread = thread;
|
|
|
|
|
self.contactsManager = contactsManager;
|
|
|
|
|
|
|
|
|
|
BOOL isBlocked = NO;
|
|
|
|
|
if (!thread.isGroupThread) {
|
|
|
|
|
NSString *contactIdentifier = thread.contactIdentifier;
|
|
|
|
|
isBlocked = [blockedPhoneNumberSet containsObject:contactIdentifier];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSMutableAttributedString *snippetText = [NSMutableAttributedString new];
|
|
|
|
|
if (isBlocked) {
|
|
|
|
|
// If thread is blocked, don't show a snippet or mute status.
|
|
|
|
|
[snippetText appendAttributedString:[[NSAttributedString alloc] initWithString:NSLocalizedString(@"HOME_VIEW_BLOCKED_CONTACT_CONVERSATION",
|
|
|
|
|
@"A label for conversations with blocked users.")
|
|
|
|
|
attributes:@{
|
|
|
|
|
NSFontAttributeName : [UIFont ows_mediumFontWithSize:12],
|
|
|
|
|
NSForegroundColorAttributeName : [UIColor ows_blackColor],
|
|
|
|
|
}]];
|
|
|
|
|
} else {
|
|
|
|
|
if ([thread isMuted]) {
|
|
|
|
|
[snippetText appendAttributedString:[[NSAttributedString alloc]
|
|
|
|
|
initWithString:@"\ue067 "
|
|
|
|
|
attributes:@{
|
|
|
|
|
NSFontAttributeName : [UIFont ows_elegantIconsFont:9.f],
|
|
|
|
|
NSForegroundColorAttributeName : (thread.hasUnreadMessages
|
|
|
|
|
? [UIColor colorWithWhite:0.1f alpha:1.f]
|
|
|
|
|
: [UIColor lightGrayColor]),
|
|
|
|
|
}]];
|
|
|
|
|
}
|
|
|
|
|
NSString *displayableText = thread.lastMessageLabel.filterStringForDisplay;
|
|
|
|
|
if (displayableText) {
|
|
|
|
|
[snippetText appendAttributedString:[[NSAttributedString alloc]
|
|
|
|
|
initWithString:displayableText
|
|
|
|
|
attributes:@{
|
|
|
|
|
NSFontAttributeName : (thread.hasUnreadMessages
|
|
|
|
|
? [UIFont ows_mediumFontWithSize:12]
|
|
|
|
|
: [UIFont ows_regularFontWithSize:12]),
|
|
|
|
|
NSForegroundColorAttributeName :
|
|
|
|
|
(thread.hasUnreadMessages ? [UIColor ows_blackColor]
|
|
|
|
|
: [UIColor lightGrayColor]),
|
|
|
|
|
}]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSAttributedString *attributedDate = [self dateAttributedString:thread.lastMessageDate];
|
|
|
|
|
NSUInteger unreadCount = [[OWSMessageUtils sharedManager] unreadMessagesInThread:thread];
|
|
|
|
|
|
|
|
|
|
BOOL hasUnreadMessages = thread.hasUnreadMessages;
|
|
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
|
selector:@selector(otherUsersProfileDidChange:)
|
|
|
|
@ -215,20 +191,29 @@ const NSUInteger kAvatarViewDiameter = 52;
|
|
|
|
|
[self updateNameLabel];
|
|
|
|
|
[self updateAvatarView];
|
|
|
|
|
|
|
|
|
|
self.snippetLabel.attributedText = snippetText;
|
|
|
|
|
self.timeLabel.attributedText = attributedDate;
|
|
|
|
|
self.snippetLabel.attributedText =
|
|
|
|
|
[self attributedSnippetForThread:thread blockedPhoneNumberSet:blockedPhoneNumberSet];
|
|
|
|
|
self.timeLabel.attributedText = [self attributedStringForDate:thread.lastMessageDate];
|
|
|
|
|
|
|
|
|
|
self.separatorInset = UIEdgeInsetsMake(0, self.avatarSize * 1.5f, 0, 0);
|
|
|
|
|
self.separatorInset
|
|
|
|
|
= UIEdgeInsetsMake(0, kHomeViewAvatarSize + kHomeViewCellHMargin + kHomeViewAvatarHSpacing, 0, 0);
|
|
|
|
|
|
|
|
|
|
_timeLabel.textColor = thread.hasUnreadMessages ? [UIColor ows_materialBlueColor] : [UIColor ows_darkGrayColor];
|
|
|
|
|
self.timeLabel.textColor = hasUnreadMessages ? [UIColor ows_materialBlueColor] : [UIColor ows_darkGrayColor];
|
|
|
|
|
|
|
|
|
|
NSUInteger unreadCount = [[OWSMessageUtils sharedManager] unreadMessagesInThread:thread];
|
|
|
|
|
if (unreadCount > 0) {
|
|
|
|
|
self.unreadBadge.hidden = NO;
|
|
|
|
|
self.unreadLabel.hidden = NO;
|
|
|
|
|
self.unreadLabel.text = [OWSFormat formatInt:MIN(99, (int)unreadCount)];
|
|
|
|
|
|
|
|
|
|
[self.viewConstraints addObjectsFromArray:@[
|
|
|
|
|
[self.unreadBadge autoPinLeadingToTrailingEdgeOfView:self.payloadView offset:4.f],
|
|
|
|
|
]];
|
|
|
|
|
} else {
|
|
|
|
|
self.unreadBadge.hidden = YES;
|
|
|
|
|
self.unreadLabel.hidden = YES;
|
|
|
|
|
|
|
|
|
|
[self.viewConstraints addObjectsFromArray:@[
|
|
|
|
|
[self.payloadView autoPinTrailingToSuperviewMarginWithInset:kHomeViewCellHMargin],
|
|
|
|
|
]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -249,46 +234,115 @@ const NSUInteger kAvatarViewDiameter = 52;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.avatarView.image =
|
|
|
|
|
[OWSAvatarBuilder buildImageForThread:thread diameter:kAvatarViewDiameter contactsManager:contactsManager];
|
|
|
|
|
[OWSAvatarBuilder buildImageForThread:thread diameter:kHomeViewAvatarSize contactsManager:contactsManager];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSAttributedString *)attributedSnippetForThread:(TSThread *)thread
|
|
|
|
|
blockedPhoneNumberSet:(NSSet<NSString *> *)blockedPhoneNumberSet
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(thread);
|
|
|
|
|
|
|
|
|
|
BOOL isBlocked = NO;
|
|
|
|
|
if (!thread.isGroupThread) {
|
|
|
|
|
NSString *contactIdentifier = thread.contactIdentifier;
|
|
|
|
|
isBlocked = [blockedPhoneNumberSet containsObject:contactIdentifier];
|
|
|
|
|
}
|
|
|
|
|
BOOL hasUnreadMessages = thread.hasUnreadMessages;
|
|
|
|
|
|
|
|
|
|
NSMutableAttributedString *snippetText = [NSMutableAttributedString new];
|
|
|
|
|
if (isBlocked) {
|
|
|
|
|
// If thread is blocked, don't show a snippet or mute status.
|
|
|
|
|
[snippetText
|
|
|
|
|
appendAttributedString:[[NSAttributedString alloc]
|
|
|
|
|
initWithString:NSLocalizedString(@"HOME_VIEW_BLOCKED_CONTACT_CONVERSATION",
|
|
|
|
|
@"A label for conversations with blocked users.")
|
|
|
|
|
attributes:@{
|
|
|
|
|
NSFontAttributeName : self.snippetFont.ows_medium,
|
|
|
|
|
NSForegroundColorAttributeName : [UIColor ows_blackColor],
|
|
|
|
|
}]];
|
|
|
|
|
} else {
|
|
|
|
|
if ([thread isMuted]) {
|
|
|
|
|
[snippetText appendAttributedString:[[NSAttributedString alloc]
|
|
|
|
|
initWithString:@"\ue067 "
|
|
|
|
|
attributes:@{
|
|
|
|
|
NSFontAttributeName : [UIFont ows_elegantIconsFont:9.f],
|
|
|
|
|
NSForegroundColorAttributeName : (hasUnreadMessages
|
|
|
|
|
? [UIColor colorWithWhite:0.1f alpha:1.f]
|
|
|
|
|
: [UIColor lightGrayColor]),
|
|
|
|
|
}]];
|
|
|
|
|
}
|
|
|
|
|
NSString *displayableText = thread.lastMessageLabel.filterStringForDisplay;
|
|
|
|
|
if (displayableText) {
|
|
|
|
|
[snippetText appendAttributedString:[[NSAttributedString alloc]
|
|
|
|
|
initWithString:displayableText
|
|
|
|
|
attributes:@{
|
|
|
|
|
NSFontAttributeName :
|
|
|
|
|
(hasUnreadMessages ? self.snippetFont.ows_medium
|
|
|
|
|
: self.snippetFont),
|
|
|
|
|
NSForegroundColorAttributeName :
|
|
|
|
|
(hasUnreadMessages ? [UIColor ows_blackColor]
|
|
|
|
|
: [UIColor lightGrayColor]),
|
|
|
|
|
}]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return snippetText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Date formatting
|
|
|
|
|
|
|
|
|
|
- (NSAttributedString *)dateAttributedString:(nullable NSDate *)date
|
|
|
|
|
- (NSAttributedString *)attributedStringForDate:(nullable NSDate *)date
|
|
|
|
|
{
|
|
|
|
|
if (date == nil) {
|
|
|
|
|
OWSProdLogAndFail(@"%@ date was unexpectedly nil", self.logTag);
|
|
|
|
|
return [NSAttributedString new];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSString *timeString;
|
|
|
|
|
|
|
|
|
|
if ([DateUtil dateIsToday:date]) {
|
|
|
|
|
timeString = [[DateUtil timeFormatter] stringFromDate:date];
|
|
|
|
|
} else {
|
|
|
|
|
timeString = [[DateUtil dateFormatter] stringFromDate:date];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSDateFormatter *formatter = ([DateUtil dateIsToday:date] ? [DateUtil timeFormatter] : [DateUtil dateFormatter]);
|
|
|
|
|
NSString *timeString = [formatter stringFromDate:date];
|
|
|
|
|
OWSAssert(timeString);
|
|
|
|
|
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:timeString];
|
|
|
|
|
return [[NSAttributedString alloc] initWithString:timeString
|
|
|
|
|
attributes:@{
|
|
|
|
|
NSForegroundColorAttributeName : [UIColor ows_darkGrayColor],
|
|
|
|
|
NSFontAttributeName : self.dateTimeFont,
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[attributedString addAttribute:NSForegroundColorAttributeName
|
|
|
|
|
value:[UIColor ows_darkGrayColor]
|
|
|
|
|
range:NSMakeRange(0, timeString.length)];
|
|
|
|
|
#pragma mark - Constants
|
|
|
|
|
|
|
|
|
|
- (UIFont *)dateTimeFont
|
|
|
|
|
{
|
|
|
|
|
return [UIFont ows_dynamicTypeFootnoteFont];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[attributedString addAttribute:NSFontAttributeName
|
|
|
|
|
value:[UIFont ows_regularFontWithSize:TIME_LABEL_SIZE]
|
|
|
|
|
range:NSMakeRange(0, timeString.length)];
|
|
|
|
|
- (UIFont *)snippetFont
|
|
|
|
|
{
|
|
|
|
|
return [UIFont ows_dynamicTypeBodyFont];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIFont *)nameFont
|
|
|
|
|
{
|
|
|
|
|
return [UIFont ows_dynamicTypeBodyFont].ows_medium;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return attributedString;
|
|
|
|
|
// Used for profile names.
|
|
|
|
|
- (UIFont *)nameSecondaryFont
|
|
|
|
|
{
|
|
|
|
|
return [UIFont ows_dynamicTypeFootnoteFont];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Reuse
|
|
|
|
|
|
|
|
|
|
- (void)prepareForReuse
|
|
|
|
|
{
|
|
|
|
|
[super prepareForReuse];
|
|
|
|
|
|
|
|
|
|
[NSLayoutConstraint deactivateConstraints:self.viewConstraints];
|
|
|
|
|
[self.viewConstraints removeAllObjects];
|
|
|
|
|
|
|
|
|
|
self.thread = nil;
|
|
|
|
|
self.contactsManager = nil;
|
|
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -302,7 +356,7 @@ const NSUInteger kAvatarViewDiameter = 52;
|
|
|
|
|
if (recipientId.length == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (![self.thread isKindOfClass:[TSContactThread class]]) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -310,12 +364,12 @@ const NSUInteger kAvatarViewDiameter = 52;
|
|
|
|
|
if (![self.thread.contactIdentifier isEqualToString:recipientId]) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[self updateNameLabel];
|
|
|
|
|
[self updateAvatarView];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)updateNameLabel
|
|
|
|
|
- (void)updateNameLabel
|
|
|
|
|
{
|
|
|
|
|
OWSAssertIsOnMainThread();
|
|
|
|
|
|
|
|
|
@ -325,14 +379,14 @@ const NSUInteger kAvatarViewDiameter = 52;
|
|
|
|
|
self.nameLabel.attributedText = nil;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OWSContactsManager *contactsManager = self.contactsManager;
|
|
|
|
|
if (contactsManager == nil) {
|
|
|
|
|
OWSFail(@"%@ contacts manager should not be nil", self.logTag);
|
|
|
|
|
self.nameLabel.attributedText = nil;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NSAttributedString *name;
|
|
|
|
|
if (thread.isGroupThread) {
|
|
|
|
|
if (thread.name.length == 0) {
|
|
|
|
@ -341,12 +395,11 @@ const NSUInteger kAvatarViewDiameter = 52;
|
|
|
|
|
name = [[NSAttributedString alloc] initWithString:thread.name];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
name = [contactsManager
|
|
|
|
|
attributedStringForConversationTitleWithPhoneIdentifier:thread.contactIdentifier
|
|
|
|
|
primaryFont:self.nameLabel.font
|
|
|
|
|
secondaryFont:[UIFont ows_dynamicTypeFootnoteFont]];
|
|
|
|
|
name = [contactsManager attributedStringForConversationTitleWithPhoneIdentifier:thread.contactIdentifier
|
|
|
|
|
primaryFont:self.nameFont
|
|
|
|
|
secondaryFont:self.nameSecondaryFont];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.nameLabel.attributedText = name;
|
|
|
|
|
}
|
|
|
|
|
|