2017-04-28 18:18:42 +02:00
|
|
|
//
|
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "UpdateGroupViewController.h"
|
|
|
|
#import "AddToGroupViewController.h"
|
2017-07-31 23:12:09 +02:00
|
|
|
#import "AvatarViewHelper.h"
|
2017-04-28 18:18:42 +02:00
|
|
|
#import "BlockListUIUtils.h"
|
|
|
|
#import "ContactTableViewCell.h"
|
|
|
|
#import "ContactsViewHelper.h"
|
|
|
|
#import "Environment.h"
|
|
|
|
#import "OWSContactsManager.h"
|
2017-08-17 18:37:21 +02:00
|
|
|
#import "OWSNavigationController.h"
|
2017-04-28 18:18:42 +02:00
|
|
|
#import "OWSTableViewController.h"
|
2017-05-08 19:29:10 +02:00
|
|
|
#import "Signal-Swift.h"
|
2017-04-28 18:18:42 +02:00
|
|
|
#import "SignalKeyingStorage.h"
|
|
|
|
#import "TSOutgoingMessage.h"
|
|
|
|
#import "UIUtil.h"
|
|
|
|
#import "UIView+OWS.h"
|
|
|
|
#import "UIViewController+OWS.h"
|
2017-05-02 16:54:07 +02:00
|
|
|
#import "ViewControllerUtils.h"
|
2017-04-28 18:18:42 +02:00
|
|
|
#import <SignalServiceKit/NSDate+millisecondTimeStamp.h>
|
|
|
|
#import <SignalServiceKit/OWSMessageSender.h>
|
2017-07-31 20:48:43 +02:00
|
|
|
#import <SignalServiceKit/SecurityUtils.h>
|
2017-05-05 18:33:10 +02:00
|
|
|
#import <SignalServiceKit/SignalAccount.h>
|
2017-04-28 18:18:42 +02:00
|
|
|
#import <SignalServiceKit/TSGroupModel.h>
|
|
|
|
#import <SignalServiceKit/TSGroupThread.h>
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@interface UpdateGroupViewController () <UIImagePickerControllerDelegate,
|
|
|
|
UITextFieldDelegate,
|
|
|
|
ContactsViewHelperDelegate,
|
2017-07-31 23:12:09 +02:00
|
|
|
AvatarViewHelperDelegate,
|
2017-04-28 18:18:42 +02:00
|
|
|
AddToGroupViewControllerDelegate,
|
|
|
|
OWSTableViewControllerDelegate,
|
2017-08-17 18:37:21 +02:00
|
|
|
UINavigationControllerDelegate,
|
|
|
|
OWSNavigationView>
|
2017-04-28 18:18:42 +02:00
|
|
|
|
|
|
|
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
|
|
|
@property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper;
|
2017-07-31 23:12:09 +02:00
|
|
|
@property (nonatomic, readonly) AvatarViewHelper *avatarViewHelper;
|
2017-04-28 18:18:42 +02:00
|
|
|
|
|
|
|
@property (nonatomic, readonly) OWSTableViewController *tableViewController;
|
2017-05-27 18:17:05 +02:00
|
|
|
@property (nonatomic, readonly) AvatarImageView *avatarView;
|
2017-04-28 18:18:42 +02:00
|
|
|
@property (nonatomic, readonly) UITextField *groupNameTextField;
|
|
|
|
|
|
|
|
@property (nonatomic, nullable) UIImage *groupAvatar;
|
|
|
|
@property (nonatomic, nullable) NSSet<NSString *> *previousMemberRecipientIds;
|
2017-05-02 16:54:07 +02:00
|
|
|
@property (nonatomic) NSMutableSet<NSString *> *memberRecipientIds;
|
2017-04-28 18:18:42 +02:00
|
|
|
|
|
|
|
@property (nonatomic) BOOL hasUnsavedChanges;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
@implementation UpdateGroupViewController
|
|
|
|
|
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self commonInit];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder
|
|
|
|
{
|
|
|
|
self = [super initWithCoder:aDecoder];
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self commonInit];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)commonInit
|
|
|
|
{
|
|
|
|
_messageSender = [Environment getCurrent].messageSender;
|
2017-05-12 17:09:25 +02:00
|
|
|
_contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self];
|
2017-07-31 23:12:09 +02:00
|
|
|
_avatarViewHelper = [AvatarViewHelper new];
|
|
|
|
_avatarViewHelper.delegate = self;
|
2017-04-28 18:18:42 +02:00
|
|
|
|
|
|
|
self.memberRecipientIds = [NSMutableSet new];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - View Lifecycle
|
|
|
|
|
|
|
|
- (void)loadView
|
|
|
|
{
|
|
|
|
[super loadView];
|
|
|
|
|
|
|
|
OWSAssert(self.thread);
|
|
|
|
OWSAssert(self.thread.groupModel);
|
|
|
|
OWSAssert(self.thread.groupModel.groupMemberIds);
|
|
|
|
|
|
|
|
[self.memberRecipientIds addObjectsFromArray:self.thread.groupModel.groupMemberIds];
|
|
|
|
self.previousMemberRecipientIds = [NSSet setWithArray:self.thread.groupModel.groupMemberIds];
|
|
|
|
|
2017-05-02 18:30:53 +02:00
|
|
|
self.title = NSLocalizedString(@"EDIT_GROUP_DEFAULT_TITLE", @"The navbar title for the 'update group' view.");
|
2017-04-28 18:18:42 +02:00
|
|
|
|
|
|
|
// First section.
|
|
|
|
|
|
|
|
UIView *firstSection = [self firstSectionHeader];
|
|
|
|
[self.view addSubview:firstSection];
|
|
|
|
[firstSection autoSetDimension:ALDimensionHeight toSize:100.f];
|
|
|
|
[firstSection autoPinWidthToSuperview];
|
|
|
|
[firstSection autoPinEdgeToSuperviewEdge:ALEdgeTop];
|
|
|
|
|
|
|
|
_tableViewController = [OWSTableViewController new];
|
|
|
|
_tableViewController.delegate = self;
|
|
|
|
[self.view addSubview:self.tableViewController.view];
|
|
|
|
[_tableViewController.view autoPinWidthToSuperview];
|
|
|
|
[_tableViewController.view autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:firstSection];
|
|
|
|
[_tableViewController.view autoPinEdgeToSuperviewEdge:ALEdgeBottom];
|
|
|
|
|
|
|
|
[self updateTableContents];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
|
|
[self.navigationController.navigationBar setTranslucent:NO];
|
|
|
|
}
|
|
|
|
|
2017-05-02 18:30:53 +02:00
|
|
|
- (void)setHasUnsavedChanges:(BOOL)hasUnsavedChanges
|
|
|
|
{
|
|
|
|
_hasUnsavedChanges = hasUnsavedChanges;
|
|
|
|
|
|
|
|
[self updateNavigationBar];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateNavigationBar
|
|
|
|
{
|
|
|
|
self.navigationItem.rightBarButtonItem = (self.hasUnsavedChanges
|
|
|
|
? [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"EDIT_GROUP_UPDATE_BUTTON",
|
|
|
|
@"The title for the 'update group' button.")
|
|
|
|
style:UIBarButtonItemStylePlain
|
|
|
|
target:self
|
|
|
|
action:@selector(updateGroupPressed)]
|
|
|
|
: nil);
|
|
|
|
}
|
|
|
|
|
2017-04-28 18:18:42 +02:00
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewDidAppear:animated];
|
|
|
|
|
2017-05-02 16:54:07 +02:00
|
|
|
switch (self.mode) {
|
|
|
|
case UpdateGroupMode_EditGroupName:
|
|
|
|
[self.groupNameTextField becomeFirstResponder];
|
|
|
|
break;
|
|
|
|
case UpdateGroupMode_EditGroupAvatar:
|
2017-07-31 23:12:09 +02:00
|
|
|
[self showChangeAvatarUI];
|
2017-05-02 16:54:07 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2017-04-28 18:18:42 +02:00
|
|
|
}
|
2017-05-02 16:54:07 +02:00
|
|
|
// Only perform these actions the first time the view appears.
|
|
|
|
self.mode = UpdateGroupMode_Default;
|
2017-04-28 18:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (UIView *)firstSectionHeader
|
|
|
|
{
|
2017-05-12 16:49:34 +02:00
|
|
|
OWSAssert(self.thread);
|
|
|
|
OWSAssert(self.thread.groupModel);
|
|
|
|
|
2017-04-28 18:18:42 +02:00
|
|
|
UIView *firstSectionHeader = [UIView new];
|
2017-07-26 15:29:29 +02:00
|
|
|
firstSectionHeader.userInteractionEnabled = YES;
|
|
|
|
[firstSectionHeader
|
|
|
|
addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headerWasTapped:)]];
|
2017-04-28 18:18:42 +02:00
|
|
|
firstSectionHeader.backgroundColor = [UIColor whiteColor];
|
|
|
|
UIView *threadInfoView = [UIView new];
|
|
|
|
[firstSectionHeader addSubview:threadInfoView];
|
|
|
|
[threadInfoView autoPinWidthToSuperviewWithMargin:16.f];
|
|
|
|
[threadInfoView autoPinHeightToSuperviewWithMargin:16.f];
|
|
|
|
|
|
|
|
const CGFloat kAvatarSize = 68.f;
|
2017-05-27 18:17:05 +02:00
|
|
|
AvatarImageView *avatarView = [AvatarImageView new];
|
2017-04-28 18:18:42 +02:00
|
|
|
_avatarView = avatarView;
|
2017-05-27 18:17:05 +02:00
|
|
|
|
2017-04-28 18:18:42 +02:00
|
|
|
[threadInfoView addSubview:avatarView];
|
|
|
|
[avatarView autoVCenterInSuperview];
|
2017-07-11 18:27:24 +02:00
|
|
|
[avatarView autoPinLeadingToSuperView];
|
2017-04-28 18:18:42 +02:00
|
|
|
[avatarView autoSetDimension:ALDimensionWidth toSize:kAvatarSize];
|
|
|
|
[avatarView autoSetDimension:ALDimensionHeight toSize:kAvatarSize];
|
2017-05-12 16:49:34 +02:00
|
|
|
_groupAvatar = self.thread.groupModel.groupImage;
|
2017-04-28 18:18:42 +02:00
|
|
|
[self updateAvatarView];
|
|
|
|
|
|
|
|
UITextField *groupNameTextField = [UITextField new];
|
|
|
|
_groupNameTextField = groupNameTextField;
|
2017-05-12 16:49:34 +02:00
|
|
|
self.groupNameTextField.text =
|
|
|
|
[self.thread.groupModel.groupName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
2017-04-28 18:18:42 +02:00
|
|
|
groupNameTextField.textColor = [UIColor blackColor];
|
|
|
|
groupNameTextField.font = [UIFont ows_dynamicTypeTitle2Font];
|
2017-05-02 18:30:53 +02:00
|
|
|
groupNameTextField.placeholder
|
|
|
|
= NSLocalizedString(@"NEW_GROUP_NAMEGROUP_REQUEST_DEFAULT", @"Placeholder text for group name field");
|
2017-04-28 18:18:42 +02:00
|
|
|
groupNameTextField.delegate = self;
|
|
|
|
[groupNameTextField addTarget:self
|
|
|
|
action:@selector(groupNameDidChange:)
|
|
|
|
forControlEvents:UIControlEventEditingChanged];
|
|
|
|
[threadInfoView addSubview:groupNameTextField];
|
|
|
|
[groupNameTextField autoVCenterInSuperview];
|
2017-07-11 18:27:24 +02:00
|
|
|
[groupNameTextField autoPinTrailingToSuperView];
|
|
|
|
[groupNameTextField autoPinLeadingToTrailingOfView:avatarView margin:16.f];
|
2017-04-28 18:18:42 +02:00
|
|
|
|
2017-05-02 18:30:53 +02:00
|
|
|
[avatarView
|
|
|
|
addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarTouched:)]];
|
2017-04-28 18:18:42 +02:00
|
|
|
avatarView.userInteractionEnabled = YES;
|
|
|
|
|
|
|
|
return firstSectionHeader;
|
|
|
|
}
|
|
|
|
|
2017-07-26 15:29:29 +02:00
|
|
|
- (void)headerWasTapped:(UIGestureRecognizer *)sender
|
|
|
|
{
|
|
|
|
if (sender.state == UIGestureRecognizerStateRecognized) {
|
|
|
|
[self.groupNameTextField becomeFirstResponder];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-28 18:18:42 +02:00
|
|
|
- (void)avatarTouched:(UIGestureRecognizer *)sender
|
|
|
|
{
|
|
|
|
if (sender.state == UIGestureRecognizerStateRecognized) {
|
2017-07-31 23:12:09 +02:00
|
|
|
[self showChangeAvatarUI];
|
2017-04-28 18:18:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Table Contents
|
|
|
|
|
|
|
|
- (void)updateTableContents
|
|
|
|
{
|
|
|
|
OWSAssert(self.thread);
|
|
|
|
|
|
|
|
OWSTableContents *contents = [OWSTableContents new];
|
|
|
|
|
|
|
|
__weak UpdateGroupViewController *weakSelf = self;
|
2017-05-02 16:54:07 +02:00
|
|
|
ContactsViewHelper *contactsViewHelper = self.contactsViewHelper;
|
2017-04-28 18:18:42 +02:00
|
|
|
|
|
|
|
// Group Members
|
|
|
|
|
|
|
|
OWSTableSection *section = [OWSTableSection new];
|
|
|
|
section.headerTitle = NSLocalizedString(
|
|
|
|
@"EDIT_GROUP_MEMBERS_SECTION_TITLE", @"a title for the members section of the 'new/update group' view.");
|
|
|
|
|
2017-07-11 22:00:32 +02:00
|
|
|
[section addItem:[OWSTableItem
|
|
|
|
disclosureItemWithText:NSLocalizedString(@"EDIT_GROUP_MEMBERS_ADD_MEMBER",
|
|
|
|
@"Label for the cell that lets you add a new member to a group.")
|
|
|
|
customRowHeight:[ContactTableViewCell rowHeight]
|
|
|
|
actionBlock:^{
|
|
|
|
AddToGroupViewController *viewController = [AddToGroupViewController new];
|
|
|
|
viewController.addToGroupDelegate = weakSelf;
|
|
|
|
[weakSelf.navigationController pushViewController:viewController animated:YES];
|
|
|
|
}]];
|
2017-04-28 18:18:42 +02:00
|
|
|
|
|
|
|
NSMutableSet *memberRecipientIds = [self.memberRecipientIds mutableCopy];
|
2017-05-02 16:54:07 +02:00
|
|
|
[memberRecipientIds removeObject:[contactsViewHelper localNumber]];
|
2017-04-28 18:18:42 +02:00
|
|
|
for (NSString *recipientId in [memberRecipientIds.allObjects sortedArrayUsingSelector:@selector(compare:)]) {
|
|
|
|
[section
|
|
|
|
addItem:[OWSTableItem itemWithCustomCellBlock:^{
|
|
|
|
UpdateGroupViewController *strongSelf = weakSelf;
|
2017-07-25 19:56:16 +02:00
|
|
|
OWSCAssert(strongSelf);
|
2017-04-28 18:18:42 +02:00
|
|
|
|
|
|
|
ContactTableViewCell *cell = [ContactTableViewCell new];
|
2017-05-02 16:54:07 +02:00
|
|
|
SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId];
|
2017-04-28 18:18:42 +02:00
|
|
|
BOOL isPreviousMember = [strongSelf.previousMemberRecipientIds containsObject:recipientId];
|
2017-05-02 16:54:07 +02:00
|
|
|
BOOL isBlocked = [contactsViewHelper isRecipientIdBlocked:recipientId];
|
2017-04-28 18:18:42 +02:00
|
|
|
if (isPreviousMember) {
|
|
|
|
if (isBlocked) {
|
|
|
|
cell.accessoryMessage = NSLocalizedString(
|
|
|
|
@"CONTACT_CELL_IS_BLOCKED", @"An indicator that a contact has been blocked.");
|
|
|
|
} else {
|
|
|
|
cell.selectionStyle = UITableViewCellSeparatorStyleNone;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// In the "members" section, we label "new" members as such when editing an existing group.
|
|
|
|
//
|
|
|
|
// The only way a "new" member could be blocked is if we blocked them on a linked device
|
|
|
|
// while in this dialog. We don't need to worry about that edge case.
|
|
|
|
cell.accessoryMessage = NSLocalizedString(
|
|
|
|
@"EDIT_GROUP_NEW_MEMBER_LABEL", @"An indicator that a user is a new member of the group.");
|
|
|
|
}
|
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
if (signalAccount) {
|
2017-05-02 16:54:07 +02:00
|
|
|
[cell configureWithSignalAccount:signalAccount contactsManager:contactsViewHelper.contactsManager];
|
2017-04-28 18:18:42 +02:00
|
|
|
} else {
|
2017-05-02 16:54:07 +02:00
|
|
|
[cell configureWithRecipientId:recipientId contactsManager:contactsViewHelper.contactsManager];
|
2017-04-28 18:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
customRowHeight:[ContactTableViewCell rowHeight]
|
|
|
|
actionBlock:^{
|
2017-05-02 16:54:07 +02:00
|
|
|
SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId];
|
2017-04-28 18:18:42 +02:00
|
|
|
BOOL isPreviousMember = [weakSelf.previousMemberRecipientIds containsObject:recipientId];
|
2017-05-02 16:54:07 +02:00
|
|
|
BOOL isBlocked = [contactsViewHelper isRecipientIdBlocked:recipientId];
|
2017-04-28 18:18:42 +02:00
|
|
|
if (isPreviousMember) {
|
|
|
|
if (isBlocked) {
|
2017-05-01 18:51:59 +02:00
|
|
|
if (signalAccount) {
|
|
|
|
[weakSelf showUnblockAlertForSignalAccount:signalAccount];
|
2017-04-28 18:18:42 +02:00
|
|
|
} else {
|
|
|
|
[weakSelf showUnblockAlertForRecipientId:recipientId];
|
|
|
|
}
|
|
|
|
} else {
|
2017-05-08 19:29:10 +02:00
|
|
|
[OWSAlerts
|
2017-05-02 16:54:07 +02:00
|
|
|
showAlertWithTitle:
|
|
|
|
NSLocalizedString(@"UPDATE_GROUP_CANT_REMOVE_MEMBERS_ALERT_TITLE",
|
|
|
|
@"Title for alert indicating that group members can't be removed.")
|
|
|
|
message:NSLocalizedString(
|
|
|
|
@"UPDATE_GROUP_CANT_REMOVE_MEMBERS_ALERT_MESSAGE",
|
|
|
|
@"Title for alert indicating that group members can't "
|
|
|
|
@"be removed.")];
|
2017-04-28 18:18:42 +02:00
|
|
|
}
|
2017-05-02 16:54:07 +02:00
|
|
|
} else {
|
|
|
|
[weakSelf removeRecipientId:recipientId];
|
2017-04-28 18:18:42 +02:00
|
|
|
}
|
|
|
|
}]];
|
|
|
|
}
|
|
|
|
[contents addSection:section];
|
|
|
|
|
|
|
|
self.tableViewController.contents = contents;
|
|
|
|
}
|
|
|
|
|
2017-05-01 18:51:59 +02:00
|
|
|
- (void)showUnblockAlertForSignalAccount:(SignalAccount *)signalAccount
|
2017-04-28 18:18:42 +02:00
|
|
|
{
|
2017-05-01 18:51:59 +02:00
|
|
|
OWSAssert(signalAccount);
|
2017-04-28 18:18:42 +02:00
|
|
|
|
|
|
|
__weak UpdateGroupViewController *weakSelf = self;
|
2017-05-01 18:51:59 +02:00
|
|
|
[BlockListUIUtils showUnblockSignalAccountActionSheet:signalAccount
|
|
|
|
fromViewController:self
|
2017-05-02 16:54:07 +02:00
|
|
|
blockingManager:self.contactsViewHelper.blockingManager
|
|
|
|
contactsManager:self.contactsViewHelper.contactsManager
|
2017-05-01 18:51:59 +02:00
|
|
|
completionBlock:^(BOOL isBlocked) {
|
|
|
|
if (!isBlocked) {
|
|
|
|
[weakSelf updateTableContents];
|
|
|
|
}
|
|
|
|
}];
|
2017-04-28 18:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showUnblockAlertForRecipientId:(NSString *)recipientId
|
|
|
|
{
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
__weak UpdateGroupViewController *weakSelf = self;
|
|
|
|
[BlockListUIUtils showUnblockPhoneNumberActionSheet:recipientId
|
|
|
|
fromViewController:self
|
2017-05-02 16:54:07 +02:00
|
|
|
blockingManager:self.contactsViewHelper.blockingManager
|
|
|
|
contactsManager:self.contactsViewHelper.contactsManager
|
2017-04-28 18:18:42 +02:00
|
|
|
completionBlock:^(BOOL isBlocked) {
|
|
|
|
if (!isBlocked) {
|
|
|
|
[weakSelf updateTableContents];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)removeRecipientId:(NSString *)recipientId
|
|
|
|
{
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
[self.memberRecipientIds removeObject:recipientId];
|
|
|
|
[self updateTableContents];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Methods
|
|
|
|
|
|
|
|
- (void)updateGroup
|
|
|
|
{
|
2017-05-02 16:54:07 +02:00
|
|
|
OWSAssert(self.conversationSettingsViewDelegate);
|
2017-04-28 18:18:42 +02:00
|
|
|
|
2017-05-12 16:46:59 +02:00
|
|
|
NSString *groupName =
|
|
|
|
[self.groupNameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
TSGroupModel *groupModel = [[TSGroupModel alloc] initWithTitle:groupName
|
2017-04-28 18:18:42 +02:00
|
|
|
memberIds:[self.memberRecipientIds.allObjects mutableCopy]
|
|
|
|
image:self.groupAvatar
|
|
|
|
groupId:self.thread.groupModel.groupId];
|
2017-05-02 16:54:07 +02:00
|
|
|
[self.conversationSettingsViewDelegate groupWasUpdated:groupModel];
|
2017-04-28 18:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Group Avatar
|
|
|
|
|
2017-07-31 23:12:09 +02:00
|
|
|
- (void)showChangeAvatarUI
|
2017-04-28 18:18:42 +02:00
|
|
|
{
|
|
|
|
[self.groupNameTextField resignFirstResponder];
|
|
|
|
|
2017-07-31 23:12:09 +02:00
|
|
|
[self.avatarViewHelper showChangeAvatarUI];
|
2017-04-28 18:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setGroupAvatar:(nullable UIImage *)groupAvatar
|
|
|
|
{
|
|
|
|
OWSAssert([NSThread isMainThread]);
|
|
|
|
|
|
|
|
_groupAvatar = groupAvatar;
|
|
|
|
|
|
|
|
self.hasUnsavedChanges = YES;
|
|
|
|
|
|
|
|
[self updateAvatarView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateAvatarView
|
|
|
|
{
|
2017-05-27 18:17:05 +02:00
|
|
|
self.avatarView.image = (self.groupAvatar ?: [UIImage imageNamed:@"empty-group-avatar"]);
|
2017-04-28 18:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Event Handling
|
|
|
|
|
2017-08-17 18:37:21 +02:00
|
|
|
- (void)backButtonPressed
|
2017-04-28 18:18:42 +02:00
|
|
|
{
|
|
|
|
[self.groupNameTextField resignFirstResponder];
|
|
|
|
|
|
|
|
if (!self.hasUnsavedChanges) {
|
|
|
|
// If user made no changes, return to conversation settings view.
|
2017-08-17 18:37:21 +02:00
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
2017-04-28 18:18:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UIAlertController *controller = [UIAlertController
|
|
|
|
alertControllerWithTitle:NSLocalizedString(@"EDIT_GROUP_VIEW_UNSAVED_CHANGES_TITLE",
|
|
|
|
@"The alert title if user tries to exit update group view without saving changes.")
|
|
|
|
message:
|
|
|
|
NSLocalizedString(@"EDIT_GROUP_VIEW_UNSAVED_CHANGES_MESSAGE",
|
|
|
|
@"The alert message if user tries to exit update group view without saving changes.")
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
2017-05-02 16:54:07 +02:00
|
|
|
[controller
|
|
|
|
addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"ALERT_SAVE",
|
|
|
|
@"The label for the 'save' button in action sheets.")
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
handler:^(UIAlertAction *action) {
|
|
|
|
OWSAssert(self.conversationSettingsViewDelegate);
|
2017-04-28 18:18:42 +02:00
|
|
|
|
2017-05-02 16:54:07 +02:00
|
|
|
[self updateGroup];
|
2017-04-28 18:18:42 +02:00
|
|
|
|
2017-05-02 16:54:07 +02:00
|
|
|
[self.conversationSettingsViewDelegate popAllConversationSettingsViews];
|
|
|
|
}]];
|
2017-04-28 18:18:42 +02:00
|
|
|
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"ALERT_DONT_SAVE",
|
|
|
|
@"The label for the 'don't save' button in action sheets.")
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
handler:^(UIAlertAction *action) {
|
2017-08-17 18:37:21 +02:00
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
2017-04-28 18:18:42 +02:00
|
|
|
}]];
|
|
|
|
[self presentViewController:controller animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
2017-05-02 18:30:53 +02:00
|
|
|
- (void)updateGroupPressed
|
|
|
|
{
|
|
|
|
OWSAssert(self.conversationSettingsViewDelegate);
|
|
|
|
|
|
|
|
[self updateGroup];
|
|
|
|
|
|
|
|
[self.conversationSettingsViewDelegate popAllConversationSettingsViews];
|
|
|
|
}
|
2017-04-28 18:18:42 +02:00
|
|
|
|
|
|
|
- (void)groupNameDidChange:(id)sender
|
|
|
|
{
|
|
|
|
self.hasUnsavedChanges = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Text Field Delegate
|
|
|
|
|
|
|
|
- (BOOL)textFieldShouldReturn:(UITextField *)textField
|
|
|
|
{
|
|
|
|
[self.groupNameTextField resignFirstResponder];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - OWSTableViewControllerDelegate
|
|
|
|
|
|
|
|
- (void)tableViewDidScroll
|
|
|
|
{
|
|
|
|
[self.groupNameTextField resignFirstResponder];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - ContactsViewHelperDelegate
|
|
|
|
|
|
|
|
- (void)contactsViewHelperDidUpdateContacts
|
|
|
|
{
|
|
|
|
[self updateTableContents];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)shouldHideLocalNumber
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2017-07-31 23:12:09 +02:00
|
|
|
#pragma mark - AvatarViewHelperDelegate
|
2017-04-28 18:18:42 +02:00
|
|
|
|
2017-08-01 17:31:00 +02:00
|
|
|
- (NSString *)avatarActionSheetTitle
|
|
|
|
{
|
|
|
|
return NSLocalizedString(
|
|
|
|
@"NEW_GROUP_ADD_PHOTO_ACTION", @"Action Sheet title prompting the user for a group avatar");
|
|
|
|
}
|
|
|
|
|
2017-07-31 23:12:09 +02:00
|
|
|
- (void)avatarDidChange:(UIImage *)image
|
2017-04-28 18:18:42 +02:00
|
|
|
{
|
|
|
|
OWSAssert(image);
|
|
|
|
|
|
|
|
self.groupAvatar = image;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIViewController *)fromViewController
|
|
|
|
{
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-08-01 17:58:51 +02:00
|
|
|
- (BOOL)hasClearAvatarAction
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2017-04-28 18:18:42 +02:00
|
|
|
#pragma mark - AddToGroupViewControllerDelegate
|
|
|
|
|
|
|
|
- (void)recipientIdWasAdded:(NSString *)recipientId
|
|
|
|
{
|
|
|
|
[self.memberRecipientIds addObject:recipientId];
|
|
|
|
self.hasUnsavedChanges = YES;
|
|
|
|
[self updateTableContents];
|
|
|
|
}
|
|
|
|
|
2017-05-02 16:54:07 +02:00
|
|
|
- (BOOL)isRecipientGroupMember:(NSString *)recipientId
|
|
|
|
{
|
|
|
|
OWSAssert(recipientId.length > 0);
|
|
|
|
|
|
|
|
return [self.memberRecipientIds containsObject:recipientId];
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:37:21 +02:00
|
|
|
#pragma mark - OWSNavigationView
|
|
|
|
|
|
|
|
- (void)navBackButtonPressed
|
|
|
|
{
|
|
|
|
[self backButtonPressed];
|
|
|
|
}
|
|
|
|
|
2017-04-28 18:18:42 +02:00
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|