mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Now store showDecryptedContentInNotifications
settings option in UserDefaults instead for MXKAccount in order to keep this information when the user logout. Fix issue #1914.
This commit is contained in:
parent
43017dfb30
commit
8221ebfc67
2 changed files with 54 additions and 36 deletions
|
@ -54,6 +54,8 @@
|
|||
#import "MXSession+Riot.h"
|
||||
#import "MXRoom+Riot.h"
|
||||
|
||||
#import "Riot-Swift.h"
|
||||
|
||||
//#define MX_CALL_STACK_OPENWEBRTC
|
||||
#ifdef MX_CALL_STACK_OPENWEBRTC
|
||||
#import <MatrixOpenWebRTCWrapper/MatrixOpenWebRTCWrapper.h>
|
||||
|
@ -455,12 +457,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
|
|||
|
||||
_isAppForeground = NO;
|
||||
|
||||
// Retrieve custom configuration
|
||||
NSString* userDefaults = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UserDefaults"];
|
||||
NSString *defaultsPathFromApp = [[NSBundle mainBundle] pathForResource:userDefaults ofType:@"plist"];
|
||||
NSDictionary *defaults = [NSDictionary dictionaryWithContentsOfFile:defaultsPathFromApp];
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
[self setupUserDefaults];
|
||||
|
||||
// Configure our analytics. It will indeed start if the option is enabled
|
||||
[MXSDKOptions sharedInstance].analyticsDelegate = [Analytics sharedInstance];
|
||||
|
@ -591,7 +588,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
|
|||
NSLog(@"[AppDelegate] applicationDidBecomeActive");
|
||||
|
||||
// Check if there is crash log to send
|
||||
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"enableCrashReport"])
|
||||
if (RiotSettings.shared.enableCrashReport)
|
||||
{
|
||||
[self checkExceptionToReport];
|
||||
}
|
||||
|
@ -1405,7 +1402,8 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
|
|||
@"user_id": account.mxCredentials.userId
|
||||
};
|
||||
|
||||
BOOL isNotificationContentShown = !event.isEncrypted || account.showDecryptedContentInNotifications;
|
||||
BOOL isNotificationContentShown = !event.isEncrypted || RiotSettings.shared.showDecryptedContentInNotifications;
|
||||
|
||||
if ((event.eventType == MXEventTypeRoomMessage || event.eventType == MXEventTypeRoomEncrypted) && isNotificationContentShown)
|
||||
{
|
||||
eventNotification.category = @"QUICK_REPLY";
|
||||
|
@ -1493,7 +1491,7 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
|
|||
NSString *msgType = event.content[@"msgtype"];
|
||||
NSString *content = event.content[@"body"];
|
||||
|
||||
if (event.isEncrypted && !account.showDecryptedContentInNotifications)
|
||||
if (event.isEncrypted && !RiotSettings.shared.showDecryptedContentInNotifications)
|
||||
{
|
||||
// Hide the content
|
||||
msgType = nil;
|
||||
|
@ -4023,4 +4021,26 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN
|
|||
[self.gdprConsentViewController dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
#pragma mark - Settings
|
||||
|
||||
- (void)setupUserDefaults
|
||||
{
|
||||
// Retrieve custom configuration
|
||||
NSString* userDefaults = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UserDefaults"];
|
||||
NSString *defaultsPathFromApp = [[NSBundle mainBundle] pathForResource:userDefaults ofType:@"plist"];
|
||||
NSDictionary *defaults = [NSDictionary dictionaryWithContentsOfFile:defaultsPathFromApp];
|
||||
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
|
||||
// Now use RiotSettings and NSUserDefaults to store `showDecryptedContentInNotifications` setting option
|
||||
// Migrate this information from main MXKAccount to RiotSettings, only if value was set to YES as default value is NO
|
||||
|
||||
MXKAccount *currentAccount = [MXKAccountManager sharedManager].activeAccounts.firstObject;
|
||||
|
||||
if (currentAccount.showDecryptedContentInNotifications)
|
||||
{
|
||||
RiotSettings.shared.showDecryptedContentInNotifications = currentAccount.showDecryptedContentInNotifications;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
|
||||
#import "GBDeviceInfo_iOS.h"
|
||||
|
||||
#import "Riot-Swift.h"
|
||||
|
||||
NSString* const kSettingsViewControllerPhoneBookCountryCellId = @"kSettingsViewControllerPhoneBookCountryCellId";
|
||||
|
||||
enum
|
||||
|
@ -1681,7 +1683,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
||||
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_show_decrypted_content", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = account.showDecryptedContentInNotifications;
|
||||
labelAndSwitchCell.mxkSwitch.on = RiotSettings.shared.showDecryptedContentInNotifications;
|
||||
labelAndSwitchCell.mxkSwitch.enabled = account.isPushKitNotificationActive;
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleShowDecodedContent:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
|
@ -1705,7 +1707,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
||||
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_pin_rooms_with_missed_notif", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"pinRoomsWithMissedNotif"];
|
||||
labelAndSwitchCell.mxkSwitch.on = RiotSettings.shared.pinRoomsWithMissedNotificationsOnHome;
|
||||
labelAndSwitchCell.mxkSwitch.enabled = YES;
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(togglePinRoomsWithMissedNotif:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
|
@ -1716,7 +1718,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
||||
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_pin_rooms_with_unread", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"pinRoomsWithUnread"];
|
||||
labelAndSwitchCell.mxkSwitch.on = RiotSettings.shared.pinRoomsWithUnreadMessagesOnHome;
|
||||
labelAndSwitchCell.mxkSwitch.enabled = YES;
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(togglePinRoomsWithUnread:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
|
@ -1782,7 +1784,8 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kSettingsViewControllerPhoneBookCountryCellId];
|
||||
}
|
||||
|
||||
NSString *theme = [[NSUserDefaults standardUserDefaults] stringForKey:@"userInterfaceTheme"];
|
||||
NSString *theme = RiotSettings.shared.userInterfaceTheme;
|
||||
|
||||
if (!theme)
|
||||
{
|
||||
if (@available(iOS 11.0, *))
|
||||
|
@ -1942,7 +1945,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
MXKTableViewCellWithLabelAndSwitch* sendCrashReportCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
||||
|
||||
sendCrashReportCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_send_crash_report", @"Vector", nil);
|
||||
sendCrashReportCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"enableCrashReport"];
|
||||
sendCrashReportCell.mxkSwitch.on = RiotSettings.shared.enableCrashReport;
|
||||
sendCrashReportCell.mxkSwitch.enabled = YES;
|
||||
[sendCrashReportCell.mxkSwitch addTarget:self action:@selector(toggleSendCrashReport:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
|
@ -1953,7 +1956,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
MXKTableViewCellWithLabelAndSwitch* enableRageShakeCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
||||
|
||||
enableRageShakeCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_enable_rageshake", @"Vector", nil);
|
||||
enableRageShakeCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"enableRageShake"];
|
||||
enableRageShakeCell.mxkSwitch.on = RiotSettings.shared.enableRageShake;
|
||||
enableRageShakeCell.mxkSwitch.enabled = YES;
|
||||
[enableRageShakeCell.mxkSwitch addTarget:self action:@selector(toggleEnableRageShake:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
|
@ -2042,7 +2045,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
||||
|
||||
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_labs_create_conference_with_jitsi", @"Vector", nil);
|
||||
labelAndSwitchCell.mxkSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"createConferenceCallsWithJitsi"];
|
||||
labelAndSwitchCell.mxkSwitch.on = RiotSettings.shared.createConferenceCallsWithJitsi;
|
||||
|
||||
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleJitsiForConference:) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
|
@ -2820,8 +2823,8 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
|
||||
- (void)toggleShowDecodedContent:(id)sender
|
||||
{
|
||||
MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject;
|
||||
account.showDecryptedContentInNotifications = !account.showDecryptedContentInNotifications;
|
||||
UISwitch *switchButton = (UISwitch*)sender;
|
||||
RiotSettings.shared.showDecryptedContentInNotifications = switchButton.isOn;
|
||||
}
|
||||
|
||||
- (void)toggleLocalContactsSync:(id)sender
|
||||
|
@ -2847,12 +2850,12 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
|
||||
- (void)toggleSendCrashReport:(id)sender
|
||||
{
|
||||
BOOL enable = [[NSUserDefaults standardUserDefaults] boolForKey:@"enableCrashReport"];
|
||||
BOOL enable = RiotSettings.shared.enableCrashReport;
|
||||
if (enable)
|
||||
{
|
||||
NSLog(@"[SettingsViewController] disable automatic crash report and analytics sending");
|
||||
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"enableCrashReport"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
|
||||
RiotSettings.shared.enableCrashReport = NO;
|
||||
|
||||
[[Analytics sharedInstance] stop];
|
||||
|
||||
|
@ -2862,8 +2865,8 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
else
|
||||
{
|
||||
NSLog(@"[SettingsViewController] enable automatic crash report and analytics sending");
|
||||
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"enableCrashReport"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
|
||||
RiotSettings.shared.enableCrashReport = YES;
|
||||
|
||||
[[Analytics sharedInstance] start];
|
||||
}
|
||||
|
@ -2875,8 +2878,7 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
{
|
||||
UISwitch *switchButton = (UISwitch*)sender;
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] setBool:switchButton.isOn forKey:@"enableRageShake"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
RiotSettings.shared.enableRageShake = switchButton.isOn;
|
||||
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
@ -2887,9 +2889,8 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
if (sender && [sender isKindOfClass:UISwitch.class])
|
||||
{
|
||||
UISwitch *switchButton = (UISwitch*)sender;
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] setBool:switchButton.isOn forKey:@"createConferenceCallsWithJitsi"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
|
||||
RiotSettings.shared.createConferenceCallsWithJitsi = switchButton.isOn;
|
||||
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
@ -3012,16 +3013,14 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
{
|
||||
UISwitch *switchButton = (UISwitch*)sender;
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] setBool:switchButton.on forKey:@"pinRoomsWithMissedNotif"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
RiotSettings.shared.pinRoomsWithMissedNotificationsOnHome = switchButton.on;
|
||||
}
|
||||
|
||||
- (void)togglePinRoomsWithUnread:(id)sender
|
||||
{
|
||||
UISwitch *switchButton = (UISwitch*)sender;
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] setBool:switchButton.on forKey:@"pinRoomsWithUnread"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
|
||||
RiotSettings.shared.pinRoomsWithUnreadMessagesOnHome = switchButton.on;
|
||||
}
|
||||
|
||||
- (void)toggleCommunityFlair:(id)sender
|
||||
|
@ -3661,15 +3660,14 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
|
|||
newTheme = @"black";
|
||||
}
|
||||
|
||||
NSString *theme = [[NSUserDefaults standardUserDefaults] stringForKey:@"userInterfaceTheme"];
|
||||
NSString *theme = RiotSettings.shared.userInterfaceTheme;
|
||||
if (newTheme && ![newTheme isEqualToString:theme])
|
||||
{
|
||||
// Clear fake Riot Avatars based on the previous theme.
|
||||
[AvatarGenerator clear];
|
||||
|
||||
// The user wants to select this theme
|
||||
[[NSUserDefaults standardUserDefaults] setObject:newTheme forKey:@"userInterfaceTheme"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
RiotSettings.shared.userInterfaceTheme = newTheme;
|
||||
|
||||
[self.tableView reloadData];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue