@ -19,6 +19,7 @@
#import "UIUtil . h "
#import "UIUtil . h "
#import "UIView + OWS . h "
#import "UIView + OWS . h "
#import "UIViewController + OWS . h "
#import "UIViewController + OWS . h "
#import "ViewControllerUtils . h "
#import < SignalServiceKit / NSDate + millisecondTimeStamp . h >
#import < SignalServiceKit / NSDate + millisecondTimeStamp . h >
#import < SignalServiceKit / OWSMessageSender . h >
#import < SignalServiceKit / OWSMessageSender . h >
#import < SignalServiceKit / TSGroupModel . h >
#import < SignalServiceKit / TSGroupModel . h >
@ -44,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN
@ property ( nonatomic , nullable ) UIImage * groupAvatar ;
@ property ( nonatomic , nullable ) UIImage * groupAvatar ;
@ property ( nonatomic , nullable ) NSSet < NSString * > * previousMemberRecipientIds ;
@ property ( nonatomic , nullable ) NSSet < NSString * > * previousMemberRecipientIds ;
@ property ( nonatomic , nullable ) NSMutableSet < NSString * > * memberRecipientIds ;
@ property ( nonatomic ) NSMutableSet < NSString * > * memberRecipientIds ;
@ property ( nonatomic ) BOOL hasUnsavedChanges ;
@ property ( nonatomic ) BOOL hasUnsavedChanges ;
@ -135,13 +136,18 @@ NS_ASSUME_NONNULL_BEGIN
{
{
[ super viewDidAppear : animated ] ;
[ super viewDidAppear : animated ] ;
if ( self . shouldEditGroupNameOnAppear ) {
switch ( self . mode ) {
[ self . groupNameTextField becomeFirstResponder ] ;
case UpdateGroupMode_EditGroupName :
} else if ( self . shouldEditAvatarOnAppear ) {
[ self . groupNameTextField becomeFirstResponder ] ;
[ self showChangeGroupAvatarUI : nil ] ;
break ;
case UpdateGroupMode_EditGroupAvatar :
[ self showChangeGroupAvatarUI ] ;
break ;
default :
break ;
}
}
self . shouldEditGroupNameOnAppear = NO ;
/ / Only perform these actions the first time the view appears .
self . shouldEditAvatarOnAppear = NO ;
self . mode = UpdateGroupMode_Default ;
}
}
- ( UIView * ) firstSectionHeader
- ( UIView * ) firstSectionHeader
@ -197,7 +203,7 @@ NS_ASSUME_NONNULL_BEGIN
- ( void ) avatarTouched : ( UIGestureRecognizer * ) sender
- ( void ) avatarTouched : ( UIGestureRecognizer * ) sender
{
{
if ( sender . state == UIGestureRecognizerStateRecognized ) {
if ( sender . state == UIGestureRecognizerStateRecognized ) {
[ self showChangeGroupAvatarUI :nil ];
[ self showChangeGroupAvatarUI ];
}
}
}
}
@ -210,7 +216,7 @@ NS_ASSUME_NONNULL_BEGIN
OWSTableContents * contents = [ OWSTableContents new ] ;
OWSTableContents * contents = [ OWSTableContents new ] ;
__weak UpdateGroupViewController * weakSelf = self ;
__weak UpdateGroupViewController * weakSelf = self ;
ContactsViewHelper * h elper = self . contactsViewHelper ;
ContactsViewHelper * contactsViewH elper = self . contactsViewHelper ;
/ / Group Members
/ / Group Members
@ -235,7 +241,7 @@ NS_ASSUME_NONNULL_BEGIN
} ] ] ;
} ] ] ;
NSMutableSet * memberRecipientIds = [ self . memberRecipientIds mutableCopy ] ;
NSMutableSet * memberRecipientIds = [ self . memberRecipientIds mutableCopy ] ;
[ memberRecipientIds removeObject : [ h elper localNumber ] ] ;
[ memberRecipientIds removeObject : [ contactsViewH elper localNumber ] ] ;
for ( NSString * recipientId in [ memberRecipientIds . allObjects sortedArrayUsingSelector : @ selector ( compare : ) ] ) {
for ( NSString * recipientId in [ memberRecipientIds . allObjects sortedArrayUsingSelector : @ selector ( compare : ) ] ) {
[ section
[ section
addItem : [ OWSTableItem itemWithCustomCellBlock : ^{
addItem : [ OWSTableItem itemWithCustomCellBlock : ^{
@ -245,9 +251,9 @@ NS_ASSUME_NONNULL_BEGIN
}
}
ContactTableViewCell * cell = [ ContactTableViewCell new ] ;
ContactTableViewCell * cell = [ ContactTableViewCell new ] ;
SignalAccount * signalAccount = [ h elper signalAccountForRecipientId : recipientId ] ;
SignalAccount * signalAccount = [ contactsViewH elper signalAccountForRecipientId : recipientId ] ;
BOOL isPreviousMember = [ strongSelf . previousMemberRecipientIds containsObject : recipientId ] ;
BOOL isPreviousMember = [ strongSelf . previousMemberRecipientIds containsObject : recipientId ] ;
BOOL isBlocked = [ h elper isRecipientIdBlocked : recipientId ] ;
BOOL isBlocked = [ contactsViewH elper isRecipientIdBlocked : recipientId ] ;
if ( isPreviousMember ) {
if ( isPreviousMember ) {
if ( isBlocked ) {
if ( isBlocked ) {
cell . accessoryMessage = NSLocalizedString (
cell . accessoryMessage = NSLocalizedString (
@ -265,18 +271,18 @@ NS_ASSUME_NONNULL_BEGIN
}
}
if ( signalAccount ) {
if ( signalAccount ) {
[ cell configureWithSignalAccount : signalAccount contactsManager : h elper. contactsManager ] ;
[ cell configureWithSignalAccount : signalAccount contactsManager : contactsViewH elper. contactsManager ] ;
} else {
} else {
[ cell configureWithRecipientId : recipientId contactsManager : h elper. contactsManager ] ;
[ cell configureWithRecipientId : recipientId contactsManager : contactsViewH elper. contactsManager ] ;
}
}
return cell ;
return cell ;
}
}
customRowHeight : [ ContactTableViewCell rowHeight ]
customRowHeight : [ ContactTableViewCell rowHeight ]
actionBlock : ^{
actionBlock : ^{
SignalAccount * signalAccount = [ h elper signalAccountForRecipientId : recipientId ] ;
SignalAccount * signalAccount = [ contactsViewH elper signalAccountForRecipientId : recipientId ] ;
BOOL isPreviousMember = [ weakSelf . previousMemberRecipientIds containsObject : recipientId ] ;
BOOL isPreviousMember = [ weakSelf . previousMemberRecipientIds containsObject : recipientId ] ;
BOOL isBlocked = [ h elper isRecipientIdBlocked : recipientId ] ;
BOOL isBlocked = [ contactsViewH elper isRecipientIdBlocked : recipientId ] ;
if ( isPreviousMember ) {
if ( isPreviousMember ) {
if ( isBlocked ) {
if ( isBlocked ) {
if ( signalAccount ) {
if ( signalAccount ) {
@ -284,25 +290,18 @@ NS_ASSUME_NONNULL_BEGIN
} else {
} else {
[ weakSelf showUnblockAlertForRecipientId : recipientId ] ;
[ weakSelf showUnblockAlertForRecipientId : recipientId ] ;
}
}
}
} else {
if ( signalAccount ) {
[ weakSelf . groupViewHelper
showRemoveFromGroupAlertForSignalAccount : signalAccount
fromViewController : weakSelf
contactsManager : helper . contactsManager
successBlock : ^{
[ weakSelf removeSignalAccount : signalAccount ] ;
} ] ;
} else {
} else {
[ weakSelf . groupViewHelper
[ ViewControllerUtils
showRemoveFromGroupAlertForRecipientId : recipientId
showAlertWithTitle :
fromViewController : weakSelf
NSLocalizedString ( @ "UPDATE_GROUP_CANT_REMOVE_MEMBERS_ALERT_TITLE ",
contactsManager : helper . contactsManager
@ "Title for alert indicating that group members can ' t be removed . ")
successBlock : ^{
message : NSLocalizedString (
[ weakSelf removeRecipientId : recipientId ] ;
@ "UPDATE_GROUP_CANT_REMOVE_MEMBERS_ALERT_MESSAGE ",
} ] ;
@ "Title for alert indicating that group members can ' t "
@ "be removed . ") ] ;
}
}
} else {
[ weakSelf removeRecipientId : recipientId ] ;
}
}
} ] ] ;
} ] ] ;
}
}
@ -316,11 +315,10 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert ( signalAccount ) ;
OWSAssert ( signalAccount ) ;
__weak UpdateGroupViewController * weakSelf = self ;
__weak UpdateGroupViewController * weakSelf = self ;
ContactsViewHelper * helper = self . contactsViewHelper ;
[ BlockListUIUtils showUnblockSignalAccountActionSheet : signalAccount
[ BlockListUIUtils showUnblockSignalAccountActionSheet : signalAccount
fromViewController : self
fromViewController : self
blockingManager : h elper. blockingManager
blockingManager : self. contactsViewH elper. blockingManager
contactsManager : h elper. contactsManager
contactsManager : self. contactsViewH elper. contactsManager
completionBlock : ^( BOOL isBlocked ) {
completionBlock : ^( BOOL isBlocked ) {
if ( !isBlocked ) {
if ( !isBlocked ) {
[ weakSelf updateTableContents ] ;
[ weakSelf updateTableContents ] ;
@ -333,11 +331,10 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert ( recipientId . length > 0 ) ;
OWSAssert ( recipientId . length > 0 ) ;
__weak UpdateGroupViewController * weakSelf = self ;
__weak UpdateGroupViewController * weakSelf = self ;
ContactsViewHelper * helper = self . contactsViewHelper ;
[ BlockListUIUtils showUnblockPhoneNumberActionSheet : recipientId
[ BlockListUIUtils showUnblockPhoneNumberActionSheet : recipientId
fromViewController : self
fromViewController : self
blockingManager : h elper. blockingManager
blockingManager : self. contactsViewH elper. blockingManager
contactsManager : h elper. contactsManager
contactsManager : self. contactsViewH elper. contactsManager
completionBlock : ^( BOOL isBlocked ) {
completionBlock : ^( BOOL isBlocked ) {
if ( !isBlocked ) {
if ( !isBlocked ) {
[ weakSelf updateTableContents ] ;
[ weakSelf updateTableContents ] ;
@ -345,14 +342,6 @@ NS_ASSUME_NONNULL_BEGIN
} ] ;
} ] ;
}
}
- ( void ) removeSignalAccount : ( SignalAccount * ) signalAccount
{
OWSAssert ( signalAccount ) ;
[ self . memberRecipientIds removeObject : signalAccount . recipientId ] ;
[ self updateTableContents ] ;
}
- ( void ) removeRecipientId : ( NSString * ) recipientId
- ( void ) removeRecipientId : ( NSString * ) recipientId
{
{
OWSAssert ( recipientId . length > 0 ) ;
OWSAssert ( recipientId . length > 0 ) ;
@ -365,18 +354,18 @@ NS_ASSUME_NONNULL_BEGIN
- ( void ) updateGroup
- ( void ) updateGroup
{
{
OWSAssert ( self . d elegate) ;
OWSAssert ( self . conversationSettingsViewD elegate) ;
TSGroupModel * groupModel = [ [ TSGroupModel alloc ] initWithTitle : self . groupNameTextField . text
TSGroupModel * groupModel = [ [ TSGroupModel alloc ] initWithTitle : self . groupNameTextField . text
memberIds : [ self . memberRecipientIds . allObjects mutableCopy ]
memberIds : [ self . memberRecipientIds . allObjects mutableCopy ]
image : self . groupAvatar
image : self . groupAvatar
groupId : self . thread . groupModel . groupId ] ;
groupId : self . thread . groupModel . groupId ] ;
[ self . d elegate groupWasUpdated : groupModel ] ;
[ self . conversationSettingsViewD elegate groupWasUpdated : groupModel ] ;
}
}
#pragma mark - Group Avatar
#pragma mark - Group Avatar
- ( void ) showChangeGroupAvatarUI : ( nullable id ) sender
- ( void ) showChangeGroupAvatarUI
{
{
[ self . groupNameTextField resignFirstResponder ] ;
[ self . groupNameTextField resignFirstResponder ] ;
@ -413,7 +402,7 @@ NS_ASSUME_NONNULL_BEGIN
if ( !self . hasUnsavedChanges ) {
if ( !self . hasUnsavedChanges ) {
/ / If user made no changes , return to conversation settings view .
/ / If user made no changes , return to conversation settings view .
[ self . navigationController popViewControllerAnimated : YES ] ;
[ self dismissViewControllerAnimated : YES completion : nil ] ;
return ;
return ;
}
}
@ -424,21 +413,22 @@ NS_ASSUME_NONNULL_BEGIN
NSLocalizedString ( @ "EDIT_GROUP_VIEW_UNSAVED_CHANGES_MESSAGE ",
NSLocalizedString ( @ "EDIT_GROUP_VIEW_UNSAVED_CHANGES_MESSAGE ",
@ "The alert message if user tries to exit update group view without saving changes . ")
@ "The alert message if user tries to exit update group view without saving changes . ")
preferredStyle : UIAlertControllerStyleAlert ] ;
preferredStyle : UIAlertControllerStyleAlert ] ;
[ controller addAction : [ UIAlertAction actionWithTitle : NSLocalizedString ( @ "ALERT_SAVE ",
[ controller
@ "The label for the ' save' button in action sheets . ")
addAction : [ UIAlertAction actionWithTitle : NSLocalizedString ( @ "ALERT_SAVE ",
style : UIAlertActionStyleDefault
@ "The label for the ' save' button in action sheets . ")
handler : ^( UIAlertAction * action ) {
style : UIAlertActionStyleDefault
OWSAssert ( self . delegate ) ;
handler : ^( UIAlertAction * action ) {
OWSAssert ( self . conversationSettingsViewDelegate ) ;
[ self updateGroup ] ;
[ self updateGroup ] ;
[ self . d elegate popAllConversationSettingsViews ] ;
[ self . conversationSettingsViewD elegate popAllConversationSettingsViews ] ;
} ] ] ;
} ] ] ;
[ controller addAction : [ UIAlertAction actionWithTitle : NSLocalizedString ( @ "ALERT_DONT_SAVE ",
[ controller addAction : [ UIAlertAction actionWithTitle : NSLocalizedString ( @ "ALERT_DONT_SAVE ",
@ "The label for the ' don' t save ' button in action sheets . ")
@ "The label for the ' don' t save ' button in action sheets . ")
style : UIAlertActionStyleDestructive
style : UIAlertActionStyleDestructive
handler : ^( UIAlertAction * action ) {
handler : ^( UIAlertAction * action ) {
[ self . navigationController popViewControllerAnimated : YES ] ;
[ self dismissViewControllerAnimated : YES completion : nil ] ;
} ] ] ;
} ] ] ;
[ self presentViewController : controller animated : YES completion : nil ] ;
[ self presentViewController : controller animated : YES completion : nil ] ;
}
}
@ -499,6 +489,13 @@ NS_ASSUME_NONNULL_BEGIN
[ self updateTableContents ] ;
[ self updateTableContents ] ;
}
}
- ( BOOL ) isRecipientGroupMember : ( NSString * ) recipientId
{
OWSAssert ( recipientId . length > 0 ) ;
return [ self . memberRecipientIds containsObject : recipientId ] ;
}
@ end
@ end
NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END