@ -227,45 +227,53 @@
} ] ] ;
} ] ] ;
#endif
#endif
[ section addItem : [ OWSTableItem itemWithCustomCellBlock : ^{
if ( TSAccountManager . sharedInstance . isDeregistered ) {
UITableViewCell * cell = [ UITableViewCell new ] ;
[ section addItem : [ self destructiveButtonItemWithTitle : NSLocalizedString ( @ "SETTINGS_REREGISTER_BUTTON ",
cell . preservesSuperviewLayoutMargins = YES ;
@ "Label for re - registration button . ")
cell . contentView . preservesSuperviewLayoutMargins = YES ;
selector : @ selector ( reregisterUser )
cell . selectionStyle = UITableViewCellSelectionStyleNone ;
color : [ UIColor ows_materialBlueColor ] ] ] ;
[ section addItem : [ self destructiveButtonItemWithTitle : NSLocalizedString ( @ "SETTINGS_DELETE_DATA_BUTTON ",
const CGFloat kButtonHeight = 40. f ;
@ "Label for ' delete data' button . ")
OWSFlatButton * button ;
selector : @ selector ( deleteUnregisterUserData )
if ( TSAccountManager . sharedInstance . isDeregistered ) {
color : [ UIColor ows_destructiveRedColor ] ] ] ;
button = [ OWSFlatButton
} else {
buttonWithTitle : NSLocalizedString ( @ "SETTINGS_REREGISTER_BUTTON ", @ "Label for re - registration button . ")
[ section addItem : [ self destructiveButtonItemWithTitle : NSLocalizedString ( @ "SETTINGS_DELETE_ACCOUNT_BUTTON ", @ "")
font : [ OWSFlatButton fontForHeight : kButtonHeight ]
selector : @ selector ( unregisterUser )
titleColor : [ UIColor whiteColor ]
color : [ UIColor ows_destructiveRedColor ] ] ] ;
backgroundColor : [ UIColor ows_destructiveRedColor ]
target : self
selector : @ selector ( reregisterUser ) ] ;
} else {
button = [ OWSFlatButton buttonWithTitle : NSLocalizedString ( @ "SETTINGS_DELETE_ACCOUNT_BUTTON ", @ "")
font : [ OWSFlatButton fontForHeight : kButtonHeight ]
titleColor : [ UIColor whiteColor ]
backgroundColor : [ UIColor ows_destructiveRedColor ]
target : self
selector : @ selector ( unregisterUser ) ] ;
}
[ cell . contentView addSubview : button ] ;
[ button autoSetDimension : ALDimensionHeight toSize : kButtonHeight ] ;
[ button autoVCenterInSuperview ] ;
[ button autoPinLeadingAndTrailingToSuperviewMargin ] ;
return cell ;
}
}
customRowHeight : 90. f
actionBlock : nil ] ] ;
[ contents addSection : section ] ;
[ contents addSection : section ] ;
self . contents = contents ;
self . contents = contents ;
}
}
- ( OWSTableItem * ) destructiveButtonItemWithTitle : ( NSString * ) title selector : ( SEL ) selector color : ( UIColor * ) color
{
return [ OWSTableItem
itemWithCustomCellBlock : ^{
UITableViewCell * cell = [ UITableViewCell new ] ;
cell . preservesSuperviewLayoutMargins = YES ;
cell . contentView . preservesSuperviewLayoutMargins = YES ;
cell . selectionStyle = UITableViewCellSelectionStyleNone ;
const CGFloat kButtonHeight = 40. f ;
OWSFlatButton * button = [ OWSFlatButton buttonWithTitle : title
font : [ OWSFlatButton fontForHeight : kButtonHeight ]
titleColor : [ UIColor whiteColor ]
backgroundColor : color
target : self
selector : selector ] ;
[ cell . contentView addSubview : button ] ;
[ button autoSetDimension : ALDimensionHeight toSize : kButtonHeight ] ;
[ button autoVCenterInSuperview ] ;
[ button autoPinLeadingAndTrailingToSuperviewMargin ] ;
return cell ;
}
customRowHeight : 90. f
actionBlock : nil ] ;
}
- ( UITableViewCell * ) profileHeaderCell
- ( UITableViewCell * ) profileHeaderCell
{
{
UITableViewCell * cell = [ UITableViewCell new ] ;
UITableViewCell * cell = [ UITableViewCell new ] ;
@ -411,6 +419,16 @@
#pragma mark - Unregister & Re - register
#pragma mark - Unregister & Re - register
- ( void ) unregisterUser
- ( void ) unregisterUser
{
[ self showDeleteAccountUI : YES ] ;
}
- ( void ) deleteUnregisterUserData
{
[ self showDeleteAccountUI : NO ] ;
}
- ( void ) showDeleteAccountUI : ( BOOL ) isRegistered
{
{
UIAlertController * alertController =
UIAlertController * alertController =
[ UIAlertController alertControllerWithTitle : NSLocalizedString ( @ "CONFIRM_ACCOUNT_DESTRUCTION_TITLE ", @ "")
[ UIAlertController alertControllerWithTitle : NSLocalizedString ( @ "CONFIRM_ACCOUNT_DESTRUCTION_TITLE ", @ "")
@ -419,30 +437,36 @@
[ alertController addAction : [ UIAlertAction actionWithTitle : NSLocalizedString ( @ "PROCEED_BUTTON ", @ "")
[ alertController addAction : [ UIAlertAction actionWithTitle : NSLocalizedString ( @ "PROCEED_BUTTON ", @ "")
style : UIAlertActionStyleDestructive
style : UIAlertActionStyleDestructive
handler : ^( UIAlertAction * action ) {
handler : ^( UIAlertAction * action ) {
[ self proceedToUnregistration ] ;
[ self deleteAccount: isRegistered ] ;
} ] ] ;
} ] ] ;
[ alertController addAction : [ OWSAlerts cancelAction ] ] ;
[ alertController addAction : [ OWSAlerts cancelAction ] ] ;
[ self presentViewController : alertController animated : YES completion : nil ] ;
[ self presentViewController : alertController animated : YES completion : nil ] ;
}
}
- ( void ) proceedToUnregistration
- ( void ) deleteAccount: ( BOOL ) isRegistered
{
{
[ ModalActivityIndicatorViewController
if ( isRegistered ) {
presentFromViewController : self
[ ModalActivityIndicatorViewController
canCancel : NO
presentFromViewController : self
backgroundBlock : ^( ModalActivityIndicatorViewController * modalActivityIndicator ) {
canCancel : NO
[ TSAccountManager unregisterTextSecureWithSuccess : ^{
backgroundBlock : ^( ModalActivityIndicatorViewController * modalActivityIndicator ) {
[ SignalApp resetAppData ] ;
[ TSAccountManager
}
unregisterTextSecureWithSuccess : ^{
failure : ^( NSError * error ) {
[ SignalApp resetAppData ] ;
dispatch_async ( dispatch_get_main_queue ( ) , ^{
}
[ modalActivityIndicator dismissWithCompletion : ^{
failure : ^( NSError * error ) {
[ OWSAlerts showAlertWithTitle : NSLocalizedString ( @ "UNREGISTER_SIGNAL_FAIL ", @ "") ] ;
dispatch_async ( dispatch_get_main_queue ( ) , ^{
} ] ;
[ modalActivityIndicator dismissWithCompletion : ^{
} ) ;
[ OWSAlerts
} ] ;
showAlertWithTitle : NSLocalizedString ( @ "UNREGISTER_SIGNAL_FAIL ", @ "") ] ;
} ] ;
} ] ;
} ) ;
} ] ;
} ] ;
} else {
[ SignalApp resetAppData ] ;
}
}
}
- ( void ) reregisterUser
- ( void ) reregisterUser