WIP: ContactViewHelper incorporates group blocking

-[ ] UI
  -[ ] Conversation Settings
    -[x] Show switch for group
    -[ ] localize
    -[ ] migrate existing localizations? (nice to have)
    -[ ] can view conversation settings (but not edit them) in left group
    -[ ] special block copy for groups
    -[ ] special unblock copy for groups
  -[ ] ConversationViewHelper
   -[x] Track blocked groups
   -[ ] HomeView
   -[ ] ConversationView
   -[ ] Any others?
   -[ ] Rename? Extract BlockList cache?
  -[ ] Block List
    -[ ] Group Section
    -[ ] Unblock group
  -[ ] Interstitial interacting with blocked threads (e.g. thread picker)
    -[ ] BlockListUIUtils w/ thread
        -[x] Block
        -[x] Unblock
        -[ ] Replace usages where possible
        -[x] block manager
-[ ] Sync
  -[x] tentative protos
  -[ ] confirm protos w/ team
  -[x] send new protos
-[ ] Message Processing
  -[ ] Drop messages from blocked groups
This commit is contained in:
Michael Kirk 2018-09-09 12:11:41 -05:00
parent b282d51da0
commit eadb04efcc
11 changed files with 57 additions and 20 deletions

View File

@ -293,8 +293,8 @@ typedef enum : NSUInteger {
- (void)addNotificationListeners
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(blockedPhoneNumbersDidChange:)
name:kNSNotificationName_BlockedPhoneNumbersDidChange
selector:@selector(blockListDidChange:)
name:kNSNotificationName_BlockListDidChange
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(windowManagerCallDidChange:)
@ -410,7 +410,7 @@ typedef enum : NSUInteger {
}
}
- (void)blockedPhoneNumbersDidChange:(id)notification
- (void)blockListDidChange:(id)notification
{
OWSAssertIsOnMainThread();
@ -865,6 +865,7 @@ typedef enum : NSUInteger {
}
NSString *blockStateMessage = nil;
// FIXME - group blocking
if ([self isBlockedContactConversation]) {
blockStateMessage = NSLocalizedString(
@"MESSAGES_VIEW_CONTACT_BLOCKED", @"Indicates that this 1:1 conversation has been blocked.");

View File

@ -55,6 +55,7 @@ class ConversationSearchViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
// MJK TODO
let blockingManager = OWSBlockingManager.shared()
blockedPhoneNumberSet = Set(blockingManager.blockedPhoneNumbers())

View File

@ -347,6 +347,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(thread);
BOOL isBlocked = NO;
// FIXME
if (!thread.isGroupThread) {
NSString *contactIdentifier = thread.contactIdentifier;
isBlocked = [blockedPhoneNumberSet containsObject:contactIdentifier];

View File

@ -159,8 +159,8 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
#pragma GCC diagnostic pop
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(blockedPhoneNumbersDidChange:)
name:kNSNotificationName_BlockedPhoneNumbersDidChange
selector:@selector(blockListDidChange:)
name:kNSNotificationName_BlockListDidChange
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(signalAccountsDidChange:)
@ -207,12 +207,14 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
#pragma mark - Notifications
- (void)blockedPhoneNumbersDidChange:(id)notification
- (void)blockListDidChange:(id)notification
{
OWSAssertIsOnMainThread();
_blockedPhoneNumberSet = [NSSet setWithArray:[_blockingManager blockedPhoneNumbers]];
// FIXME rather than tracking blockedPhoneNumberSet, use ContactViewHelper?
[self reloadTableViewData];
}

View File

@ -17,7 +17,6 @@
#import <SignalMessaging/UIView+OWS.h>
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/ContactsUpdater.h>
#import <SignalServiceKit/OWSBlockingManager.h>
#import <SignalServiceKit/PhoneNumberUtil.h>
#import <SignalServiceKit/SignalAccount.h>
#import <SignalServiceKit/TSAccountManager.h>

View File

@ -197,12 +197,10 @@ NS_ASSUME_NONNULL_BEGIN
// instead of HomeViewCell to present contacts and threads.
ContactTableViewCell *cell = [ContactTableViewCell new];
if ([thread isKindOfClass:[TSContactThread class]]) {
BOOL isBlocked = [helper isRecipientIdBlocked:thread.contactIdentifier];
if (isBlocked) {
cell.accessoryMessage = NSLocalizedString(
@"CONTACT_CELL_IS_BLOCKED", @"An indicator that a contact has been blocked.");
}
BOOL isBlocked = [helper isThreadBlocked:thread];
if (isBlocked) {
cell.accessoryMessage = NSLocalizedString(
@"CONTACT_CELL_IS_BLOCKED", @"An indicator that a contact has been blocked.");
}
[cell configureWithThread:thread contactsManager:helper.contactsManager];

View File

@ -46,6 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
// Useful to differentiate between having no signal accounts vs. haven't checked yet
@property (nonatomic, readonly) BOOL hasUpdatedContactsAtLeastOnce;
// MJK TODO Can we remove? Do we need blockedGroupList?
@property (nonatomic, readonly) NSArray<NSString *> *blockedPhoneNumbers;
// Suitable when the user tries to perform an action which is not possible due to the user having
@ -64,6 +65,8 @@ NS_ASSUME_NONNULL_BEGIN
// is only safe to be called on the main thread.
- (BOOL)isRecipientIdBlocked:(NSString *)recipientId;
// This method is faster than OWSBlockingManager but
// is only safe to be called on the main thread.
- (BOOL)isThreadBlocked:(TSThread *)thread;
// NOTE: This method uses a transaction.

View File

@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) NSArray<SignalAccount *> *signalAccounts;
@property (nonatomic) NSArray<NSString *> *blockedPhoneNumbers;
@property (nonatomic) NSArray<NSData *> *blockedGroupIds;
@property (nonatomic) BOOL shouldNotifyDelegateOfUpdatedContacts;
@property (nonatomic) BOOL hasUpdatedContactsAtLeastOnce;
@ -52,6 +53,8 @@ NS_ASSUME_NONNULL_BEGIN
_blockingManager = [OWSBlockingManager sharedManager];
_blockedPhoneNumbers = [_blockingManager blockedPhoneNumbers];
_blockedGroupIds = [_blockingManager blockedGroupIds];
_conversationSearcher = ConversationSearcher.shared;
_contactsManager = [Environment current].contactsManager;
@ -74,8 +77,8 @@ NS_ASSUME_NONNULL_BEGIN
name:OWSContactsManagerSignalAccountsDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(blockedPhoneNumbersDidChange:)
name:kNSNotificationName_BlockedPhoneNumbersDidChange
selector:@selector(blockListDidChange:)
name:kNSNotificationName_BlockListDidChange
object:nil];
}
@ -91,11 +94,12 @@ NS_ASSUME_NONNULL_BEGIN
[self updateContacts];
}
- (void)blockedPhoneNumbersDidChange:(id)notification
- (void)blockListDidChange:(NSNotification *)notification
{
OWSAssertIsOnMainThread();
self.blockedPhoneNumbers = [_blockingManager blockedPhoneNumbers];
self.blockedPhoneNumbers = self.blockingManager.blockedPhoneNumbers;
self.blockedGroupIds = self.blockingManager.blockedGroupIds;
[self updateContacts];
}
@ -161,6 +165,27 @@ NS_ASSUME_NONNULL_BEGIN
return [_blockedPhoneNumbers containsObject:recipientId];
}
- (BOOL)isGroupIdBlocked:(NSData *)groupId
{
OWSAssertIsOnMainThread();
return [self.blockedGroupIds containsObject:groupId];
}
- (BOOL)isThreadBlocked:(TSThread *)thread
{
if ([thread isKindOfClass:[TSContactThread class]]) {
TSContactThread *contactThread = (TSContactThread *)thread;
return [self isRecipientIdBlocked:contactThread.contactIdentifier];
} else if ([thread isKindOfClass:[TSGroupThread class]]) {
TSGroupThread *groupThread = (TSGroupThread *)thread;
return [self isGroupIdBlocked:groupThread.groupModel.groupId];
} else {
OWSFail(@"%@ failure: unexpected thread: %@", self.logTag, thread.class);
return NO;
}
}
- (void)updateContacts
{
OWSAssertIsOnMainThread();

View File

@ -347,6 +347,9 @@ NS_ASSUME_NONNULL_BEGIN
shouldHaveAddToContactsOffer = NO;
// Only create block offers in 1:1 conversations.
shouldHaveBlockOffer = NO;
// MJK TODO - any conditions under which we'd make a block offer for groups?
// Only create profile whitelist offers in 1:1 conversations.
shouldHaveAddToProfileWhitelistOffer = NO;
} else {
@ -665,6 +668,10 @@ NS_ASSUME_NONNULL_BEGIN
if (![OWSProfileManager.sharedManager hasLocalProfile]) {
return NO;
}
if ([blockingManager isThreadBlocked:thread]) {
return NO;
}
BOOL hasUnwhitelistedMember = NO;
NSArray<NSString *> *blockedPhoneNumbers = [blockingManager blockedPhoneNumbers];
for (NSString *recipientId in thread.recipientIdentifiers) {

View File

@ -6,7 +6,7 @@ NS_ASSUME_NONNULL_BEGIN
@class TSThread;
extern NSString *const kNSNotificationName_BlockedPhoneNumbersDidChange;
extern NSString *const kNSNotificationName_BlockListDidChange;
// This class can be safely accessed and used from any thread.
@interface OWSBlockingManager : NSObject

View File

@ -16,7 +16,7 @@
NS_ASSUME_NONNULL_BEGIN
NSString *const kNSNotificationName_BlockedPhoneNumbersDidChange = @"kNSNotificationName_BlockedPhoneNumbersDidChange";
NSString *const kNSNotificationName_BlockListDidChange = @"kNSNotificationName_BlockListDidChange";
NSString *const kOWSBlockingManager_BlockListCollection = @"kOWSBlockingManager_BlockedPhoneNumbersCollection";
@ -298,7 +298,7 @@ NSString *const kOWSBlockingManager_SyncedBlockedGroupIdsKey = @"kOWSBlockingMan
[self saveSyncedBlockListWithPhoneNumbers:blockedPhoneNumbers groupIds:blockedGroupIds];
}
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_BlockedPhoneNumbersDidChange
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:kNSNotificationName_BlockListDidChange
object:nil
userInfo:nil];
});