From 96f0ab215c9254842781a681fc4ac039744e35ea Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 23 Aug 2017 16:41:31 -0400 Subject: [PATCH] wip --- .../ConversationView/MessagesViewController.m | 5 + .../src/ViewControllers/InboxTableViewCell.m | 99 +++++++++++++++---- 2 files changed, 87 insertions(+), 17 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index 66f2279f1..ffe90fd45 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -360,6 +360,11 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { NSString *recipientId = notification.userInfo[kNSNotificationKey_ProfileRecipientId]; OWSAssert(recipientId.length > 0); if (recipientId.length > 0 && [self.thread.recipientIdentifiers containsObject:recipientId]) { + if ([self.thread isKindOfClass:[TSContactThread class]]) { + // update title with profile name + [self setNavigationTitle]; + } + // Reload all cells. [self resetContentAndLayout]; } diff --git a/Signal/src/ViewControllers/InboxTableViewCell.m b/Signal/src/ViewControllers/InboxTableViewCell.m index 4e6bdb917..eb6698f44 100644 --- a/Signal/src/ViewControllers/InboxTableViewCell.m +++ b/Signal/src/ViewControllers/InboxTableViewCell.m @@ -31,7 +31,8 @@ const NSUInteger kAvatarViewDiameter = 52; @property (nonatomic) UIView *unreadBadge; @property (nonatomic) UILabel *unreadLabel; -@property (nonatomic) NSString *threadId; +@property (nonatomic) TSThread *thread; +@property (nonatomic) OWSContactsManager *contactsManager; @end @@ -158,13 +159,15 @@ const NSUInteger kAvatarViewDiameter = 52; OWSAssert(contactsManager); OWSAssert(blockedPhoneNumberSet); + self.thread = thread; + self.contactsManager = contactsManager; + BOOL isBlocked = NO; if (!thread.isGroupThread) { NSString *contactIdentifier = thread.contactIdentifier; isBlocked = [blockedPhoneNumberSet containsObject:contactIdentifier]; } - - self.threadId = thread.uniqueId; + NSMutableAttributedString *snippetText = [NSMutableAttributedString new]; if (isBlocked) { // If thread is blocked, don't show a snippet or mute status. @@ -203,20 +206,13 @@ const NSUInteger kAvatarViewDiameter = 52; NSAttributedString *attributedDate = [self dateAttributedString:thread.lastMessageDate]; NSUInteger unreadCount = [[TSMessagesManager sharedManager] unreadMessagesInThread:thread]; - NSAttributedString *name; - if (thread.isGroupThread) { - if (thread.name.length == 0) { - name = [[NSAttributedString alloc] initWithString:NSLocalizedString(@"NEW_GROUP_DEFAULT_TITLE", @"")]; - } else { - name = [[NSAttributedString alloc] initWithString:thread.name]; - } - } else { - name = [contactsManager attributedStringForConversationTitleWithPhoneIdentifier:thread.contactIdentifier - primaryFont:self.nameLabel.font - secondaryFont:[UIFont ows_footnoteFont]]; - } - - self.nameLabel.attributedText = name; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(otherUsersProfileDidChange:) + name:kNSNotificationName_OtherUsersProfileDidChange + object:nil]; + [self updateNameLabel]; + self.snippetLabel.attributedText = snippetText; self.timeLabel.attributedText = attributedDate; self.avatarView.image = nil; @@ -266,9 +262,78 @@ const NSUInteger kAvatarViewDiameter = 52; - (void)prepareForReuse { + [[NSNotificationCenter defaultCenter] removeObserver:self]; [super prepareForReuse]; } +#pragma mark - Name + +- (void)otherUsersProfileDidChange:(NSNotification *)notification +{ + OWSAssert([NSThread isMainThread]); + + NSString *recipientId = notification.userInfo[kNSNotificationKey_ProfileRecipientId]; + if (recipientId.length == 0) { + return; + } + + if (![self.thread isKindOfClass:[TSContactThread class]]) { + return; + } + + if (![self.thread.contactIdentifier isEqualToString:recipientId]) { + return; + } + + [self updateNameLabel]; +} + +-(void)updateNameLabel +{ + AssertIsOnMainThread(); + + TSThread *thread = self.thread; + if (thread == nil) { + OWSFail(@"%@ thread should not be nil", self.logTag); + 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) { + name = [[NSAttributedString alloc] initWithString:NSLocalizedString(@"NEW_GROUP_DEFAULT_TITLE", @"")]; + } else { + name = [[NSAttributedString alloc] initWithString:thread.name]; + } + } else { + name = [contactsManager attributedStringForConversationTitleWithPhoneIdentifier:thread.contactIdentifier + primaryFont:self.nameLabel.font + secondaryFont:[UIFont ows_footnoteFont]]; + } + + self.nameLabel.attributedText = name; +} + +#pragma mark - Logging + ++ (NSString *)logTag +{ + return [NSString stringWithFormat:@"[%@]", self.class]; +} + +- (NSString *)logTag +{ + return self.class.logTag; +} + @end NS_ASSUME_NONNULL_END