2017-02-17 23:30:49 +01:00
|
|
|
//
|
2018-01-19 23:03:39 +01:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2017-02-17 23:30:49 +01:00
|
|
|
//
|
2016-09-21 14:37:51 +02:00
|
|
|
|
2017-08-01 22:16:33 +02:00
|
|
|
#import "OWSConversationSettingsViewController.h"
|
2017-04-03 16:29:11 +02:00
|
|
|
#import "BlockListUIUtils.h"
|
2017-05-09 23:55:18 +02:00
|
|
|
#import "ContactsViewHelper.h"
|
2016-09-21 14:37:51 +02:00
|
|
|
#import "FingerprintViewController.h"
|
2017-07-04 22:40:28 +02:00
|
|
|
#import "OWSAddToContactViewController.h"
|
2017-04-03 16:29:11 +02:00
|
|
|
#import "OWSBlockingManager.h"
|
2018-02-22 04:31:55 +01:00
|
|
|
#import "OWSSoundSettingsViewController.h"
|
2016-09-21 14:37:51 +02:00
|
|
|
#import "PhoneNumber.h"
|
|
|
|
#import "ShowGroupMembersViewController.h"
|
2017-04-21 23:03:18 +02:00
|
|
|
#import "Signal-Swift.h"
|
2016-10-06 15:44:25 +02:00
|
|
|
#import "UIFont+OWS.h"
|
2017-04-17 21:13:15 +02:00
|
|
|
#import "UIView+OWS.h"
|
2017-04-28 18:18:42 +02:00
|
|
|
#import "UpdateGroupViewController.h"
|
2017-11-28 00:17:46 +01:00
|
|
|
#import <Curve25519Kit/Curve25519.h>
|
2017-12-19 03:50:51 +01:00
|
|
|
#import <SignalMessaging/Environment.h>
|
2017-12-08 17:50:35 +01:00
|
|
|
#import <SignalMessaging/OWSAvatarBuilder.h>
|
2017-12-19 03:50:51 +01:00
|
|
|
#import <SignalMessaging/OWSContactsManager.h>
|
2017-12-04 16:35:47 +01:00
|
|
|
#import <SignalMessaging/OWSProfileManager.h>
|
2018-02-22 20:38:40 +01:00
|
|
|
#import <SignalMessaging/OWSSounds.h>
|
2017-12-08 19:45:24 +01:00
|
|
|
#import <SignalMessaging/OWSUserProfile.h>
|
2017-12-08 17:50:35 +01:00
|
|
|
#import <SignalMessaging/UIUtil.h>
|
2017-09-22 16:30:35 +02:00
|
|
|
#import <SignalServiceKit/NSDate+OWS.h>
|
2016-09-21 14:37:51 +02:00
|
|
|
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
|
|
|
|
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
|
2016-10-14 22:59:58 +02:00
|
|
|
#import <SignalServiceKit/OWSMessageSender.h>
|
2016-09-21 14:37:51 +02:00
|
|
|
#import <SignalServiceKit/OWSNotifyRemoteOfUpdatedDisappearingConfigurationJob.h>
|
2018-03-05 15:30:58 +01:00
|
|
|
#import <SignalServiceKit/OWSPrimaryStorage.h>
|
2016-09-21 14:37:51 +02:00
|
|
|
#import <SignalServiceKit/TSGroupThread.h>
|
2016-10-14 22:59:58 +02:00
|
|
|
#import <SignalServiceKit/TSOutgoingMessage.h>
|
2016-09-21 14:37:51 +02:00
|
|
|
#import <SignalServiceKit/TSThread.h>
|
|
|
|
|
2017-05-09 23:55:18 +02:00
|
|
|
@import ContactsUI;
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2018-07-03 18:57:51 +02:00
|
|
|
const CGFloat kIconViewLength = 24;
|
|
|
|
|
2018-06-28 19:28:14 +02:00
|
|
|
@interface OWSConversationSettingsViewController () <ContactEditingDelegate,
|
|
|
|
ContactsViewHelperDelegate,
|
|
|
|
ColorPickerDelegate>
|
2016-09-21 14:37:51 +02:00
|
|
|
|
|
|
|
@property (nonatomic) TSThread *thread;
|
2018-03-19 17:22:39 +01:00
|
|
|
@property (nonatomic) YapDatabaseConnection *uiDatabaseConnection;
|
2018-06-28 19:28:14 +02:00
|
|
|
@property (nonatomic, readonly) YapDatabaseConnection *editingDatabaseConnection;
|
2016-09-21 14:37:51 +02:00
|
|
|
|
|
|
|
@property (nonatomic) NSArray<NSNumber *> *disappearingMessagesDurations;
|
|
|
|
@property (nonatomic) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration;
|
2018-03-19 20:20:33 +01:00
|
|
|
@property (nullable, nonatomic) MediaGalleryViewController *mediaGalleryViewController;
|
2017-08-02 21:15:31 +02:00
|
|
|
@property (nonatomic, readonly) TSAccountManager *accountManager;
|
2016-09-21 14:37:51 +02:00
|
|
|
@property (nonatomic, readonly) OWSContactsManager *contactsManager;
|
2016-10-14 22:59:58 +02:00
|
|
|
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
2017-04-03 16:29:11 +02:00
|
|
|
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
|
2017-05-09 23:55:18 +02:00
|
|
|
@property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper;
|
2017-04-21 21:37:51 +02:00
|
|
|
@property (nonatomic, readonly) UIImageView *avatarView;
|
2017-04-17 21:13:15 +02:00
|
|
|
@property (nonatomic, readonly) UILabel *disappearingMessagesDurationLabel;
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
@end
|
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
#pragma mark -
|
|
|
|
|
2017-08-01 22:16:33 +02:00
|
|
|
@implementation OWSConversationSettingsViewController
|
2016-09-21 14:37:51 +02:00
|
|
|
|
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-03-10 14:59:59 +01:00
|
|
|
[self commonInit];
|
2016-09-21 14:37:51 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder
|
|
|
|
{
|
|
|
|
self = [super initWithCoder:aDecoder];
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-03-10 14:59:59 +01:00
|
|
|
[self commonInit];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-08-01 22:16:33 +02:00
|
|
|
- (instancetype)initWithNibName:(nullable NSString *)nibNameOrNil bundle:(nullable NSBundle *)nibBundleOrNil
|
|
|
|
{
|
2017-03-10 14:59:59 +01:00
|
|
|
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
2017-08-01 22:16:33 +02:00
|
|
|
|
2017-03-10 14:59:59 +01:00
|
|
|
[self commonInit];
|
2017-08-01 22:16:33 +02:00
|
|
|
|
2017-03-10 14:59:59 +01:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)commonInit
|
|
|
|
{
|
2017-08-02 21:15:31 +02:00
|
|
|
_accountManager = [TSAccountManager sharedInstance];
|
2017-12-04 16:35:47 +01:00
|
|
|
_contactsManager = [Environment current].contactsManager;
|
|
|
|
_messageSender = [Environment current].messageSender;
|
2017-04-03 16:29:11 +02:00
|
|
|
_blockingManager = [OWSBlockingManager sharedManager];
|
2017-05-12 17:09:25 +02:00
|
|
|
_contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self];
|
2017-06-09 22:21:59 +02:00
|
|
|
|
|
|
|
[self observeNotifications];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)observeNotifications
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(identityStateDidChange:)
|
|
|
|
name:kNSNotificationName_IdentityStateDidChange
|
|
|
|
object:nil];
|
2017-08-23 23:09:43 +02:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(otherUsersProfileDidChange:)
|
|
|
|
name:kNSNotificationName_OtherUsersProfileDidChange
|
|
|
|
object:nil];
|
2016-09-21 14:37:51 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 19:28:14 +02:00
|
|
|
- (YapDatabaseConnection *)editingDatabaseConnection
|
|
|
|
{
|
|
|
|
return [OWSPrimaryStorage sharedManager].dbReadWriteConnection;
|
|
|
|
}
|
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
- (NSString *)threadName
|
|
|
|
{
|
|
|
|
NSString *threadName = self.thread.name;
|
|
|
|
if ([threadName isEqualToString:self.thread.contactIdentifier]) {
|
|
|
|
threadName =
|
|
|
|
[PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:self.thread.contactIdentifier];
|
|
|
|
} else if (threadName.length == 0 && [self isGroupThread]) {
|
2017-10-14 19:20:46 +02:00
|
|
|
threadName = [MessageStrings newGroupDefaultTitle];
|
2017-04-17 21:13:15 +02:00
|
|
|
}
|
|
|
|
return threadName;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isGroupThread
|
|
|
|
{
|
|
|
|
return [self.thread isKindOfClass:[TSGroupThread class]];
|
|
|
|
}
|
|
|
|
|
2018-03-19 17:22:39 +01:00
|
|
|
- (void)configureWithThread:(TSThread *)thread uiDatabaseConnection:(YapDatabaseConnection *)uiDatabaseConnection
|
2016-09-21 14:37:51 +02:00
|
|
|
{
|
2017-05-12 21:30:06 +02:00
|
|
|
OWSAssert(thread);
|
2016-09-21 14:37:51 +02:00
|
|
|
self.thread = thread;
|
2018-03-19 17:22:39 +01:00
|
|
|
self.uiDatabaseConnection = uiDatabaseConnection;
|
2017-05-12 21:30:06 +02:00
|
|
|
|
|
|
|
if ([self.thread isKindOfClass:[TSContactThread class]]) {
|
|
|
|
self.title = NSLocalizedString(
|
|
|
|
@"CONVERSATION_SETTINGS_CONTACT_INFO_TITLE", @"Navbar title when viewing settings for a 1-on-1 thread");
|
|
|
|
} else {
|
|
|
|
self.title = NSLocalizedString(
|
|
|
|
@"CONVERSATION_SETTINGS_GROUP_INFO_TITLE", @"Navbar title when viewing settings for a group thread");
|
|
|
|
}
|
|
|
|
|
2017-05-09 23:55:18 +02:00
|
|
|
[self updateEditButton];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateEditButton
|
|
|
|
{
|
|
|
|
OWSAssert(self.thread);
|
|
|
|
|
2017-07-04 22:40:28 +02:00
|
|
|
if ([self.thread isKindOfClass:[TSContactThread class]] && self.contactsManager.supportsContactEditing
|
|
|
|
&& self.hasExistingContact) {
|
2017-05-09 23:55:18 +02:00
|
|
|
self.navigationItem.rightBarButtonItem =
|
|
|
|
[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"EDIT_TXT", nil)
|
|
|
|
style:UIBarButtonItemStylePlain
|
|
|
|
target:self
|
|
|
|
action:@selector(didTapEditButton)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-04 22:40:28 +02:00
|
|
|
- (BOOL)hasExistingContact
|
|
|
|
{
|
|
|
|
OWSAssert([self.thread isKindOfClass:[TSContactThread class]]);
|
|
|
|
TSContactThread *contactThread = (TSContactThread *)self.thread;
|
|
|
|
NSString *recipientId = contactThread.contactIdentifier;
|
2017-12-14 16:51:46 +01:00
|
|
|
return [self.contactsManager hasSignalAccountForRecipientId:recipientId];
|
2017-07-04 22:40:28 +02:00
|
|
|
}
|
|
|
|
|
2017-05-09 23:55:18 +02:00
|
|
|
#pragma mark - ContactEditingDelegate
|
|
|
|
|
|
|
|
- (void)didFinishEditingContact
|
|
|
|
{
|
2017-07-04 22:40:28 +02:00
|
|
|
[self updateTableContents];
|
|
|
|
|
2017-11-08 20:04:51 +01:00
|
|
|
DDLogDebug(@"%@ %s", self.logTag, __PRETTY_FUNCTION__);
|
2017-05-10 18:02:14 +02:00
|
|
|
[self dismissViewControllerAnimated:NO completion:nil];
|
2017-05-09 23:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - CNContactViewControllerDelegate
|
|
|
|
|
|
|
|
- (void)contactViewController:(CNContactViewController *)viewController
|
|
|
|
didCompleteWithContact:(nullable CNContact *)contact
|
|
|
|
{
|
2017-07-04 22:40:28 +02:00
|
|
|
[self updateTableContents];
|
|
|
|
|
2017-05-10 18:02:14 +02:00
|
|
|
if (contact) {
|
|
|
|
// Saving normally returns you to the "Show Contact" view
|
|
|
|
// which we're not interested in, so we skip it here. There is
|
|
|
|
// an unfortunate blip of the "Show Contact" view on slower devices.
|
2017-11-08 20:04:51 +01:00
|
|
|
DDLogDebug(@"%@ completed editing contact.", self.logTag);
|
2017-05-10 18:02:14 +02:00
|
|
|
[self dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
} else {
|
2017-11-08 20:04:51 +01:00
|
|
|
DDLogDebug(@"%@ canceled editing contact.", self.logTag);
|
2017-05-10 18:02:14 +02:00
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
2017-05-09 23:55:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - ContactsViewHelperDelegate
|
|
|
|
|
|
|
|
- (void)contactsViewHelperDidUpdateContacts
|
|
|
|
{
|
|
|
|
[self updateTableContents];
|
2016-09-21 14:37:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - View Lifecycle
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
2018-07-17 20:24:21 +02:00
|
|
|
self.tableView.estimatedRowHeight = 45;
|
|
|
|
self.tableView.rowHeight = UITableViewAutomaticDimension;
|
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
_disappearingMessagesDurationLabel = [UILabel new];
|
2016-09-21 14:37:51 +02:00
|
|
|
|
|
|
|
self.disappearingMessagesDurations = [OWSDisappearingMessagesConfiguration validDurationsSeconds];
|
|
|
|
|
|
|
|
self.disappearingMessagesConfiguration =
|
|
|
|
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:self.thread.uniqueId];
|
|
|
|
|
|
|
|
if (!self.disappearingMessagesConfiguration) {
|
|
|
|
self.disappearingMessagesConfiguration =
|
|
|
|
[[OWSDisappearingMessagesConfiguration alloc] initDefaultWithThreadId:self.thread.uniqueId];
|
|
|
|
}
|
|
|
|
|
2017-04-03 16:29:11 +02:00
|
|
|
[self updateTableContents];
|
|
|
|
}
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewDidAppear:animated];
|
|
|
|
|
|
|
|
if (self.showVerificationOnAppear) {
|
|
|
|
self.showVerificationOnAppear = NO;
|
|
|
|
if (self.isGroupThread) {
|
|
|
|
[self showGroupMembersView];
|
|
|
|
} else {
|
|
|
|
[self showVerificationView];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-03 16:29:11 +02:00
|
|
|
- (void)updateTableContents
|
|
|
|
{
|
|
|
|
OWSTableContents *contents = [OWSTableContents new];
|
|
|
|
contents.title = NSLocalizedString(@"CONVERSATION_SETTINGS", @"title for conversation settings screen");
|
|
|
|
|
2017-08-01 22:16:33 +02:00
|
|
|
__weak OWSConversationSettingsViewController *weakSelf = self;
|
2017-04-03 16:29:11 +02:00
|
|
|
|
2017-07-04 22:40:28 +02:00
|
|
|
// Main section.
|
2017-04-10 21:58:34 +02:00
|
|
|
|
2017-07-04 22:40:28 +02:00
|
|
|
OWSTableSection *mainSection = [OWSTableSection new];
|
2017-04-03 16:29:11 +02:00
|
|
|
|
2017-07-04 22:40:28 +02:00
|
|
|
mainSection.customHeaderView = [self mainSectionHeader];
|
|
|
|
mainSection.customHeaderHeight = @(100.f);
|
|
|
|
|
2018-03-19 17:22:39 +01:00
|
|
|
[mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
|
|
|
return [weakSelf disclosureCellWithName:MediaStrings.allMedia iconName:@"actionsheet_camera_roll_black"];
|
|
|
|
}
|
|
|
|
actionBlock:^{
|
|
|
|
[weakSelf showMediaGallery];
|
|
|
|
}]];
|
|
|
|
|
2018-07-10 19:55:14 +02:00
|
|
|
#ifdef CONVERSATION_COLORS_ENABLED
|
2018-06-28 19:28:14 +02:00
|
|
|
[mainSection addItem:[OWSTableItem
|
|
|
|
itemWithCustomCellBlock:^{
|
|
|
|
NSString *colorName = self.thread.conversationColorName;
|
|
|
|
UIColor *currentColor = [UIColor ows_conversationColorForColorName:colorName];
|
|
|
|
NSString *title = NSLocalizedString(@"CONVERSATION_SETTINGS_CONVERSATION_COLOR",
|
|
|
|
@"Label for table cell which leads to picking a new conversation color");
|
|
|
|
return [weakSelf disclosureCellWithName:title iconColor:currentColor];
|
|
|
|
}
|
|
|
|
actionBlock:^{
|
|
|
|
[weakSelf showColorPicker];
|
|
|
|
}]];
|
2018-07-09 17:51:28 +02:00
|
|
|
#endif
|
2018-06-28 19:28:14 +02:00
|
|
|
|
2017-07-04 22:40:28 +02:00
|
|
|
if ([self.thread isKindOfClass:[TSContactThread class]] && self.contactsManager.supportsContactEditing
|
|
|
|
&& !self.hasExistingContact) {
|
|
|
|
[mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
|
|
|
return
|
|
|
|
[weakSelf disclosureCellWithName:NSLocalizedString(@"CONVERSATION_SETTINGS_NEW_CONTACT",
|
|
|
|
@"Label for 'new contact' button in conversation settings view.")
|
|
|
|
iconName:@"table_ic_new_contact"];
|
|
|
|
}
|
|
|
|
actionBlock:^{
|
|
|
|
[weakSelf presentContactViewController];
|
|
|
|
}]];
|
|
|
|
[mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
|
|
|
return
|
|
|
|
[weakSelf disclosureCellWithName:NSLocalizedString(@"CONVERSATION_SETTINGS_ADD_TO_EXISTING_CONTACT",
|
|
|
|
@"Label for 'new contact' button in conversation settings view.")
|
|
|
|
iconName:@"table_ic_add_to_existing_contact"];
|
|
|
|
}
|
|
|
|
actionBlock:^{
|
2017-08-01 22:16:33 +02:00
|
|
|
OWSConversationSettingsViewController *strongSelf = weakSelf;
|
2017-07-25 19:56:16 +02:00
|
|
|
OWSCAssert(strongSelf);
|
|
|
|
TSContactThread *contactThread = (TSContactThread *)strongSelf.thread;
|
2017-07-04 22:40:28 +02:00
|
|
|
NSString *recipientId = contactThread.contactIdentifier;
|
2017-07-25 19:56:16 +02:00
|
|
|
[strongSelf presentAddToContactViewControllerWithRecipientId:recipientId];
|
2017-07-04 22:40:28 +02:00
|
|
|
}]];
|
|
|
|
}
|
2017-04-10 21:58:34 +02:00
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
if (!self.isGroupThread && self.thread.hasSafetyNumbers) {
|
2017-07-04 22:40:28 +02:00
|
|
|
[mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
2017-06-09 22:58:00 +02:00
|
|
|
return [weakSelf
|
|
|
|
disclosureCellWithName:
|
|
|
|
NSLocalizedString(@"VERIFY_PRIVACY",
|
|
|
|
@"Label for button or row which allows users to verify the safety number of another user.")
|
2017-06-12 21:50:54 +02:00
|
|
|
iconName:@"table_ic_not_verified"];
|
2017-06-09 22:58:00 +02:00
|
|
|
}
|
2017-07-04 22:40:28 +02:00
|
|
|
actionBlock:^{
|
|
|
|
[weakSelf showVerificationView];
|
|
|
|
}]];
|
2017-04-10 21:58:34 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 19:12:26 +02:00
|
|
|
if ([OWSProfileManager.sharedManager isThreadInProfileWhitelist:self.thread]) {
|
2017-08-01 22:16:33 +02:00
|
|
|
[mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
|
|
|
return [weakSelf
|
|
|
|
labelCellWithName:(self.isGroupThread
|
|
|
|
? NSLocalizedString(
|
|
|
|
@"CONVERSATION_SETTINGS_VIEW_PROFILE_IS_SHARED_WITH_GROUP",
|
|
|
|
@"Indicates that user's profile has been shared with a group.")
|
|
|
|
: NSLocalizedString(@"CONVERSATION_SETTINGS_VIEW_PROFILE_IS_SHARED_WITH_USER",
|
|
|
|
@"Indicates that user's profile has been shared with a user."))iconName
|
|
|
|
:@"table_ic_share_profile"];
|
|
|
|
}
|
2017-08-03 23:43:21 +02:00
|
|
|
actionBlock:nil]];
|
2017-08-01 22:16:33 +02:00
|
|
|
} else {
|
|
|
|
[mainSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
|
|
|
return
|
|
|
|
[weakSelf disclosureCellWithName:(self.isGroupThread
|
|
|
|
? NSLocalizedString(
|
|
|
|
@"CONVERSATION_SETTINGS_VIEW_SHARE_PROFILE_WITH_GROUP",
|
|
|
|
@"Action that shares user profile with a group.")
|
|
|
|
: NSLocalizedString(
|
|
|
|
@"CONVERSATION_SETTINGS_VIEW_SHARE_PROFILE_WITH_USER",
|
|
|
|
@"Action that shares user profile with a user."))iconName
|
|
|
|
:@"table_ic_share_profile"];
|
|
|
|
}
|
|
|
|
actionBlock:^{
|
|
|
|
[weakSelf showShareProfileAlert];
|
|
|
|
}]];
|
|
|
|
}
|
|
|
|
|
2018-07-11 20:40:59 +02:00
|
|
|
[mainSection addItem:[OWSTableItem
|
|
|
|
itemWithCustomCellBlock:^{
|
|
|
|
UITableViewCell *cell = [UITableViewCell new];
|
|
|
|
OWSConversationSettingsViewController *strongSelf = weakSelf;
|
|
|
|
OWSCAssert(strongSelf);
|
|
|
|
cell.preservesSuperviewLayoutMargins = YES;
|
|
|
|
cell.contentView.preservesSuperviewLayoutMargins = YES;
|
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
|
2018-07-12 17:57:57 +02:00
|
|
|
NSString *iconName
|
|
|
|
= (strongSelf.disappearingMessagesConfiguration.isEnabled ? @"ic_timer"
|
|
|
|
: @"ic_timer_disabled");
|
|
|
|
UIImageView *iconView = [strongSelf viewForIconWithName:iconName];
|
2018-07-11 20:40:59 +02:00
|
|
|
|
|
|
|
UILabel *rowLabel = [UILabel new];
|
|
|
|
rowLabel.text = NSLocalizedString(
|
|
|
|
@"DISAPPEARING_MESSAGES", @"table cell label in conversation settings");
|
|
|
|
rowLabel.textColor = [UIColor blackColor];
|
|
|
|
rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
|
|
|
|
rowLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
|
|
|
|
UISwitch *switchView = [UISwitch new];
|
|
|
|
switchView.on = strongSelf.disappearingMessagesConfiguration.isEnabled;
|
|
|
|
[switchView addTarget:strongSelf
|
|
|
|
action:@selector(disappearingMessagesSwitchValueDidChange:)
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
2018-07-17 20:24:21 +02:00
|
|
|
|
|
|
|
UIStackView *topRow =
|
|
|
|
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel, switchView ]];
|
|
|
|
topRow.spacing = self.iconSpacing;
|
|
|
|
topRow.alignment = UIStackViewAlignmentCenter;
|
|
|
|
[cell.contentView addSubview:topRow];
|
|
|
|
[topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom];
|
2018-07-11 20:40:59 +02:00
|
|
|
|
|
|
|
UILabel *subtitleLabel = [UILabel new];
|
|
|
|
subtitleLabel.text = NSLocalizedString(
|
|
|
|
@"DISAPPEARING_MESSAGES_DESCRIPTION", @"subheading in conversation settings");
|
|
|
|
subtitleLabel.textColor = [UIColor blackColor];
|
|
|
|
subtitleLabel.font = [UIFont ows_dynamicTypeCaption1Font];
|
|
|
|
subtitleLabel.numberOfLines = 0;
|
|
|
|
subtitleLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
|
|
|
[cell.contentView addSubview:subtitleLabel];
|
2018-07-17 20:24:21 +02:00
|
|
|
[subtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topRow withOffset:8];
|
2018-07-11 20:40:59 +02:00
|
|
|
[subtitleLabel autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:rowLabel];
|
|
|
|
[subtitleLabel autoPinTrailingToSuperviewMargin];
|
|
|
|
[subtitleLabel autoPinBottomToSuperviewMargin];
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
customRowHeight:UITableViewAutomaticDimension
|
|
|
|
actionBlock:nil]];
|
2017-04-17 21:13:15 +02:00
|
|
|
|
|
|
|
if (self.disappearingMessagesConfiguration.isEnabled) {
|
2017-07-04 22:40:28 +02:00
|
|
|
[mainSection
|
2017-04-17 21:13:15 +02:00
|
|
|
addItem:[OWSTableItem
|
|
|
|
itemWithCustomCellBlock:^{
|
|
|
|
UITableViewCell *cell = [UITableViewCell new];
|
2017-08-01 22:16:33 +02:00
|
|
|
OWSConversationSettingsViewController *strongSelf = weakSelf;
|
2017-07-25 19:56:16 +02:00
|
|
|
OWSCAssert(strongSelf);
|
2017-07-11 18:17:28 +02:00
|
|
|
cell.preservesSuperviewLayoutMargins = YES;
|
|
|
|
cell.contentView.preservesSuperviewLayoutMargins = YES;
|
2017-04-17 21:13:15 +02:00
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
|
2018-01-20 17:27:32 +01:00
|
|
|
UIImageView *iconView = [strongSelf viewForIconWithName:@"ic_timer"];
|
2017-04-17 21:13:15 +02:00
|
|
|
|
2017-07-25 19:56:16 +02:00
|
|
|
UILabel *rowLabel = strongSelf.disappearingMessagesDurationLabel;
|
|
|
|
[strongSelf updateDisappearingMessagesDurationLabel];
|
2017-04-17 21:13:15 +02:00
|
|
|
rowLabel.textColor = [UIColor blackColor];
|
2018-07-11 20:40:59 +02:00
|
|
|
rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
|
2018-07-17 20:24:21 +02:00
|
|
|
// don't truncate useful duration info which is in the tail
|
|
|
|
rowLabel.lineBreakMode = NSLineBreakByTruncatingHead;
|
|
|
|
|
|
|
|
UIStackView *topRow =
|
|
|
|
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
|
|
|
|
topRow.spacing = self.iconSpacing;
|
|
|
|
topRow.alignment = UIStackViewAlignmentCenter;
|
|
|
|
[cell.contentView addSubview:topRow];
|
|
|
|
[topRow autoPinEdgesToSuperviewMarginsExcludingEdge:ALEdgeBottom];
|
2017-04-17 21:13:15 +02:00
|
|
|
|
|
|
|
UISlider *slider = [UISlider new];
|
2017-07-25 19:56:16 +02:00
|
|
|
slider.maximumValue = (float)(strongSelf.disappearingMessagesDurations.count - 1);
|
2017-04-17 21:13:15 +02:00
|
|
|
slider.minimumValue = 0;
|
|
|
|
slider.continuous = YES; // NO fires change event only once you let go
|
2017-07-25 19:56:16 +02:00
|
|
|
slider.value = strongSelf.disappearingMessagesConfiguration.durationIndex;
|
|
|
|
[slider addTarget:strongSelf
|
2017-04-17 21:13:15 +02:00
|
|
|
action:@selector(durationSliderDidChange:)
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
|
|
|
[cell.contentView addSubview:slider];
|
2018-07-17 20:24:21 +02:00
|
|
|
[slider autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:topRow withOffset:6];
|
2017-07-11 18:17:28 +02:00
|
|
|
[slider autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:rowLabel];
|
2018-04-02 21:31:32 +02:00
|
|
|
[slider autoPinTrailingToSuperviewMargin];
|
2018-07-11 20:40:59 +02:00
|
|
|
[slider autoPinBottomToSuperviewMargin];
|
2017-04-17 21:13:15 +02:00
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
2018-07-11 20:40:59 +02:00
|
|
|
customRowHeight:UITableViewAutomaticDimension
|
2017-04-17 21:13:15 +02:00
|
|
|
actionBlock:nil]];
|
2017-04-03 16:29:11 +02:00
|
|
|
}
|
|
|
|
|
2017-07-04 22:40:28 +02:00
|
|
|
[contents addSection:mainSection];
|
2017-04-17 21:13:15 +02:00
|
|
|
|
|
|
|
// Group settings section.
|
2017-04-03 16:29:11 +02:00
|
|
|
|
|
|
|
if (self.isGroupThread) {
|
|
|
|
NSArray *groupItems = @[
|
|
|
|
[OWSTableItem itemWithCustomCellBlock:^{
|
2017-06-05 23:33:29 +02:00
|
|
|
return [weakSelf disclosureCellWithName:NSLocalizedString(@"EDIT_GROUP_ACTION",
|
|
|
|
@"table cell label in conversation settings")
|
|
|
|
iconName:@"table_ic_group_edit"];
|
2017-04-03 16:29:11 +02:00
|
|
|
}
|
|
|
|
actionBlock:^{
|
2017-05-02 16:54:07 +02:00
|
|
|
[weakSelf showUpdateGroupView:UpdateGroupMode_Default];
|
2017-04-03 16:29:11 +02:00
|
|
|
}],
|
|
|
|
[OWSTableItem itemWithCustomCellBlock:^{
|
2017-06-05 23:33:29 +02:00
|
|
|
return [weakSelf disclosureCellWithName:NSLocalizedString(@"LIST_GROUP_MEMBERS_ACTION",
|
|
|
|
@"table cell label in conversation settings")
|
|
|
|
iconName:@"table_ic_group_members"];
|
2017-04-03 16:29:11 +02:00
|
|
|
}
|
|
|
|
actionBlock:^{
|
2017-06-09 22:21:59 +02:00
|
|
|
[weakSelf showGroupMembersView];
|
2017-04-03 16:29:11 +02:00
|
|
|
}],
|
2017-06-05 22:13:01 +02:00
|
|
|
[OWSTableItem itemWithCustomCellBlock:^{
|
2017-06-05 23:33:29 +02:00
|
|
|
return [weakSelf disclosureCellWithName:NSLocalizedString(@"LEAVE_GROUP_ACTION",
|
|
|
|
@"table cell label in conversation settings")
|
|
|
|
iconName:@"table_ic_group_leave"];
|
2017-06-05 22:13:01 +02:00
|
|
|
}
|
|
|
|
actionBlock:^{
|
|
|
|
[weakSelf didTapLeaveGroup];
|
|
|
|
}],
|
2017-04-03 16:29:11 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
[contents addSection:[OWSTableSection sectionWithTitle:NSLocalizedString(@"GROUP_MANAGEMENT_SECTION",
|
|
|
|
@"Conversation settings table section title")
|
|
|
|
items:groupItems]];
|
|
|
|
}
|
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
// Mute thread section.
|
|
|
|
|
2018-02-23 21:25:58 +01:00
|
|
|
OWSTableSection *notificationsSection = [OWSTableSection new];
|
|
|
|
// We need a section header to separate the notifications UI from the group settings UI.
|
|
|
|
notificationsSection.headerTitle = NSLocalizedString(
|
|
|
|
@"SETTINGS_SECTION_NOTIFICATIONS", @"Label for the notifications section of conversation settings view.");
|
|
|
|
|
2018-07-11 20:40:59 +02:00
|
|
|
[notificationsSection
|
|
|
|
addItem:[OWSTableItem
|
|
|
|
itemWithCustomCellBlock:^{
|
|
|
|
UITableViewCell *cell =
|
|
|
|
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
|
|
|
|
OWSConversationSettingsViewController *strongSelf = weakSelf;
|
|
|
|
OWSCAssert(strongSelf);
|
|
|
|
cell.preservesSuperviewLayoutMargins = YES;
|
|
|
|
cell.contentView.preservesSuperviewLayoutMargins = YES;
|
|
|
|
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
|
|
|
|
|
|
|
UIImageView *iconView = [strongSelf viewForIconWithName:@"table_ic_notification_sound"];
|
|
|
|
|
|
|
|
UILabel *rowLabel = [UILabel new];
|
|
|
|
rowLabel.text = NSLocalizedString(@"SETTINGS_ITEM_NOTIFICATION_SOUND",
|
|
|
|
@"Label for settings view that allows user to change the notification sound.");
|
|
|
|
rowLabel.textColor = [UIColor blackColor];
|
|
|
|
rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
|
|
|
|
rowLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
2018-07-17 20:24:21 +02:00
|
|
|
|
|
|
|
UIStackView *contentRow =
|
|
|
|
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
|
|
|
|
contentRow.spacing = self.iconSpacing;
|
|
|
|
contentRow.alignment = UIStackViewAlignmentCenter;
|
|
|
|
[cell.contentView addSubview:contentRow];
|
|
|
|
[contentRow autoPinEdgesToSuperviewMargins];
|
2018-07-11 20:40:59 +02:00
|
|
|
|
|
|
|
OWSSound sound = [OWSSounds notificationSoundForThread:self.thread];
|
|
|
|
cell.detailTextLabel.text = [OWSSounds displayNameForSound:sound];
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
customRowHeight:UITableViewAutomaticDimension
|
|
|
|
actionBlock:^{
|
|
|
|
OWSSoundSettingsViewController *vc = [OWSSoundSettingsViewController new];
|
|
|
|
vc.thread = weakSelf.thread;
|
|
|
|
[weakSelf.navigationController pushViewController:vc animated:YES];
|
|
|
|
}]];
|
|
|
|
|
|
|
|
[notificationsSection
|
|
|
|
addItem:[OWSTableItem
|
|
|
|
itemWithCustomCellBlock:^{
|
|
|
|
UITableViewCell *cell =
|
|
|
|
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
|
|
|
|
OWSConversationSettingsViewController *strongSelf = weakSelf;
|
|
|
|
OWSCAssert(strongSelf);
|
|
|
|
cell.preservesSuperviewLayoutMargins = YES;
|
|
|
|
cell.contentView.preservesSuperviewLayoutMargins = YES;
|
|
|
|
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
|
|
|
|
|
|
|
UIImageView *iconView = [strongSelf viewForIconWithName:@"table_ic_mute_thread"];
|
|
|
|
|
|
|
|
UILabel *rowLabel = [UILabel new];
|
|
|
|
rowLabel.text = NSLocalizedString(@"CONVERSATION_SETTINGS_MUTE_LABEL",
|
|
|
|
@"label for 'mute thread' cell in conversation settings");
|
|
|
|
rowLabel.textColor = [UIColor blackColor];
|
|
|
|
rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
|
|
|
|
rowLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
|
|
|
|
NSString *muteStatus = NSLocalizedString(@"CONVERSATION_SETTINGS_MUTE_NOT_MUTED",
|
|
|
|
@"Indicates that the current thread is not muted.");
|
|
|
|
NSDate *mutedUntilDate = strongSelf.thread.mutedUntilDate;
|
|
|
|
NSDate *now = [NSDate date];
|
|
|
|
if (mutedUntilDate != nil && [mutedUntilDate timeIntervalSinceDate:now] > 0) {
|
|
|
|
NSCalendar *calendar = [NSCalendar currentCalendar];
|
|
|
|
NSCalendarUnit calendarUnits = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
|
|
|
|
NSDateComponents *muteUntilComponents =
|
|
|
|
[calendar components:calendarUnits fromDate:mutedUntilDate];
|
|
|
|
NSDateComponents *nowComponents = [calendar components:calendarUnits fromDate:now];
|
|
|
|
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
|
|
|
if (nowComponents.year != muteUntilComponents.year
|
|
|
|
|| nowComponents.month != muteUntilComponents.month
|
|
|
|
|| nowComponents.day != muteUntilComponents.day) {
|
|
|
|
|
|
|
|
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
|
|
|
|
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
|
|
|
|
} else {
|
|
|
|
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
|
|
|
|
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
|
|
|
|
}
|
|
|
|
|
|
|
|
muteStatus = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"CONVERSATION_SETTINGS_MUTED_UNTIL_FORMAT",
|
|
|
|
@"Indicates that this thread is muted until a given date or time. "
|
|
|
|
@"Embeds {{The date or time which the thread is muted until}}."),
|
|
|
|
[dateFormatter stringFromDate:mutedUntilDate]];
|
|
|
|
}
|
2017-04-17 21:13:15 +02:00
|
|
|
|
2018-07-17 20:24:21 +02:00
|
|
|
UIStackView *contentRow =
|
|
|
|
[[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
|
|
|
|
contentRow.spacing = self.iconSpacing;
|
|
|
|
contentRow.alignment = UIStackViewAlignmentCenter;
|
|
|
|
[cell.contentView addSubview:contentRow];
|
|
|
|
[contentRow autoPinEdgesToSuperviewMargins];
|
|
|
|
|
2018-07-11 20:40:59 +02:00
|
|
|
cell.detailTextLabel.text = muteStatus;
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
customRowHeight:UITableViewAutomaticDimension
|
|
|
|
actionBlock:^{
|
|
|
|
[weakSelf showMuteUnmuteActionSheet];
|
|
|
|
}]];
|
2018-02-23 21:25:58 +01:00
|
|
|
notificationsSection.footerTitle
|
2017-04-17 21:13:15 +02:00
|
|
|
= NSLocalizedString(@"MUTE_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of muting a thread.");
|
2018-02-23 21:25:58 +01:00
|
|
|
[contents addSection:notificationsSection];
|
2017-04-17 21:13:15 +02:00
|
|
|
|
|
|
|
// Block user section.
|
|
|
|
|
|
|
|
if (!self.isGroupThread) {
|
|
|
|
BOOL isBlocked = [[_blockingManager blockedPhoneNumbers] containsObject:self.thread.contactIdentifier];
|
|
|
|
|
2017-07-14 16:55:49 +02:00
|
|
|
OWSTableSection *section = [OWSTableSection new];
|
|
|
|
section.footerTitle = NSLocalizedString(
|
|
|
|
@"BLOCK_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of blocking another user.");
|
|
|
|
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
2017-06-05 23:33:29 +02:00
|
|
|
UITableViewCell *cell =
|
|
|
|
[weakSelf disclosureCellWithName:NSLocalizedString(@"CONVERSATION_SETTINGS_BLOCK_THIS_USER",
|
|
|
|
@"table cell label in conversation settings")
|
|
|
|
iconName:@"table_ic_block"];
|
2017-08-01 22:16:33 +02:00
|
|
|
OWSConversationSettingsViewController *strongSelf = weakSelf;
|
2017-07-25 19:56:16 +02:00
|
|
|
OWSCAssert(strongSelf);
|
2017-04-17 21:13:15 +02:00
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
|
|
|
|
UISwitch *blockUserSwitch = [UISwitch new];
|
|
|
|
blockUserSwitch.on = isBlocked;
|
2017-07-25 19:56:16 +02:00
|
|
|
[blockUserSwitch addTarget:strongSelf
|
2017-04-17 21:13:15 +02:00
|
|
|
action:@selector(blockUserSwitchDidChange:)
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
|
|
|
cell.accessoryView = blockUserSwitch;
|
|
|
|
return cell;
|
|
|
|
}
|
2017-07-14 16:55:49 +02:00
|
|
|
actionBlock:nil]];
|
2017-04-17 21:13:15 +02:00
|
|
|
[contents addSection:section];
|
|
|
|
}
|
|
|
|
|
2017-04-03 16:29:11 +02:00
|
|
|
self.contents = contents;
|
2016-09-21 14:37:51 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 18:17:28 +02:00
|
|
|
- (CGFloat)iconSpacing
|
|
|
|
{
|
|
|
|
return 12.f;
|
|
|
|
}
|
|
|
|
|
2018-06-28 19:28:14 +02:00
|
|
|
- (UITableViewCell *)disclosureCellWithName:(NSString *)name iconColor:(UIColor *)iconColor
|
|
|
|
{
|
|
|
|
OWSAssert(name.length > 0);
|
|
|
|
|
2018-07-03 18:57:51 +02:00
|
|
|
UIView *iconView = [UIView containerView];
|
|
|
|
[iconView autoSetDimensionsToSize:CGSizeMake(kIconViewLength, kIconViewLength)];
|
2018-06-28 19:28:14 +02:00
|
|
|
|
|
|
|
UIView *swatchView = [NeverClearView new];
|
2018-07-03 18:57:51 +02:00
|
|
|
const CGFloat kSwatchWidth = 20;
|
|
|
|
[swatchView autoSetDimensionsToSize:CGSizeMake(kSwatchWidth, kSwatchWidth)];
|
2018-06-28 19:28:14 +02:00
|
|
|
swatchView.layer.cornerRadius = kSwatchWidth / 2;
|
|
|
|
swatchView.backgroundColor = iconColor;
|
2018-07-03 18:57:51 +02:00
|
|
|
[iconView addSubview:swatchView];
|
|
|
|
[swatchView autoCenterInSuperview];
|
2018-06-28 19:28:14 +02:00
|
|
|
|
2018-07-03 18:57:51 +02:00
|
|
|
return [self cellWithName:name iconView:iconView];
|
2018-06-28 19:28:14 +02:00
|
|
|
}
|
|
|
|
|
2017-08-01 22:16:33 +02:00
|
|
|
- (UITableViewCell *)cellWithName:(NSString *)name iconName:(NSString *)iconName
|
2017-06-05 23:33:29 +02:00
|
|
|
{
|
|
|
|
OWSAssert(iconName.length > 0);
|
2018-07-03 18:57:51 +02:00
|
|
|
UIImageView *iconView = [self viewForIconWithName:iconName];
|
|
|
|
return [self cellWithName:name iconView:iconView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)cellWithName:(NSString *)name iconView:(UIView *)iconView
|
|
|
|
{
|
|
|
|
OWSAssert(name.length > 0);
|
2017-06-05 23:33:29 +02:00
|
|
|
|
|
|
|
UITableViewCell *cell = [UITableViewCell new];
|
2017-07-11 18:17:28 +02:00
|
|
|
cell.preservesSuperviewLayoutMargins = YES;
|
|
|
|
cell.contentView.preservesSuperviewLayoutMargins = YES;
|
2017-06-05 23:33:29 +02:00
|
|
|
|
|
|
|
UILabel *rowLabel = [UILabel new];
|
|
|
|
rowLabel.text = name;
|
|
|
|
rowLabel.textColor = [UIColor blackColor];
|
2018-07-11 20:40:59 +02:00
|
|
|
rowLabel.font = [UIFont ows_dynamicTypeBodyFont];
|
2017-06-05 23:33:29 +02:00
|
|
|
rowLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
2018-07-17 20:24:21 +02:00
|
|
|
|
|
|
|
UIStackView *contentRow = [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, rowLabel ]];
|
|
|
|
contentRow.spacing = self.iconSpacing;
|
|
|
|
|
|
|
|
[cell.contentView addSubview:contentRow];
|
|
|
|
[contentRow autoPinEdgesToSuperviewMargins];
|
2017-06-05 23:33:29 +02:00
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2017-08-01 22:16:33 +02:00
|
|
|
- (UITableViewCell *)disclosureCellWithName:(NSString *)name iconName:(NSString *)iconName
|
|
|
|
{
|
|
|
|
UITableViewCell *cell = [self cellWithName:name iconName:iconName];
|
|
|
|
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)labelCellWithName:(NSString *)name iconName:(NSString *)iconName
|
|
|
|
{
|
|
|
|
UITableViewCell *cell = [self cellWithName:name iconName:iconName];
|
|
|
|
cell.accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2017-07-04 22:40:28 +02:00
|
|
|
- (UIView *)mainSectionHeader
|
2017-04-17 21:13:15 +02:00
|
|
|
{
|
2017-07-04 22:40:28 +02:00
|
|
|
UIView *mainSectionHeader = [UIView new];
|
2017-07-21 16:36:45 +02:00
|
|
|
UIView *threadInfoView = [UIView containerView];
|
2017-07-04 22:40:28 +02:00
|
|
|
[mainSectionHeader addSubview:threadInfoView];
|
2017-04-17 21:13:15 +02:00
|
|
|
[threadInfoView autoPinWidthToSuperviewWithMargin:16.f];
|
|
|
|
[threadInfoView autoPinHeightToSuperviewWithMargin:16.f];
|
|
|
|
|
2017-05-27 17:56:08 +02:00
|
|
|
const NSUInteger kAvatarSize = 68;
|
2017-07-31 22:07:38 +02:00
|
|
|
UIImage *avatarImage =
|
|
|
|
[OWSAvatarBuilder buildImageForThread:self.thread diameter:kAvatarSize contactsManager:self.contactsManager];
|
|
|
|
OWSAssert(avatarImage);
|
2017-05-27 17:56:08 +02:00
|
|
|
|
2017-07-31 22:07:38 +02:00
|
|
|
AvatarImageView *avatarView = [[AvatarImageView alloc] initWithImage:avatarImage];
|
2017-04-21 21:37:51 +02:00
|
|
|
_avatarView = avatarView;
|
2017-04-17 21:13:15 +02:00
|
|
|
[threadInfoView addSubview:avatarView];
|
|
|
|
[avatarView autoVCenterInSuperview];
|
2018-04-02 21:31:32 +02:00
|
|
|
[avatarView autoPinLeadingToSuperviewMargin];
|
2017-04-17 21:13:15 +02:00
|
|
|
[avatarView autoSetDimension:ALDimensionWidth toSize:kAvatarSize];
|
|
|
|
[avatarView autoSetDimension:ALDimensionHeight toSize:kAvatarSize];
|
|
|
|
|
2017-07-11 19:11:04 +02:00
|
|
|
UIView *threadNameView = [UIView containerView];
|
2017-04-17 21:13:15 +02:00
|
|
|
[threadInfoView addSubview:threadNameView];
|
|
|
|
[threadNameView autoVCenterInSuperview];
|
2018-04-02 21:31:32 +02:00
|
|
|
[threadNameView autoPinTrailingToSuperviewMargin];
|
|
|
|
[threadNameView autoPinLeadingToTrailingEdgeOfView:avatarView offset:16.f];
|
2017-04-17 21:13:15 +02:00
|
|
|
|
|
|
|
UILabel *threadTitleLabel = [UILabel new];
|
|
|
|
threadTitleLabel.text = self.threadName;
|
|
|
|
threadTitleLabel.textColor = [UIColor blackColor];
|
|
|
|
threadTitleLabel.font = [UIFont ows_dynamicTypeTitle2Font];
|
|
|
|
threadTitleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
[threadNameView addSubview:threadTitleLabel];
|
|
|
|
[threadTitleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop];
|
2017-07-11 19:24:47 +02:00
|
|
|
[threadTitleLabel autoPinWidthToSuperview];
|
2017-04-17 21:13:15 +02:00
|
|
|
|
2017-06-09 22:58:00 +02:00
|
|
|
__block UIView *lastTitleView = threadTitleLabel;
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
if (![self isGroupThread]) {
|
2017-06-09 22:58:00 +02:00
|
|
|
const CGFloat kSubtitlePointSize = 12.f;
|
|
|
|
void (^addSubtitle)(NSAttributedString *) = ^(NSAttributedString *subtitle) {
|
|
|
|
UILabel *subtitleLabel = [UILabel new];
|
|
|
|
subtitleLabel.textColor = [UIColor ows_darkGrayColor];
|
|
|
|
subtitleLabel.font = [UIFont ows_regularFontWithSize:kSubtitlePointSize];
|
|
|
|
subtitleLabel.attributedText = subtitle;
|
|
|
|
subtitleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
[threadNameView addSubview:subtitleLabel];
|
|
|
|
[subtitleLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:lastTitleView];
|
2018-04-02 21:31:32 +02:00
|
|
|
[subtitleLabel autoPinLeadingToSuperviewMargin];
|
2017-06-09 22:58:00 +02:00
|
|
|
lastTitleView = subtitleLabel;
|
|
|
|
};
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
NSString *recipientId = self.thread.contactIdentifier;
|
|
|
|
|
2017-06-09 22:58:00 +02:00
|
|
|
BOOL hasName = ![self.thread.name isEqualToString:recipientId];
|
|
|
|
if (hasName) {
|
|
|
|
NSAttributedString *subtitle = [[NSAttributedString alloc]
|
|
|
|
initWithString:[PhoneNumber
|
|
|
|
bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:recipientId]];
|
|
|
|
addSubtitle(subtitle);
|
2017-08-23 21:41:56 +02:00
|
|
|
} else {
|
|
|
|
NSString *_Nullable profileName = [self.contactsManager formattedProfileNameForRecipientId:recipientId];
|
|
|
|
if (profileName) {
|
|
|
|
addSubtitle([[NSAttributedString alloc] initWithString:profileName]);
|
|
|
|
}
|
2017-06-09 22:58:00 +02:00
|
|
|
}
|
2017-06-09 22:21:59 +02:00
|
|
|
|
2017-06-09 22:58:00 +02:00
|
|
|
BOOL isVerified = [[OWSIdentityManager sharedManager] verificationStateForRecipientId:recipientId]
|
|
|
|
== OWSVerificationStateVerified;
|
|
|
|
if (isVerified) {
|
|
|
|
NSMutableAttributedString *subtitle = [NSMutableAttributedString new];
|
|
|
|
// "checkmark"
|
|
|
|
[subtitle appendAttributedString:[[NSAttributedString alloc]
|
2018-07-18 04:20:31 +02:00
|
|
|
initWithString:LocalizationNotNeeded(@"\uf00c ")
|
2017-06-09 22:58:00 +02:00
|
|
|
attributes:@{
|
|
|
|
NSFontAttributeName :
|
|
|
|
[UIFont ows_fontAwesomeFont:kSubtitlePointSize],
|
|
|
|
}]];
|
|
|
|
[subtitle appendAttributedString:[[NSAttributedString alloc]
|
|
|
|
initWithString:NSLocalizedString(@"PRIVACY_IDENTITY_IS_VERIFIED_BADGE",
|
|
|
|
@"Badge indicating that the user is verified.")]];
|
|
|
|
addSubtitle(subtitle);
|
2017-06-09 22:21:59 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-17 21:13:15 +02:00
|
|
|
|
2017-06-09 22:58:00 +02:00
|
|
|
[lastTitleView autoPinEdgeToSuperviewEdge:ALEdgeBottom];
|
2017-04-17 21:13:15 +02:00
|
|
|
|
2017-07-04 22:40:28 +02:00
|
|
|
[mainSectionHeader
|
2017-05-02 18:30:53 +02:00
|
|
|
addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
|
|
|
|
action:@selector(conversationNameTouched:)]];
|
2017-07-04 22:40:28 +02:00
|
|
|
mainSectionHeader.userInteractionEnabled = YES;
|
2017-04-21 21:37:51 +02:00
|
|
|
|
2017-07-04 22:40:28 +02:00
|
|
|
return mainSectionHeader;
|
2017-04-17 21:13:15 +02:00
|
|
|
}
|
|
|
|
|
2017-04-21 21:37:51 +02:00
|
|
|
- (void)conversationNameTouched:(UIGestureRecognizer *)sender
|
|
|
|
{
|
2017-04-28 18:18:42 +02:00
|
|
|
if (sender.state == UIGestureRecognizerStateRecognized) {
|
2017-04-21 21:37:51 +02:00
|
|
|
if (self.isGroupThread) {
|
|
|
|
CGPoint location = [sender locationInView:self.avatarView];
|
|
|
|
if (CGRectContainsPoint(self.avatarView.bounds, location)) {
|
2017-05-02 16:54:07 +02:00
|
|
|
[self showUpdateGroupView:UpdateGroupMode_EditGroupAvatar];
|
2017-04-21 21:37:51 +02:00
|
|
|
} else {
|
2017-05-02 16:54:07 +02:00
|
|
|
[self showUpdateGroupView:UpdateGroupMode_EditGroupName];
|
2017-04-21 21:37:51 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-05-18 16:04:13 +02:00
|
|
|
if (self.contactsManager.supportsContactEditing) {
|
|
|
|
[self presentContactViewController];
|
|
|
|
}
|
2017-04-21 21:37:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
- (UIImageView *)viewForIconWithName:(NSString *)iconName
|
|
|
|
{
|
|
|
|
UIImage *icon = [UIImage imageNamed:iconName];
|
2018-01-20 17:27:32 +01:00
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
OWSAssert(icon);
|
|
|
|
UIImageView *iconView = [UIImageView new];
|
|
|
|
iconView.image = [icon imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
2018-01-22 22:53:55 +01:00
|
|
|
iconView.tintColor = [UIColor ows_darkIconColor];
|
2018-01-20 17:27:32 +01:00
|
|
|
iconView.contentMode = UIViewContentModeScaleAspectFit;
|
|
|
|
iconView.layer.minificationFilter = kCAFilterTrilinear;
|
|
|
|
iconView.layer.magnificationFilter = kCAFilterTrilinear;
|
|
|
|
|
2018-07-03 18:57:51 +02:00
|
|
|
[iconView autoSetDimensionsToSize:CGSizeMake(kIconViewLength, kIconViewLength)];
|
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
return iconView;
|
|
|
|
}
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
2017-03-19 20:11:57 +01:00
|
|
|
|
2018-07-19 00:48:02 +02:00
|
|
|
NSIndexPath *_Nullable selectedPath = [self.tableView indexPathForSelectedRow];
|
|
|
|
if (selectedPath) {
|
|
|
|
// HACK to unselect rows when swiping back
|
|
|
|
// http://stackoverflow.com/questions/19379510/uitableviewcell-doesnt-get-deselected-when-swiping-back-quickly
|
|
|
|
[self.tableView deselectRowAtIndexPath:selectedPath animated:animated];
|
|
|
|
}
|
2017-07-04 22:40:28 +02:00
|
|
|
|
|
|
|
[self updateTableContents];
|
2016-09-21 14:37:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
|
|
|
|
if (self.disappearingMessagesConfiguration.isNewRecord && !self.disappearingMessagesConfiguration.isEnabled) {
|
|
|
|
// don't save defaults, else we'll unintentionally save the configuration and notify the contact.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.disappearingMessagesConfiguration.dictionaryValueDidChange) {
|
|
|
|
[self.disappearingMessagesConfiguration save];
|
|
|
|
OWSDisappearingConfigurationUpdateInfoMessage *infoMessage =
|
|
|
|
[[OWSDisappearingConfigurationUpdateInfoMessage alloc]
|
2018-06-14 16:35:47 +02:00
|
|
|
initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
|
|
thread:self.thread
|
|
|
|
configuration:self.disappearingMessagesConfiguration
|
|
|
|
createdByRemoteName:nil
|
|
|
|
createdInExistingGroup:NO];
|
2016-09-21 14:37:51 +02:00
|
|
|
[infoMessage save];
|
|
|
|
|
|
|
|
[OWSNotifyRemoteOfUpdatedDisappearingConfigurationJob
|
|
|
|
runWithConfiguration:self.disappearingMessagesConfiguration
|
|
|
|
thread:self.thread
|
2016-10-14 22:59:58 +02:00
|
|
|
messageSender:self.messageSender];
|
2016-09-21 14:37:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Actions
|
|
|
|
|
2017-08-01 22:16:33 +02:00
|
|
|
- (void)showShareProfileAlert
|
|
|
|
{
|
2017-08-21 22:58:26 +02:00
|
|
|
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
|
|
|
|
|
2017-08-28 22:45:24 +02:00
|
|
|
[OWSProfileManager.sharedManager presentAddThreadToProfileWhitelist:self.thread
|
|
|
|
fromViewController:self
|
|
|
|
success:^{
|
|
|
|
[self updateTableContents];
|
|
|
|
}];
|
2017-08-01 22:16:33 +02:00
|
|
|
}
|
|
|
|
|
2017-06-09 22:21:59 +02:00
|
|
|
- (void)showVerificationView
|
|
|
|
{
|
2017-06-09 22:58:00 +02:00
|
|
|
NSString *recipientId = self.thread.contactIdentifier;
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
2017-06-15 22:20:33 +02:00
|
|
|
[FingerprintViewController presentFromViewController:self recipientId:recipientId];
|
2017-06-09 22:21:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showGroupMembersView
|
|
|
|
{
|
|
|
|
ShowGroupMembersViewController *showGroupMembersViewController = [ShowGroupMembersViewController new];
|
|
|
|
[showGroupMembersViewController configWithThread:(TSGroupThread *)self.thread];
|
|
|
|
[self.navigationController pushViewController:showGroupMembersViewController animated:YES];
|
|
|
|
}
|
|
|
|
|
2017-05-02 16:54:07 +02:00
|
|
|
- (void)showUpdateGroupView:(UpdateGroupMode)mode
|
|
|
|
{
|
|
|
|
OWSAssert(self.conversationSettingsViewDelegate);
|
|
|
|
|
|
|
|
UpdateGroupViewController *updateGroupViewController = [UpdateGroupViewController new];
|
|
|
|
updateGroupViewController.conversationSettingsViewDelegate = self.conversationSettingsViewDelegate;
|
|
|
|
updateGroupViewController.thread = (TSGroupThread *)self.thread;
|
|
|
|
updateGroupViewController.mode = mode;
|
2017-08-17 18:37:21 +02:00
|
|
|
[self.navigationController pushViewController:updateGroupViewController animated:YES];
|
2017-05-02 16:54:07 +02:00
|
|
|
}
|
|
|
|
|
2017-05-10 18:07:14 +02:00
|
|
|
- (void)presentContactViewController
|
|
|
|
{
|
2017-05-18 14:41:28 +02:00
|
|
|
if (!self.contactsManager.supportsContactEditing) {
|
2017-11-08 20:04:51 +01:00
|
|
|
OWSFail(@"%@ Contact editing not supported", self.logTag);
|
2017-05-18 14:41:28 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-05-10 18:07:14 +02:00
|
|
|
if (![self.thread isKindOfClass:[TSContactThread class]]) {
|
2017-11-08 20:04:51 +01:00
|
|
|
OWSFail(@"%@ unexpected thread: %@ in %s", self.logTag, self.thread, __PRETTY_FUNCTION__);
|
2017-05-10 18:07:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TSContactThread *contactThread = (TSContactThread *)self.thread;
|
|
|
|
[self.contactsViewHelper presentContactViewControllerForRecipientId:contactThread.contactIdentifier
|
|
|
|
fromViewController:self
|
|
|
|
editImmediately:YES];
|
2017-07-18 21:38:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)presentAddToContactViewControllerWithRecipientId:(NSString *)recipientId
|
|
|
|
{
|
|
|
|
if (!self.contactsManager.supportsContactEditing) {
|
|
|
|
// Should not expose UI that lets the user get here.
|
2017-11-08 20:04:51 +01:00
|
|
|
OWSFail(@"%@ Contact editing not supported.", self.logTag);
|
2017-07-18 21:38:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!self.contactsManager.isSystemContactsAuthorized) {
|
2017-07-19 15:33:17 +02:00
|
|
|
[self.contactsViewHelper presentMissingContactAccessAlertControllerFromViewController:self];
|
2017-07-18 21:38:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
OWSAddToContactViewController *viewController = [OWSAddToContactViewController new];
|
|
|
|
[viewController configureWithRecipientId:recipientId];
|
|
|
|
[self.navigationController pushViewController:viewController animated:YES];
|
2017-05-10 18:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didTapEditButton
|
|
|
|
{
|
|
|
|
[self presentContactViewController];
|
|
|
|
}
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
- (void)didTapLeaveGroup
|
|
|
|
{
|
2017-08-21 22:58:26 +02:00
|
|
|
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
UIAlertController *alertController =
|
|
|
|
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"CONFIRM_LEAVE_GROUP_TITLE", @"Alert title")
|
|
|
|
message:NSLocalizedString(@"CONFIRM_LEAVE_GROUP_DESCRIPTION", @"Alert body")
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
|
|
UIAlertAction *leaveAction = [UIAlertAction
|
|
|
|
actionWithTitle:NSLocalizedString(@"LEAVE_BUTTON_TITLE", @"Confirmation button within contextual alert")
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
handler:^(UIAlertAction *_Nonnull action) {
|
|
|
|
[self leaveGroup];
|
|
|
|
}];
|
|
|
|
[alertController addAction:leaveAction];
|
2017-08-21 22:58:26 +02:00
|
|
|
[alertController addAction:[OWSAlerts cancelAction]];
|
2016-09-21 14:37:51 +02:00
|
|
|
|
|
|
|
[self presentViewController:alertController animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)leaveGroup
|
|
|
|
{
|
|
|
|
TSGroupThread *gThread = (TSGroupThread *)self.thread;
|
2018-02-07 18:44:09 +01:00
|
|
|
TSOutgoingMessage *message =
|
2018-06-13 22:44:22 +02:00
|
|
|
[TSOutgoingMessage outgoingMessageInThread:gThread groupMetaMessage:TSGroupMessageQuit expiresInSeconds:0];
|
2017-11-15 19:21:31 +01:00
|
|
|
[self.messageSender enqueueMessage:message
|
2016-09-21 14:37:51 +02:00
|
|
|
success:^{
|
2017-11-08 20:04:51 +01:00
|
|
|
DDLogInfo(@"%@ Successfully left group.", self.logTag);
|
2016-09-21 14:37:51 +02:00
|
|
|
}
|
2016-10-14 22:59:58 +02:00
|
|
|
failure:^(NSError *error) {
|
2017-11-08 20:04:51 +01:00
|
|
|
DDLogWarn(@"%@ Failed to leave group with error: %@", self.logTag, error);
|
2016-09-21 14:37:51 +02:00
|
|
|
}];
|
|
|
|
|
|
|
|
NSMutableArray *newGroupMemberIds = [NSMutableArray arrayWithArray:gThread.groupModel.groupMemberIds];
|
2017-08-02 21:15:31 +02:00
|
|
|
[newGroupMemberIds removeObject:[self.accountManager localNumber]];
|
2016-09-21 14:37:51 +02:00
|
|
|
gThread.groupModel.groupMemberIds = newGroupMemberIds;
|
|
|
|
[gThread save];
|
|
|
|
|
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
|
|
}
|
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
- (void)disappearingMessagesSwitchValueDidChange:(UISwitch *)sender
|
2016-09-21 14:37:51 +02:00
|
|
|
{
|
|
|
|
UISwitch *disappearingMessagesSwitch = (UISwitch *)sender;
|
2017-04-17 21:13:15 +02:00
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
[self toggleDisappearingMessages:disappearingMessagesSwitch.isOn];
|
2017-04-03 16:29:11 +02:00
|
|
|
|
|
|
|
[self updateTableContents];
|
2016-09-21 14:37:51 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 16:29:11 +02:00
|
|
|
- (void)blockUserSwitchDidChange:(id)sender
|
2016-09-21 14:37:51 +02:00
|
|
|
{
|
2017-04-03 16:29:11 +02:00
|
|
|
OWSAssert(!self.isGroupThread);
|
2016-09-21 14:37:51 +02:00
|
|
|
|
2017-04-03 16:29:11 +02:00
|
|
|
if (![sender isKindOfClass:[UISwitch class]]) {
|
2017-11-08 20:04:51 +01:00
|
|
|
OWSFail(@"%@ Unexpected sender for block user switch: %@", self.logTag, sender);
|
2017-04-03 16:29:11 +02:00
|
|
|
}
|
|
|
|
UISwitch *blockUserSwitch = (UISwitch *)sender;
|
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
BOOL isCurrentlyBlocked = [[_blockingManager blockedPhoneNumbers] containsObject:self.thread.contactIdentifier];
|
2016-09-21 14:37:51 +02:00
|
|
|
|
2017-04-03 16:29:11 +02:00
|
|
|
if (blockUserSwitch.isOn) {
|
|
|
|
OWSAssert(!isCurrentlyBlocked);
|
|
|
|
if (isCurrentlyBlocked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[BlockListUIUtils showBlockPhoneNumberActionSheet:self.thread.contactIdentifier
|
|
|
|
fromViewController:self
|
|
|
|
blockingManager:_blockingManager
|
2017-04-04 16:19:47 +02:00
|
|
|
contactsManager:_contactsManager
|
2017-04-03 16:29:11 +02:00
|
|
|
completionBlock:^(BOOL isBlocked) {
|
|
|
|
// Update switch state if user cancels action.
|
|
|
|
blockUserSwitch.on = isBlocked;
|
|
|
|
}];
|
2016-09-21 14:37:51 +02:00
|
|
|
} else {
|
2017-04-03 16:29:11 +02:00
|
|
|
OWSAssert(isCurrentlyBlocked);
|
|
|
|
if (!isCurrentlyBlocked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
[BlockListUIUtils showUnblockPhoneNumberActionSheet:self.thread.contactIdentifier
|
|
|
|
fromViewController:self
|
|
|
|
blockingManager:_blockingManager
|
2017-04-04 16:19:47 +02:00
|
|
|
contactsManager:_contactsManager
|
2017-04-03 16:29:11 +02:00
|
|
|
completionBlock:^(BOOL isBlocked) {
|
|
|
|
// Update switch state if user cancels action.
|
|
|
|
blockUserSwitch.on = isBlocked;
|
|
|
|
}];
|
2016-09-21 14:37:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-03 16:29:11 +02:00
|
|
|
- (void)toggleDisappearingMessages:(BOOL)flag
|
2016-09-21 14:37:51 +02:00
|
|
|
{
|
2017-04-03 16:29:11 +02:00
|
|
|
self.disappearingMessagesConfiguration.enabled = flag;
|
|
|
|
|
2017-07-25 19:56:16 +02:00
|
|
|
[self updateTableContents];
|
2016-09-21 14:37:51 +02:00
|
|
|
}
|
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
- (void)durationSliderDidChange:(UISlider *)slider
|
2016-09-21 14:37:51 +02:00
|
|
|
{
|
|
|
|
// snap the slider to a valid value
|
|
|
|
NSUInteger index = (NSUInteger)(slider.value + 0.5);
|
|
|
|
[slider setValue:index animated:YES];
|
|
|
|
NSNumber *numberOfSeconds = self.disappearingMessagesDurations[index];
|
|
|
|
self.disappearingMessagesConfiguration.durationSeconds = [numberOfSeconds unsignedIntValue];
|
|
|
|
|
2017-04-17 21:13:15 +02:00
|
|
|
[self updateDisappearingMessagesDurationLabel];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateDisappearingMessagesDurationLabel
|
|
|
|
{
|
2016-09-21 14:37:51 +02:00
|
|
|
if (self.disappearingMessagesConfiguration.isEnabled) {
|
|
|
|
NSString *keepForFormat = NSLocalizedString(@"KEEP_MESSAGES_DURATION",
|
|
|
|
@"Slider label embeds {{TIME_AMOUNT}}, e.g. '2 hours'. See *_TIME_AMOUNT strings for examples.");
|
|
|
|
self.disappearingMessagesDurationLabel.text =
|
|
|
|
[NSString stringWithFormat:keepForFormat, self.disappearingMessagesConfiguration.durationString];
|
|
|
|
} else {
|
|
|
|
self.disappearingMessagesDurationLabel.text
|
|
|
|
= NSLocalizedString(@"KEEP_MESSAGES_FOREVER", @"Slider label when disappearing messages is off");
|
|
|
|
}
|
2017-04-17 21:13:15 +02:00
|
|
|
|
|
|
|
[self.disappearingMessagesDurationLabel setNeedsLayout];
|
|
|
|
[self.disappearingMessagesDurationLabel.superview setNeedsLayout];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showMuteUnmuteActionSheet
|
|
|
|
{
|
2017-04-18 18:41:56 +02:00
|
|
|
// The "unmute" action sheet has no title or message; the
|
|
|
|
// action label speaks for itself.
|
|
|
|
NSString *title = nil;
|
2017-04-17 21:13:15 +02:00
|
|
|
NSString *message = nil;
|
2017-04-18 18:41:56 +02:00
|
|
|
if (!self.thread.isMuted) {
|
2017-04-17 21:13:15 +02:00
|
|
|
title = NSLocalizedString(
|
|
|
|
@"CONVERSATION_SETTINGS_MUTE_ACTION_SHEET_TITLE", @"Title of the 'mute this thread' action sheet.");
|
|
|
|
message = NSLocalizedString(
|
|
|
|
@"MUTE_BEHAVIOR_EXPLANATION", @"An explanation of the consequences of muting a thread.");
|
|
|
|
}
|
|
|
|
|
|
|
|
UIAlertController *actionSheetController =
|
|
|
|
[UIAlertController alertControllerWithTitle:title
|
|
|
|
message:message
|
|
|
|
preferredStyle:UIAlertControllerStyleActionSheet];
|
|
|
|
|
2017-08-01 22:16:33 +02:00
|
|
|
__weak OWSConversationSettingsViewController *weakSelf = self;
|
2017-04-17 21:13:15 +02:00
|
|
|
if (self.thread.isMuted) {
|
|
|
|
UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"CONVERSATION_SETTINGS_UNMUTE_ACTION",
|
|
|
|
@"Label for button to unmute a thread.")
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
handler:^(UIAlertAction *_Nonnull ignore) {
|
|
|
|
[weakSelf setThreadMutedUntilDate:nil];
|
|
|
|
}];
|
|
|
|
[actionSheetController addAction:action];
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
[actionSheetController
|
|
|
|
addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CONVERSATION_SETTINGS_MUTE_ONE_MINUTE_ACTION",
|
|
|
|
@"Label for button to mute a thread for a minute.")
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
handler:^(UIAlertAction *_Nonnull ignore) {
|
|
|
|
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
|
|
|
|
NSCalendar *calendar = [NSCalendar currentCalendar];
|
|
|
|
[calendar setTimeZone:timeZone];
|
|
|
|
NSDateComponents *dateComponents = [NSDateComponents new];
|
|
|
|
[dateComponents setMinute:1];
|
|
|
|
NSDate *mutedUntilDate =
|
|
|
|
[calendar dateByAddingComponents:dateComponents
|
|
|
|
toDate:[NSDate date]
|
|
|
|
options:0];
|
|
|
|
[weakSelf setThreadMutedUntilDate:mutedUntilDate];
|
|
|
|
}]];
|
|
|
|
#endif
|
|
|
|
[actionSheetController
|
|
|
|
addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CONVERSATION_SETTINGS_MUTE_ONE_HOUR_ACTION",
|
|
|
|
@"Label for button to mute a thread for a hour.")
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
handler:^(UIAlertAction *_Nonnull ignore) {
|
|
|
|
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
|
|
|
|
NSCalendar *calendar = [NSCalendar currentCalendar];
|
|
|
|
[calendar setTimeZone:timeZone];
|
|
|
|
NSDateComponents *dateComponents = [NSDateComponents new];
|
|
|
|
[dateComponents setHour:1];
|
|
|
|
NSDate *mutedUntilDate =
|
|
|
|
[calendar dateByAddingComponents:dateComponents
|
|
|
|
toDate:[NSDate date]
|
|
|
|
options:0];
|
|
|
|
[weakSelf setThreadMutedUntilDate:mutedUntilDate];
|
|
|
|
}]];
|
|
|
|
[actionSheetController
|
|
|
|
addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CONVERSATION_SETTINGS_MUTE_ONE_DAY_ACTION",
|
|
|
|
@"Label for button to mute a thread for a day.")
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
handler:^(UIAlertAction *_Nonnull ignore) {
|
|
|
|
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
|
|
|
|
NSCalendar *calendar = [NSCalendar currentCalendar];
|
|
|
|
[calendar setTimeZone:timeZone];
|
|
|
|
NSDateComponents *dateComponents = [NSDateComponents new];
|
|
|
|
[dateComponents setDay:1];
|
|
|
|
NSDate *mutedUntilDate =
|
|
|
|
[calendar dateByAddingComponents:dateComponents
|
|
|
|
toDate:[NSDate date]
|
|
|
|
options:0];
|
|
|
|
[weakSelf setThreadMutedUntilDate:mutedUntilDate];
|
|
|
|
}]];
|
|
|
|
[actionSheetController
|
|
|
|
addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CONVERSATION_SETTINGS_MUTE_ONE_WEEK_ACTION",
|
|
|
|
@"Label for button to mute a thread for a week.")
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
handler:^(UIAlertAction *_Nonnull ignore) {
|
|
|
|
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
|
|
|
|
NSCalendar *calendar = [NSCalendar currentCalendar];
|
|
|
|
[calendar setTimeZone:timeZone];
|
|
|
|
NSDateComponents *dateComponents = [NSDateComponents new];
|
|
|
|
[dateComponents setDay:7];
|
|
|
|
NSDate *mutedUntilDate =
|
|
|
|
[calendar dateByAddingComponents:dateComponents
|
|
|
|
toDate:[NSDate date]
|
|
|
|
options:0];
|
|
|
|
[weakSelf setThreadMutedUntilDate:mutedUntilDate];
|
|
|
|
}]];
|
|
|
|
[actionSheetController
|
|
|
|
addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CONVERSATION_SETTINGS_MUTE_ONE_YEAR_ACTION",
|
|
|
|
@"Label for button to mute a thread for a year.")
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
handler:^(UIAlertAction *_Nonnull ignore) {
|
|
|
|
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
|
|
|
|
NSCalendar *calendar = [NSCalendar currentCalendar];
|
|
|
|
[calendar setTimeZone:timeZone];
|
|
|
|
NSDateComponents *dateComponents = [NSDateComponents new];
|
|
|
|
[dateComponents setYear:1];
|
|
|
|
NSDate *mutedUntilDate =
|
|
|
|
[calendar dateByAddingComponents:dateComponents
|
|
|
|
toDate:[NSDate date]
|
|
|
|
options:0];
|
|
|
|
[weakSelf setThreadMutedUntilDate:mutedUntilDate];
|
|
|
|
}]];
|
|
|
|
}
|
|
|
|
|
2017-08-21 22:58:26 +02:00
|
|
|
[actionSheetController addAction:[OWSAlerts cancelAction]];
|
2017-04-17 21:13:15 +02:00
|
|
|
|
|
|
|
[self presentViewController:actionSheetController animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setThreadMutedUntilDate:(nullable NSDate *)value
|
|
|
|
{
|
2018-06-28 19:28:14 +02:00
|
|
|
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction * _Nonnull transaction) {
|
|
|
|
[self.thread updateWithMutedUntilDate:value transaction:transaction];
|
|
|
|
}];
|
|
|
|
|
2017-07-25 19:56:16 +02:00
|
|
|
[self updateTableContents];
|
2016-09-21 14:37:51 +02:00
|
|
|
}
|
|
|
|
|
2018-03-15 18:46:29 +01:00
|
|
|
- (void)showMediaGallery
|
|
|
|
{
|
|
|
|
DDLogDebug(@"%@ in showMediaGallery", self.logTag);
|
|
|
|
|
2018-03-19 17:22:39 +01:00
|
|
|
MediaGalleryViewController *vc =
|
2018-03-20 14:56:39 +01:00
|
|
|
[[MediaGalleryViewController alloc] initWithThread:self.thread
|
|
|
|
uiDatabaseConnection:self.uiDatabaseConnection
|
|
|
|
options:MediaGalleryOptionSliderEnabled];
|
2018-03-19 17:22:39 +01:00
|
|
|
|
2018-03-19 20:20:33 +01:00
|
|
|
// although we don't present the mediaGalleryViewController directly, we need to maintain a strong
|
|
|
|
// reference to it until we're dismissed.
|
|
|
|
self.mediaGalleryViewController = vc;
|
|
|
|
|
2018-05-17 04:42:00 +02:00
|
|
|
OWSAssert([self.navigationController isKindOfClass:[OWSNavigationController class]]);
|
|
|
|
[vc pushTileViewFromNavController:(OWSNavigationController *)self.navigationController];
|
2018-03-15 18:46:29 +01:00
|
|
|
}
|
2017-06-09 22:21:59 +02:00
|
|
|
#pragma mark - Notifications
|
|
|
|
|
|
|
|
- (void)identityStateDidChange:(NSNotification *)notification
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
OWSAssertIsOnMainThread();
|
2017-06-09 22:21:59 +02:00
|
|
|
|
|
|
|
[self updateTableContents];
|
|
|
|
}
|
|
|
|
|
2017-08-23 23:09:43 +02:00
|
|
|
- (void)otherUsersProfileDidChange:(NSNotification *)notification
|
|
|
|
{
|
2017-12-19 17:38:25 +01:00
|
|
|
OWSAssertIsOnMainThread();
|
2017-08-23 23:09:43 +02:00
|
|
|
|
|
|
|
NSString *recipientId = notification.userInfo[kNSNotificationKey_ProfileRecipientId];
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
if (recipientId.length > 0 && [self.thread isKindOfClass:[TSContactThread class]] &&
|
|
|
|
[self.thread.contactIdentifier isEqualToString:recipientId]) {
|
|
|
|
[self updateTableContents];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-28 19:28:14 +02:00
|
|
|
#pragma mark - ColorPickerDelegate
|
|
|
|
|
|
|
|
- (void)showColorPicker
|
|
|
|
{
|
|
|
|
ColorPickerViewController *pickerController = [[ColorPickerViewController alloc] initWithThread:self.thread];
|
|
|
|
pickerController.delegate = self;
|
|
|
|
OWSNavigationController *modal = [[OWSNavigationController alloc] initWithRootViewController:pickerController];
|
|
|
|
|
|
|
|
[self presentViewController:modal animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)colorPicker:(ColorPickerViewController *)colorPicker didPickColorName:(NSString *)colorName
|
|
|
|
{
|
|
|
|
DDLogDebug(@"%@ in %s picked color: %@", self.logTag, __PRETTY_FUNCTION__, colorName);
|
|
|
|
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
|
|
|
[self.thread updateConversationColorName:colorName transaction:transaction];
|
|
|
|
}];
|
2018-07-04 04:28:17 +02:00
|
|
|
|
|
|
|
[self.contactsManager.avatarCache removeAllImages];
|
|
|
|
[self updateTableContents];
|
|
|
|
[self.conversationSettingsViewDelegate conversationColorWasUpdated];
|
|
|
|
|
2018-07-04 04:31:26 +02:00
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
|
|
|
ConversationConfigurationSyncOperation *operation =
|
|
|
|
[[ConversationConfigurationSyncOperation alloc] initWithThread:self.thread];
|
|
|
|
OWSAssert(operation.isReady);
|
|
|
|
[operation start];
|
|
|
|
});
|
2018-07-04 04:28:17 +02:00
|
|
|
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
2018-06-28 19:28:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)colorPickerDidCancel:(ColorPickerViewController *)colorPicker
|
|
|
|
{
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
2016-09-21 14:37:51 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|