@ -4,6 +4,7 @@
#import "OWSConversationSettingsTableViewController . h "
#import "BlockListUIUtils . h "
#import "ContactsViewHelper . h "
#import "Environment . h "
#import "FingerprintViewController . h "
#import "OWSAvatarBuilder . h "
@ -29,9 +30,11 @@
#import < SignalServiceKit / TSStorageManager . h >
#import < SignalServiceKit / TSThread . h >
@ import ContactsUI ;
NS_ASSUME_NONNULL_BEGIN
@ interface OWSConversationSettingsTableViewController ( )
@ interface OWSConversationSettingsTableViewController ( ) < ContactEditingDelegate , ContactsViewHelperDelegate >
@ property ( nonatomic ) TSThread * thread ;
@ -42,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN
@ property ( nonatomic , readonly ) OWSContactsManager * contactsManager ;
@ property ( nonatomic , readonly ) OWSMessageSender * messageSender ;
@ property ( nonatomic , readonly ) OWSBlockingManager * blockingManager ;
@ property ( nonatomic , readonly ) ContactsViewHelper * contactsViewHelper ;
@ property ( nonatomic , readonly ) UIImageView * avatarView ;
@ property ( nonatomic , readonly ) UILabel * disappearingMessagesDurationLabel ;
@ -93,6 +96,8 @@ NS_ASSUME_NONNULL_BEGIN
_contactsManager = [ Environment getCurrent ] . contactsManager ;
_messageSender = [ Environment getCurrent ] . messageSender ;
_blockingManager = [ OWSBlockingManager sharedManager ] ;
_contactsViewHelper = [ ContactsViewHelper new ] ;
_contactsViewHelper . delegate = self ;
}
- ( NSString * ) threadName
@ -115,6 +120,52 @@ NS_ASSUME_NONNULL_BEGIN
- ( void ) configureWithThread : ( TSThread * ) thread
{
self . thread = thread ;
[ self updateEditButton ] ;
}
- ( void ) updateEditButton
{
OWSAssert ( self . thread ) ;
if ( [ self . thread isKindOfClass : [ TSContactThread class ] ] ) {
self . navigationItem . rightBarButtonItem =
[ [ UIBarButtonItem alloc ] initWithTitle : NSLocalizedString ( @ "EDIT_TXT ", nil )
style : UIBarButtonItemStylePlain
target : self
action : @ selector ( didTapEditButton ) ] ;
}
}
#pragma mark - ContactEditingDelegate
- ( void ) didFinishEditingContact
{
DDLogDebug ( @ "%@ %s", self.tag, __PRETTY_FUNCTION__);
[ self dismissViewControllerAnimated : NO completion : nil ] ;
}
#pragma mark - CNContactViewControllerDelegate
- ( void ) contactViewController : ( CNContactViewController * ) viewController
didCompleteWithContact : ( nullable CNContact * ) contact
{
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 .
DDLogDebug ( @ "%@ completed editing contact.", self.tag);
[ self dismissViewControllerAnimated : NO completion : nil ] ;
} else {
DDLogDebug ( @ "%@ canceled editing contact.", self.tag);
[ self dismissViewControllerAnimated : YES completion : nil ] ;
}
}
#pragma mark - ContactsViewHelperDelegate
- ( void ) contactsViewHelperDidUpdateContacts
{
[ self updateTableContents ] ;
}
#pragma mark - View Lifecycle
@ -508,6 +559,7 @@ NS_ASSUME_NONNULL_BEGIN
[ threadNameView addSubview : threadTitleLabel ] ;
[ threadTitleLabel autoPinEdgeToSuperviewEdge : ALEdgeTop ] ;
[ threadTitleLabel autoPinEdgeToSuperviewEdge : ALEdgeLeft ] ;
[ threadTitleLabel autoPinEdgeToSuperviewEdge : ALEdgeRight ] ;
if ( ![ self isGroupThread ] && ![ self . thread . name isEqualToString : self . thread . contactIdentifier ] ) {
NSString * subtitle =
@ -546,7 +598,7 @@ NS_ASSUME_NONNULL_BEGIN
[ self showUpdateGroupView : UpdateGroupMode_EditGroupName ] ;
}
} else {
/ / TODO : Edit 1 : 1 contact .
[ self presentContactViewController ] ;
}
}
}
@ -568,6 +620,9 @@ NS_ASSUME_NONNULL_BEGIN
{
[ super viewWillAppear : animated ] ;
/ / In case we ' re dismissing a CNContactViewController which requires default system appearance
[ UIUtil applySignalAppearence ] ;
/ / HACK to unselect rows when swiping back
/ / http : / / stackoverflow . com / questions / 19379510 / uitableviewcell - doesnt - get - deselected - when - swiping - back - quickly
[ self . tableView deselectRowAtIndexPath : [ self . tableView indexPathForSelectedRow ] animated : animated ] ;
@ -614,6 +669,25 @@ NS_ASSUME_NONNULL_BEGIN
[ self presentViewController : navigationController animated : YES completion : nil ] ;
}
- ( void ) presentContactViewController
{
if ( ![ self . thread isKindOfClass : [ TSContactThread class ] ] ) {
DDLogError ( @ "%@ unexpected thread: %@ in %s", self.tag, self.thread, __PRETTY_FUNCTION__);
OWSAssert ( NO ) ;
return ;
}
TSContactThread * contactThread = ( TSContactThread * ) self . thread ;
[ self . contactsViewHelper presentContactViewControllerForRecipientId : contactThread . contactIdentifier
fromViewController : self
editImmediately : YES ] ;
}
- ( void ) didTapEditButton
{
[ self presentContactViewController ] ;
}
- ( void ) didTapLeaveGroup
{
UIAlertController * alertController =