Use BlockListCache where possible

pull/1/head
Michael Kirk 6 years ago
parent 2eca462efc
commit fd492f379a

@ -10,7 +10,7 @@ protocol ConversationSearchViewDelegate: class {
}
@objc
class ConversationSearchViewController: UITableViewController {
class ConversationSearchViewController: UITableViewController, BlockListCacheDelegate {
@objc
public weak var delegate: ConversationSearchViewDelegate?
@ -48,15 +48,16 @@ class ConversationSearchViewController: UITableViewController {
private var hasThemeChanged = false
var blockingManager: OWSBlockingManager {
return OWSBlockingManager.shared()
}
var blockListCache: BlockListCache!
// MARK: View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
blockListCache = BlockListCache()
blockListCache.startObservingAndSyncState(delegate: self)
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 60
tableView.separatorColor = Theme.hairlineColor
@ -337,6 +338,12 @@ class ConversationSearchViewController: UITableViewController {
}
}
// MARK: BlockListCacheDelegate
func blockListCacheDidUpdate(_ blocklistCache: BlockListCache) {
refreshSearchResults()
}
// MARK: Update Search Results
var refreshTimer: Timer?
@ -394,7 +401,7 @@ class ConversationSearchViewController: UITableViewController {
// MARK: -
private func isBlocked(thread: ThreadViewModel) -> Bool {
return self.blockingManager.isThreadBlocked(thread.threadRecord)
return self.blockListCache.isBlocked(thread: thread.threadRecord)
}
}

@ -158,10 +158,6 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
[ExperienceUpgradeFinder sharedManager];
#pragma GCC diagnostic pop
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(blockListDidChange:)
name:kNSNotificationName_BlockListDidChange
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(signalAccountsDidChange:)
name:OWSContactsManagerSignalAccountsDidChangeNotification
@ -207,13 +203,6 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
#pragma mark - Notifications
- (void)blockListDidChange:(id)notification
{
OWSAssertIsOnMainThread();
[self reloadTableViewData];
}
- (void)signalAccountsDidChange:(id)notification
{
OWSAssertIsOnMainThread();

@ -19,7 +19,7 @@
NS_ASSUME_NONNULL_BEGIN
@interface ContactsViewHelper ()
@interface ContactsViewHelper () <OWSBlockListCacheDelegate>
// This property is a cached value that is lazy-populated.
@property (nonatomic, nullable) NSArray<Contact *> *nonSignalContacts;
@ -27,8 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) NSDictionary<NSString *, SignalAccount *> *signalAccountMap;
@property (nonatomic) NSArray<SignalAccount *> *signalAccounts;
@property (nonatomic) NSArray<NSString *> *blockedPhoneNumbers;
@property (nonatomic) NSArray<NSData *> *blockedGroupIds;
@property (nonatomic, readonly) OWSBlockListCache *blockListCache;
@property (nonatomic) BOOL shouldNotifyDelegateOfUpdatedContacts;
@property (nonatomic) BOOL hasUpdatedContactsAtLeastOnce;
@ -52,8 +51,8 @@ NS_ASSUME_NONNULL_BEGIN
_delegate = delegate;
_blockingManager = [OWSBlockingManager sharedManager];
_blockedPhoneNumbers = [_blockingManager blockedPhoneNumbers];
_blockedGroupIds = [_blockingManager blockedGroupIds];
_blockListCache = [OWSBlockListCache new];
[_blockListCache startObservingAndSyncStateWithDelegate:self];
_conversationSearcher = ConversationSearcher.shared;
@ -76,10 +75,6 @@ NS_ASSUME_NONNULL_BEGIN
selector:@selector(signalAccountsDidChange:)
name:OWSContactsManagerSignalAccountsDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(blockListDidChange:)
name:kNSNotificationName_BlockListDidChange
object:nil];
}
- (void)dealloc
@ -94,16 +89,6 @@ NS_ASSUME_NONNULL_BEGIN
[self updateContacts];
}
- (void)blockListDidChange:(NSNotification *)notification
{
OWSAssertIsOnMainThread();
self.blockedPhoneNumbers = self.blockingManager.blockedPhoneNumbers;
self.blockedGroupIds = self.blockingManager.blockedGroupIds;
[self updateContacts];
}
#pragma mark - Contacts
- (nullable SignalAccount *)fetchSignalAccountForRecipientId:(NSString *)recipientId
@ -162,14 +147,14 @@ NS_ASSUME_NONNULL_BEGIN
{
OWSAssertIsOnMainThread();
return [_blockedPhoneNumbers containsObject:recipientId];
return [self.blockListCache isRecipientIdBlocked:recipientId];
}
- (BOOL)isGroupIdBlocked:(NSData *)groupId
{
OWSAssertIsOnMainThread();
return [self.blockedGroupIds containsObject:groupId];
return [self.blockListCache isGroupIdBlocked:groupId];
}
- (BOOL)isThreadBlocked:(TSThread *)thread
@ -434,6 +419,12 @@ NS_ASSUME_NONNULL_BEGIN
[fromViewController presentViewController:modal animated:YES completion:nil];
}
- (void)blockListCacheDidUpdate:(OWSBlockListCache *)blocklistCache
{
OWSAssertIsOnMainThread();
[self updateContacts];
}
@end
NS_ASSUME_NONNULL_END

Loading…
Cancel
Save