Update home and group cells' dependencies.

This commit is contained in:
Matthew Chen 2018-10-25 09:41:56 -04:00
parent 763acae158
commit 25ed886e72
6 changed files with 26 additions and 32 deletions

View File

@ -216,7 +216,7 @@ class ConversationSearchViewController: UITableViewController, BlockListCacheDel
owsFailDebug("searchResult was unexpectedly nil")
return UITableViewCell()
}
cell.configure(withThread: searchResult.thread, contactsManager: contactsManager, isBlocked: isBlocked(thread: searchResult.thread))
cell.configure(withThread: searchResult.thread, isBlocked: isBlocked(thread: searchResult.thread))
return cell
case .contacts:
guard let cell = tableView.dequeueReusableCell(withIdentifier: ContactTableViewCell.reuseIdentifier()) as? ContactTableViewCell else {
@ -265,7 +265,6 @@ class ConversationSearchViewController: UITableViewController, BlockListCacheDel
}
cell.configure(withThread: searchResult.thread,
contactsManager: contactsManager,
isBlocked: isBlocked(thread: searchResult.thread),
overrideSnippet: overrideSnippet,
overrideDate: overrideDate)

View File

@ -4,7 +4,6 @@
NS_ASSUME_NONNULL_BEGIN
@class OWSContactsManager;
@class ThreadViewModel;
@class YapDatabaseReadTransaction;
@ -13,11 +12,9 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)cellReuseIdentifier;
- (void)configureWithThread:(ThreadViewModel *)thread
contactsManager:(OWSContactsManager *)contactsManager
isBlocked:(BOOL)isBlocked;
- (void)configureWithThread:(ThreadViewModel *)thread
contactsManager:(OWSContactsManager *)contactsManager
isBlocked:(BOOL)isBlocked
overrideSnippet:(nullable NSAttributedString *)overrideSnippet
overrideDate:(nullable NSDate *)overrideDate;

View File

@ -27,7 +27,6 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) UILabel *unreadLabel;
@property (nonatomic, nullable) ThreadViewModel *thread;
@property (nonatomic, nullable) OWSContactsManager *contactsManager;
@property (nonatomic, readonly) NSMutableArray<NSLayoutConstraint *> *viewConstraints;
@ -37,6 +36,17 @@ NS_ASSUME_NONNULL_BEGIN
@implementation HomeViewCell
#pragma mark - Dependencies
- (OWSContactsManager *)contactsManager
{
OWSAssertDebug(Environment.shared.contactsManager);
return Environment.shared.contactsManager;
}
#pragma mark -
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(nullable NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
@ -167,30 +177,25 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)configureWithThread:(ThreadViewModel *)thread
contactsManager:(OWSContactsManager *)contactsManager
isBlocked:(BOOL)isBlocked
{
[self configureWithThread:thread
contactsManager:contactsManager
isBlocked:isBlocked
overrideSnippet:nil
overrideDate:nil];
}
- (void)configureWithThread:(ThreadViewModel *)thread
contactsManager:(OWSContactsManager *)contactsManager
isBlocked:(BOOL)isBlocked
overrideSnippet:(nullable NSAttributedString *)overrideSnippet
overrideDate:(nullable NSDate *)overrideDate
{
OWSAssertIsOnMainThread();
OWSAssertDebug(thread);
OWSAssertDebug(contactsManager);
[OWSTableItem configureCell:self];
self.thread = thread;
self.contactsManager = contactsManager;
BOOL hasUnreadMessages = thread.hasUnreadMessages;
@ -321,13 +326,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateAvatarView
{
OWSContactsManager *contactsManager = self.contactsManager;
if (contactsManager == nil) {
OWSFailDebug(@"contactsManager should not be nil");
self.avatarView.image = nil;
return;
}
ThreadViewModel *thread = self.thread;
if (thread == nil) {
OWSFailDebug(@"thread should not be nil");
@ -444,7 +442,6 @@ NS_ASSUME_NONNULL_BEGIN
[self.viewConstraints removeAllObjects];
self.thread = nil;
self.contactsManager = nil;
self.avatarView.image = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self];
@ -487,13 +484,6 @@ NS_ASSUME_NONNULL_BEGIN
return;
}
OWSContactsManager *contactsManager = self.contactsManager;
if (contactsManager == nil) {
OWSFailDebug(@"contacts manager should not be nil");
self.nameLabel.attributedText = nil;
return;
}
NSAttributedString *name;
if (thread.isGroupThread) {
if (thread.name.length == 0) {
@ -502,9 +492,9 @@ NS_ASSUME_NONNULL_BEGIN
name = [[NSAttributedString alloc] initWithString:thread.name];
}
} else {
name = [contactsManager attributedContactOrProfileNameForPhoneIdentifier:thread.contactIdentifier
primaryFont:self.nameFont
secondaryFont:self.nameSecondaryFont];
name = [self.contactsManager attributedContactOrProfileNameForPhoneIdentifier:thread.contactIdentifier
primaryFont:self.nameFont
secondaryFont:self.nameSecondaryFont];
}
self.nameLabel.attributedText = name;

View File

@ -871,7 +871,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
ThreadViewModel *thread = [self threadViewModelForIndexPath:indexPath];
BOOL isBlocked = [self.blocklistCache isThreadBlocked:thread.threadRecord];
[cell configureWithThread:thread contactsManager:self.contactsManager isBlocked:isBlocked];
[cell configureWithThread:thread isBlocked:isBlocked];
return cell;
}

View File

@ -589,7 +589,7 @@ NS_ASSUME_NONNULL_BEGIN
[groupSection addItem:[OWSTableItem
itemWithCustomCellBlock:^{
GroupTableViewCell *cell = [GroupTableViewCell new];
[cell configureWithThread:thread contactsManager:helper.contactsManager];
[cell configureWithThread:thread];
return cell;
}
customRowHeight:UITableViewAutomaticDimension

View File

@ -7,6 +7,14 @@ import SignalServiceKit
@objc class GroupTableViewCell: UITableViewCell {
// MARK: - Dependencies
private var contactsManager: OWSContactsManager {
return Environment.shared.contactsManager
}
// MARK: -
private let avatarView = AvatarImageView()
private let nameLabel = UILabel()
private let subtitleLabel = UILabel()
@ -43,7 +51,7 @@ import SignalServiceKit
}
@objc
public func configure(thread: TSGroupThread, contactsManager: OWSContactsManager) {
public func configure(thread: TSGroupThread) {
OWSTableItem.configureCell(self)
if let groupName = thread.groupModel.groupName, !groupName.isEmpty {