Update home and group cells' dependencies.

pull/1/head
Matthew Chen 7 years ago
parent 763acae158
commit 25ed886e72

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

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

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

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

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

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

Loading…
Cancel
Save