2015-01-16 15:28:41 +01:00
//
2019-01-17 22:47:36 +01:00
// Copyright ( c ) 2019 Open Whisper Systems . All rights reserved .
2015-01-16 15:28:41 +01:00
//
# import "PrivacySettingsTableViewController.h"
2020-11-16 00:34:47 +01:00
2019-05-02 23:58:48 +02:00
# import "Session-Swift.h"
2020-11-12 00:41:45 +01:00
# import < SignalCoreKit / NSString + OWS . h >
2020-11-26 00:37:56 +01:00
# import < SessionMessagingKit / Environment . h >
# import < SessionMessagingKit / OWSPreferences . h >
2020-11-16 00:34:47 +01:00
2020-11-11 07:45:50 +01:00
# import < SignalUtilitiesKit / UIColor + OWS . h >
# import < SignalUtilitiesKit / SignalUtilitiesKit - Swift . h >
2020-11-26 00:37:56 +01:00
# import < SessionUtilitiesKit / NSString + SSK . h >
2020-11-16 00:34:47 +01:00
# import < SignalUtilitiesKit / ThreadUtil . h >
2020-11-25 06:15:16 +01:00
# import < SessionMessagingKit / OWSReadReceiptManager . h >
2020-11-11 07:45:50 +01:00
# import < SignalUtilitiesKit / SignalUtilitiesKit - Swift . h >
2015-01-16 15:28:41 +01:00
2016-11-08 19:08:04 +01:00
NS_ASSUME _NONNULL _BEGIN
2018-10-31 00:06:25 +01:00
static NSString * const kSealedSenderInfoURL = @ "https://signal.org/blog/sealed-sender/" ;
2015-01-16 15:28:41 +01:00
@ implementation PrivacySettingsTableViewController
2018-03-05 17:57:12 +01:00
- ( void ) viewDidLoad
{
2015-01-16 15:28:41 +01:00
[ super viewDidLoad ] ;
2015-12-22 12:45:09 +01:00
2018-03-21 18:25:39 +01:00
[ self observeNotifications ] ;
2017-07-14 16:55:49 +02:00
[ self updateTableContents ] ;
2019-10-03 03:30:45 +02:00
2020-08-27 07:20:25 +02:00
[ LKViewControllerUtilities setUpDefaultSessionStyleForVC : self withTitle : NSLocalizedString ( @ "vc_privacy_settings_title" , @ "" ) customBackButton : NO ] ;
2019-12-09 05:29:05 +01:00
self . tableView . backgroundColor = UIColor . clearColor ;
2015-01-16 15:28:41 +01:00
}
2017-07-14 16:55:49 +02:00
- ( void ) viewDidAppear : ( BOOL ) animated
{
2018-07-18 03:50:13 +02:00
[ super viewDidAppear : animated ] ;
2017-07-14 16:55:49 +02:00
[ self updateTableContents ] ;
2015-01-16 15:28:41 +01:00
}
2018-03-21 18:25:39 +01:00
- ( void ) observeNotifications
{
[ [ NSNotificationCenter defaultCenter ] addObserver : self
selector : @ selector ( screenLockDidChange : )
name : OWSScreenLock . ScreenLockDidChange
object : nil ] ;
}
- ( void ) dealloc
{
[ [ NSNotificationCenter defaultCenter ] removeObserver : self ] ;
}
2018-10-10 20:04:40 +02:00
# pragma mark - Dependencies
2018-10-11 01:17:01 +02:00
- ( OWSPreferences * ) preferences
{
return Environment . shared . preferences ;
}
2018-10-31 17:06:02 +01:00
- ( OWSReadReceiptManager * ) readReceiptManager
{
return OWSReadReceiptManager . sharedManager ;
}
- ( id < OWSTypingIndicators > ) typingIndicators
{
return SSKEnvironment . shared . typingIndicators ;
}
2017-07-14 16:55:49 +02:00
# pragma mark - Table Contents
2015-01-16 15:28:41 +01:00
2017-07-14 16:55:49 +02:00
- ( void ) updateTableContents
2016-11-08 19:08:04 +01:00
{
2017-07-14 16:55:49 +02:00
OWSTableContents * contents = [ OWSTableContents new ] ;
__weak PrivacySettingsTableViewController * weakSelf = self ;
2020-11-16 00:34:47 +01:00
2020-09-16 02:49:52 +02:00
OWSTableSection * readReceiptsSection = [ OWSTableSection new ] ;
readReceiptsSection . headerTitle
= NSLocalizedString ( @ "SETTINGS_READ_RECEIPT" , @ "Label for the 'read receipts' setting." ) ;
readReceiptsSection . footerTitle = NSLocalizedString (
@ "SETTINGS_READ_RECEIPTS_SECTION_FOOTER" , @ "An explanation of the 'read receipts' setting." ) ;
[ readReceiptsSection
addItem : [ OWSTableItem switchItemWithText : NSLocalizedString ( @ "SETTINGS_READ_RECEIPT" ,
@ "Label for the 'read receipts' setting." )
accessibilityIdentifier : [ NSString stringWithFormat : @ "settings.privacy.%@" , @ "read_receipts" ]
isOnBlock : ^ {
return [ OWSReadReceiptManager . sharedManager areReadReceiptsEnabled ] ;
}
isEnabledBlock : ^ {
return YES ;
}
target : weakSelf
selector : @ selector ( didToggleReadReceiptsSwitch : ) ] ] ;
[ contents addSection : readReceiptsSection ] ;
2017-09-14 22:25:36 +02:00
2018-10-31 17:06:02 +01:00
OWSTableSection * typingIndicatorsSection = [ OWSTableSection new ] ;
typingIndicatorsSection . headerTitle
= NSLocalizedString ( @ "SETTINGS_TYPING_INDICATORS" , @ "Label for the 'typing indicators' setting." ) ;
2020-01-23 05:01:31 +01:00
typingIndicatorsSection . footerTitle = NSLocalizedString ( @ "See and share when messages are being typed (applies to all sessions)." , @ "" ) ;
2019-02-25 18:58:15 +01:00
[ typingIndicatorsSection
addItem : [ OWSTableItem switchItemWithText : NSLocalizedString ( @ "SETTINGS_TYPING_INDICATORS" ,
@ "Label for the 'typing indicators' setting." )
2019-03-14 15:26:38 +01:00
accessibilityIdentifier : [ NSString stringWithFormat : @ "settings.privacy.%@" , @ "typing_indicators" ]
isOnBlock : ^ {
return [ SSKEnvironment . shared . typingIndicators areTypingIndicatorsEnabled ] ;
}
isEnabledBlock : ^ {
return YES ;
}
target : weakSelf
selector : @ selector ( didToggleTypingIndicatorsSwitch : ) ] ] ;
2018-10-31 17:06:02 +01:00
[ contents addSection : typingIndicatorsSection ] ;
2018-03-21 22:11:38 +01:00
OWSTableSection * screenLockSection = [ OWSTableSection new ] ;
screenLockSection . headerTitle = NSLocalizedString (
@ "SETTINGS_SCREEN_LOCK_SECTION_TITLE" , @ "Title for the 'screen lock' section of the privacy settings." ) ;
2020-01-23 05:01:31 +01:00
screenLockSection . footerTitle = NSLocalizedString ( @ "Require Touch ID, Face ID or your device passcode to unlock Session’ s screen. You can still receive notifications when Screen Lock is enabled. Use Session’ s notification settings to customise the information displayed in notifications." , @ "" ) ;
2018-03-21 22:11:38 +01:00
[ screenLockSection
addItem : [ OWSTableItem
switchItemWithText : NSLocalizedString ( @ "SETTINGS_SCREEN_LOCK_SWITCH_LABEL" ,
@ "Label for the 'enable screen lock' switch of the privacy settings." )
2019-03-14 15:26:38 +01:00
accessibilityIdentifier : [ NSString stringWithFormat : @ "settings.privacy.%@" , @ "screenlock" ]
isOnBlock : ^ {
return [ OWSScreenLock . sharedManager isScreenLockEnabled ] ;
}
isEnabledBlock : ^ {
return YES ;
}
target : self
selector : @ selector ( isScreenLockEnabledDidChange : ) ] ] ;
2018-03-21 22:11:38 +01:00
[ contents addSection : screenLockSection ] ;
if ( OWSScreenLock . sharedManager . isScreenLockEnabled ) {
OWSTableSection * screenLockTimeoutSection = [ OWSTableSection new ] ;
uint32_t screenLockTimeout = ( uint32_t ) round ( OWSScreenLock . sharedManager . screenLockTimeout ) ;
2018-03-22 21:21:41 +01:00
NSString * screenLockTimeoutString = [ self formatScreenLockTimeout : screenLockTimeout useShortFormat : YES ] ;
2018-03-21 22:11:38 +01:00
[ screenLockTimeoutSection
addItem : [ OWSTableItem
2019-03-14 15:26:38 +01:00
disclosureItemWithText :
NSLocalizedString ( @ "SETTINGS_SCREEN_LOCK_ACTIVITY_TIMEOUT" ,
@ "Label for the 'screen lock activity timeout' setting of the privacy settings." )
detailText : screenLockTimeoutString
accessibilityIdentifier : [ NSString
stringWithFormat : @ "settings.privacy.%@" , @ "screen_lock_timeout" ]
actionBlock : ^ {
[ weakSelf showScreenLockTimeoutUI ] ;
} ] ] ;
2018-03-21 22:11:38 +01:00
[ contents addSection : screenLockTimeoutSection ] ;
}
2017-09-27 22:57:02 +02:00
OWSTableSection * screenSecuritySection = [ OWSTableSection new ] ;
screenSecuritySection . headerTitle = NSLocalizedString ( @ "SETTINGS_SECURITY_TITLE" , @ "Section header" ) ;
2020-01-20 03:20:27 +01:00
screenSecuritySection . footerTitle = NSLocalizedString ( @ "Prevent Session previews from appearing in the app switcher." , nil ) ;
2019-02-25 18:58:15 +01:00
[ screenSecuritySection
2020-01-23 05:01:31 +01:00
addItem : [ OWSTableItem switchItemWithText : NSLocalizedString ( @ "Disable Preview in App Switcher" , @ "" )
2019-03-14 15:26:38 +01:00
accessibilityIdentifier : [ NSString stringWithFormat : @ "settings.privacy.%@" , @ "screen_security" ]
isOnBlock : ^ {
return [ Environment . shared . preferences screenSecurityIsEnabled ] ;
}
isEnabledBlock : ^ {
return YES ;
}
target : weakSelf
selector : @ selector ( didToggleScreenSecuritySwitch : ) ] ] ;
2017-09-27 22:57:02 +02:00
[ contents addSection : screenSecuritySection ] ;
2019-03-21 16:12:04 +01:00
2018-03-22 14:02:41 +01:00
OWSTableSection * historyLogsSection = [ OWSTableSection new ] ;
historyLogsSection . headerTitle = NSLocalizedString ( @ "SETTINGS_HISTORYLOG_TITLE" , @ "Section header" ) ;
2019-03-14 15:26:38 +01:00
[ historyLogsSection
addItem : [ OWSTableItem disclosureItemWithText : NSLocalizedString ( @ "SETTINGS_CLEAR_HISTORY" , @ "" )
accessibilityIdentifier : [ NSString stringWithFormat : @ "settings.privacy.%@" , @ "clear_logs" ]
actionBlock : ^ {
[ weakSelf clearHistoryLogs ] ;
} ] ] ;
2018-03-22 14:02:41 +01:00
[ contents addSection : historyLogsSection ] ;
2019-01-17 22:47:36 +01:00
OWSTableSection * linkPreviewsSection = [ OWSTableSection new ] ;
[ linkPreviewsSection
addItem : [ OWSTableItem switchItemWithText : NSLocalizedString ( @ "SETTINGS_LINK_PREVIEWS" ,
@ "Setting for enabling & disabling link previews." )
2019-03-14 15:26:38 +01:00
accessibilityIdentifier : [ NSString stringWithFormat : @ "settings.privacy.%@" , @ "link_previews" ]
isOnBlock : ^ {
return [ SSKPreferences areLinkPreviewsEnabled ] ;
}
isEnabledBlock : ^ {
return YES ;
}
target : weakSelf
selector : @ selector ( didToggleLinkPreviewsEnabled : ) ] ] ;
2019-01-23 22:32:57 +01:00
linkPreviewsSection . headerTitle = NSLocalizedString (
@ "SETTINGS_LINK_PREVIEWS_HEADER" , @ "Header for setting for enabling & disabling link previews." ) ;
linkPreviewsSection . footerTitle = NSLocalizedString (
@ "SETTINGS_LINK_PREVIEWS_FOOTER" , @ "Footer for setting for enabling & disabling link previews." ) ;
2019-01-17 22:47:36 +01:00
[ contents addSection : linkPreviewsSection ] ;
2018-02-28 16:55:33 +01:00
self . contents = contents ;
2015-01-16 15:28:41 +01:00
}
2017-07-14 16:55:49 +02:00
# pragma mark - Events
- ( void ) clearHistoryLogs
{
2019-03-21 15:26:38 +01:00
UIAlertController * alert =
2017-07-14 16:55:49 +02:00
[ UIAlertController alertControllerWithTitle : nil
2020-01-23 05:01:31 +01:00
message : NSLocalizedString ( @ "Are you sure? This cannot be undone." ,
2017-07-14 16:55:49 +02:00
@ "Alert message before user confirms clearing history" )
preferredStyle : UIAlertControllerStyleAlert ] ;
2019-03-21 15:26:38 +01:00
[ alert addAction : [ OWSAlerts cancelAction ] ] ;
2017-07-14 16:55:49 +02:00
2019-03-20 16:16:15 +01:00
UIAlertAction * deleteAction =
[ UIAlertAction actionWithTitle :
NSLocalizedString ( @ "SETTINGS_DELETE_HISTORYLOG_CONFIRMATION_BUTTON" ,
@ "Confirmation text for button which deletes all message, calling, attachments, etc." )
2019-03-22 18:05:35 +01:00
accessibilityIdentifier : ACCESSIBILITY_IDENTIFIER _WITH _NAME ( self , @ "delete" )
2019-03-20 16:16:15 +01:00
style : UIAlertActionStyleDestructive
handler : ^ ( UIAlertAction * _Nonnull action ) {
[ self deleteThreadsAndMessages ] ;
} ] ;
2019-03-21 15:26:38 +01:00
[ alert addAction : deleteAction ] ;
2017-07-14 16:55:49 +02:00
2019-03-21 15:55:04 +01:00
[ self presentAlert : alert ] ;
2015-01-16 15:28:41 +01:00
}
2017-12-19 03:07:54 +01:00
- ( void ) deleteThreadsAndMessages
{
2018-03-20 18:02:10 +01:00
[ ThreadUtil deleteAllContent ] ;
2017-12-19 03:07:54 +01:00
}
2016-09-11 22:53:12 +02:00
- ( void ) didToggleScreenSecuritySwitch : ( UISwitch * ) sender
{
2017-07-14 16:55:49 +02:00
BOOL enabled = sender . isOn ;
2018-08-27 18:51:32 +02:00
OWSLogInfo ( @ "toggled screen security: %@" , enabled ? @ "ON" : @ "OFF" ) ;
2018-10-11 01:17:01 +02:00
[ self . preferences setScreenSecurity : enabled ] ;
2015-01-16 15:28:41 +01:00
}
2015-12-22 12:45:09 +01:00
2017-09-14 22:25:36 +02:00
- ( void ) didToggleReadReceiptsSwitch : ( UISwitch * ) sender
{
BOOL enabled = sender . isOn ;
2018-08-27 18:51:32 +02:00
OWSLogInfo ( @ "toggled areReadReceiptsEnabled: %@" , enabled ? @ "ON" : @ "OFF" ) ;
2018-10-31 17:06:02 +01:00
[ self . readReceiptManager setAreReadReceiptsEnabled : enabled ] ;
}
- ( void ) didToggleTypingIndicatorsSwitch : ( UISwitch * ) sender
{
BOOL enabled = sender . isOn ;
OWSLogInfo ( @ "toggled areTypingIndicatorsEnabled: %@" , enabled ? @ "ON" : @ "OFF" ) ;
[ self . typingIndicators setTypingIndicatorsEnabledWithValue : enabled ] ;
2017-09-14 22:25:36 +02:00
}
2019-01-17 22:47:36 +01:00
- ( void ) didToggleLinkPreviewsEnabled : ( UISwitch * ) sender
{
2020-02-01 04:21:32 +01:00
BOOL isOn = sender . isOn ;
if ( isOn ) {
2020-07-27 03:32:47 +02:00
NSString * title = @ "Enable Link Previews?" ;
NSString * message = @ "You will not have full metadata protection when sending or receiving link previews." ;
2020-02-01 04:21:32 +01:00
UIAlertController * alert = [ UIAlertController alertControllerWithTitle : title message : message preferredStyle : UIAlertControllerStyleAlert ] ;
[ alert addAction : [ UIAlertAction actionWithTitle : NSLocalizedString ( @ "OK" , @ "" ) style : UIAlertActionStyleDefault handler : nil ] ] ;
2020-07-27 03:32:47 +02:00
[ alert addAction : [ UIAlertAction actionWithTitle : NSLocalizedString ( @ "cancel" , @ "" ) style : UIAlertActionStyleDefault handler : ^ ( UIAlertAction * action ) {
2020-02-01 04:21:32 +01:00
[ sender setOn : NO animated : YES ] ;
SSKPreferences . areLinkPreviewsEnabled = NO ;
} ] ] ;
[ self presentViewController : alert animated : YES completion : nil ] ;
}
2019-01-17 22:47:36 +01:00
OWSLogInfo ( @ "toggled to: %@" , ( sender . isOn ? @ "ON" : @ "OFF" ) ) ;
2019-02-21 15:53:49 +01:00
SSKPreferences . areLinkPreviewsEnabled = sender . isOn ;
2019-01-17 22:47:36 +01:00
}
2018-03-21 18:25:39 +01:00
- ( void ) isScreenLockEnabledDidChange : ( UISwitch * ) sender
{
BOOL shouldBeEnabled = sender . isOn ;
if ( shouldBeEnabled = = OWSScreenLock . sharedManager . isScreenLockEnabled ) {
2018-08-27 18:51:32 +02:00
OWSLogError ( @ "ignoring redundant screen lock." ) ;
2018-03-21 18:25:39 +01:00
return ;
}
2018-08-27 18:55:37 +02:00
OWSLogInfo ( @ "trying to set is screen lock enabled: %@" , @ ( shouldBeEnabled ) ) ;
2019-10-03 03:30:45 +02:00
2018-04-12 18:23:11 +02:00
[ OWSScreenLock . sharedManager setIsScreenLockEnabled : shouldBeEnabled ] ;
2018-03-21 18:25:39 +01:00
}
- ( void ) screenLockDidChange : ( NSNotification * ) notification
{
2018-08-27 18:09:39 +02:00
OWSLogInfo ( @ "" ) ;
2018-03-21 18:25:39 +01:00
[ self updateTableContents ] ;
}
2018-03-21 22:11:38 +01:00
- ( void ) showScreenLockTimeoutUI
{
2018-08-27 18:09:39 +02:00
OWSLogInfo ( @ "" ) ;
2018-03-21 22:11:38 +01:00
2019-03-21 15:26:38 +01:00
UIAlertController * alert = [ UIAlertController
2018-03-21 22:11:38 +01:00
alertControllerWithTitle : NSLocalizedString ( @ "SETTINGS_SCREEN_LOCK_ACTIVITY_TIMEOUT" ,
@ "Label for the 'screen lock activity timeout' setting of the privacy settings." )
message : nil
preferredStyle : UIAlertControllerStyleActionSheet ] ;
for ( NSNumber * timeoutValue in OWSScreenLock . sharedManager . screenLockTimeouts ) {
uint32_t screenLockTimeout = ( uint32_t ) round ( timeoutValue . doubleValue ) ;
2018-03-22 21:21:41 +01:00
NSString * screenLockTimeoutString = [ self formatScreenLockTimeout : screenLockTimeout useShortFormat : NO ] ;
2018-03-21 22:11:38 +01:00
2019-03-20 15:56:45 +01:00
UIAlertAction * action =
[ UIAlertAction actionWithTitle : screenLockTimeoutString
2019-03-22 16:55:00 +01:00
accessibilityIdentifier : [ NSString stringWithFormat : @ "settings.privacy.timeout.%@" , timeoutValue ]
2019-03-20 15:56:45 +01:00
style : UIAlertActionStyleDefault
handler : ^ ( UIAlertAction * ignore ) {
[ OWSScreenLock . sharedManager setScreenLockTimeout : screenLockTimeout ] ;
} ] ;
2019-03-21 15:26:38 +01:00
[ alert addAction : action ] ;
2018-03-21 22:11:38 +01:00
}
2019-03-21 15:26:38 +01:00
[ alert addAction : [ OWSAlerts cancelAction ] ] ;
2018-03-21 22:11:38 +01:00
UIViewController * fromViewController = [ [ UIApplication sharedApplication ] frontmostViewController ] ;
2019-03-21 15:55:04 +01:00
[ fromViewController presentAlert : alert ] ;
2018-03-21 22:11:38 +01:00
}
2018-03-22 21:21:41 +01:00
- ( NSString * ) formatScreenLockTimeout : ( NSInteger ) value useShortFormat : ( BOOL ) useShortFormat
2018-03-22 14:02:41 +01:00
{
if ( value <= 1 ) {
return NSLocalizedString ( @ "SCREEN_LOCK_ACTIVITY_TIMEOUT_NONE" ,
@ "Indicates a delay of zero seconds, and that 'screen lock activity' will timeout immediately." ) ;
}
2018-03-22 21:21:41 +01:00
return [ NSString formatDurationSeconds : ( uint32_t ) value useShortFormat : useShortFormat ] ;
2018-03-22 14:02:41 +01:00
}
2015-01-16 15:28:41 +01:00
@ end
2016-11-08 19:08:04 +01:00
NS_ASSUME _NONNULL _END