session-ios/Session/Signal/AddToBlockListViewController.m

111 lines
3.3 KiB
Mathematica
Raw Normal View History

//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "AddToBlockListViewController.h"
#import "BlockListUIUtils.h"
2020-11-25 06:15:16 +01:00
#import <SessionMessagingKit/SSKEnvironment.h>
#import <SessionMessagingKit/OWSBlockingManager.h>
2020-11-11 07:45:50 +01:00
#import <SignalUtilitiesKit/SignalAccount.h>
NS_ASSUME_NONNULL_BEGIN
@interface AddToBlockListViewController () <SelectRecipientViewControllerDelegate>
@end
#pragma mark -
@implementation AddToBlockListViewController
- (void)loadView
{
self.delegate = self;
[super loadView];
self.title = NSLocalizedString(@"SETTINGS_ADD_TO_BLOCK_LIST_TITLE", @"Title for the 'add to block list' view.");
}
- (NSString *)phoneNumberSectionTitle
{
return NSLocalizedString(@"SETTINGS_ADD_TO_BLOCK_LIST_BLOCK_PHONE_NUMBER_TITLE",
@"Title for the 'block phone number' section of the 'add to block list' view.");
}
- (NSString *)phoneNumberButtonText
{
return NSLocalizedString(@"BLOCK_LIST_VIEW_BLOCK_BUTTON", @"A label for the block button in the block list view");
}
- (NSString *)contactsSectionTitle
{
return NSLocalizedString(@"SETTINGS_ADD_TO_BLOCK_LIST_BLOCK_CONTACT_TITLE",
@"Title for the 'block contact' section of the 'add to block list' view.");
}
- (void)phoneNumberWasSelected:(NSString *)phoneNumber
{
OWSAssertDebug(phoneNumber.length > 0);
__weak AddToBlockListViewController *weakSelf = self;
[BlockListUIUtils showBlockPhoneNumberActionSheet:phoneNumber
fromViewController:self
2020-11-16 00:34:47 +01:00
blockingManager:SSKEnvironment.shared.blockingManager
completionBlock:^(BOOL isBlocked) {
if (isBlocked) {
2017-04-04 16:19:47 +02:00
[weakSelf.navigationController popViewControllerAnimated:YES];
}
}];
}
2017-05-02 16:54:07 +02:00
- (BOOL)canSignalAccountBeSelected:(SignalAccount *)signalAccount
{
OWSAssertDebug(signalAccount);
2017-05-02 16:54:07 +02:00
2020-11-16 00:34:47 +01:00
return ![SSKEnvironment.shared.blockingManager isRecipientIdBlocked:signalAccount.recipientId];
2017-05-02 16:54:07 +02:00
}
2017-05-01 18:51:59 +02:00
- (void)signalAccountWasSelected:(SignalAccount *)signalAccount
{
OWSAssertDebug(signalAccount);
2017-04-04 16:19:47 +02:00
__weak AddToBlockListViewController *weakSelf = self;
2020-11-16 00:34:47 +01:00
if ([SSKEnvironment.shared.blockingManager isRecipientIdBlocked:signalAccount.recipientId]) {
OWSFailDebug(@"Cannot add already blocked user to block list.");
return;
}
2017-05-01 18:51:59 +02:00
[BlockListUIUtils showBlockSignalAccountActionSheet:signalAccount
fromViewController:self
2020-11-16 00:34:47 +01:00
blockingManager:SSKEnvironment.shared.blockingManager
2017-05-01 18:51:59 +02:00
completionBlock:^(BOOL isBlocked) {
if (isBlocked) {
[weakSelf.navigationController popViewControllerAnimated:YES];
}
}];
}
- (BOOL)shouldHideLocalNumber
{
return YES;
}
2017-04-28 20:25:53 +02:00
- (BOOL)shouldHideContacts
{
return NO;
}
- (BOOL)shouldValidatePhoneNumbers
{
return NO;
}
2017-05-02 16:54:07 +02:00
- (nullable NSString *)accessoryMessageForSignalAccount:(SignalAccount *)signalAccount
{
return nil;
}
@end
NS_ASSUME_NONNULL_END