mirror of https://github.com/oxen-io/session-ios
Removed an initial request occurring when pushing the conversation screen (could hold up main thread)
Removed the old OWSPreferences file (everything left over seems to be unused)pull/612/head
parent
af073657a2
commit
4dced25e85
@ -1,67 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <SessionMessagingKit/YapDatabaseConnection+OWS.h>
|
||||
#import <SessionMessagingKit/YapDatabaseTransaction+OWS.h>
|
||||
#import <SessionUtilitiesKit/SessionUtilitiesKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// Used when migrating logging to NSUserDefaults.
|
||||
extern NSString *const OWSPreferencesSignalDatabaseCollection;
|
||||
extern NSString *const OWSPreferencesCallLoggingDidChangeNotification;
|
||||
|
||||
@class YapDatabaseReadWriteTransaction;
|
||||
|
||||
@interface OWSPreferences : NSObject
|
||||
|
||||
#pragma mark - Helpers
|
||||
|
||||
- (nullable id)tryGetValueForKey:(NSString *)key;
|
||||
- (void)setValueForKey:(NSString *)key toValue:(nullable id)value;
|
||||
- (void)clear;
|
||||
|
||||
#pragma mark - Specific Preferences
|
||||
|
||||
- (BOOL)hasSentAMessage;
|
||||
- (void)setHasSentAMessage:(BOOL)enabled;
|
||||
|
||||
- (BOOL)hasDeclinedNoContactsView;
|
||||
- (void)setHasDeclinedNoContactsView:(BOOL)value;
|
||||
|
||||
- (void)setIOSUpgradeNagDate:(NSDate *)value;
|
||||
- (nullable NSDate *)iOSUpgradeNagDate;
|
||||
|
||||
- (BOOL)shouldShowUnidentifiedDeliveryIndicators;
|
||||
- (void)setShouldShowUnidentifiedDeliveryIndicators:(BOOL)value;
|
||||
|
||||
#pragma mark Callkit
|
||||
|
||||
- (BOOL)isSystemCallLogEnabled;
|
||||
- (void)setIsSystemCallLogEnabled:(BOOL)flag;
|
||||
|
||||
#pragma mark - Legacy CallKit settings
|
||||
|
||||
- (void)applyCallLoggingSettingsForLegacyUsersWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
|
||||
|
||||
- (BOOL)isCallKitEnabled;
|
||||
- (void)setIsCallKitEnabled:(BOOL)flag;
|
||||
|
||||
// Returns YES IFF isCallKitEnabled has been set by user.
|
||||
- (BOOL)isCallKitEnabledSet;
|
||||
|
||||
- (BOOL)isCallKitPrivacyEnabled;
|
||||
- (void)setIsCallKitPrivacyEnabled:(BOOL)flag;
|
||||
// Returns YES IFF isCallKitPrivacyEnabled has been set by user.
|
||||
- (BOOL)isCallKitPrivacySet;
|
||||
|
||||
#pragma mark direct call connectivity (non-TURN)
|
||||
|
||||
- (BOOL)doCallsHideIPAddress;
|
||||
- (void)setDoCallsHideIPAddress:(BOOL)flag;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -1,256 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSPreferences.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
NSString *const OWSPreferencesSignalDatabaseCollection = @"SignalPreferences";
|
||||
NSString *const OWSPreferencesCallLoggingDidChangeNotification = @"OWSPreferencesCallLoggingDidChangeNotification";
|
||||
NSString *const OWSPreferencesKeyCallKitEnabled = @"CallKitEnabled";
|
||||
NSString *const OWSPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled";
|
||||
NSString *const OWSPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress";
|
||||
NSString *const OWSPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView";
|
||||
NSString *const OWSPreferencesKeyShouldShowUnidentifiedDeliveryIndicators
|
||||
= @"OWSPreferencesKeyShouldShowUnidentifiedDeliveryIndicators";
|
||||
NSString *const OWSPreferencesKeyIOSUpgradeNagDate = @"iOSUpgradeNagDate";
|
||||
NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySystemCallLogEnabled";
|
||||
|
||||
@implementation OWSPreferences
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Helpers
|
||||
|
||||
- (void)clear
|
||||
{
|
||||
[NSUserDefaults removeAll];
|
||||
}
|
||||
|
||||
- (nullable id)tryGetValueForKey:(NSString *)key
|
||||
{
|
||||
__block id result;
|
||||
[LKStorage readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
result = [self tryGetValueForKey:key transaction:transaction];
|
||||
}];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (nullable id)tryGetValueForKey:(NSString *)key transaction:(YapDatabaseReadTransaction *)transaction
|
||||
{
|
||||
return [transaction objectForKey:key inCollection:OWSPreferencesSignalDatabaseCollection];
|
||||
}
|
||||
|
||||
- (void)setValueForKey:(NSString *)key toValue:(nullable id)value
|
||||
{
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self setValueForKey:key toValue:value transaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setValueForKey:(NSString *)key
|
||||
toValue:(nullable id)value
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
[transaction setObject:value forKey:key inCollection:OWSPreferencesSignalDatabaseCollection];
|
||||
}
|
||||
|
||||
#pragma mark - Specific Preferences
|
||||
|
||||
- (BOOL)hasDeclinedNoContactsView
|
||||
{
|
||||
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyHasDeclinedNoContactsView];
|
||||
// Default to NO.
|
||||
return preference ? [preference boolValue] : NO;
|
||||
}
|
||||
|
||||
- (void)setHasDeclinedNoContactsView:(BOOL)value
|
||||
{
|
||||
[self setValueForKey:OWSPreferencesKeyHasDeclinedNoContactsView toValue:@(value)];
|
||||
}
|
||||
|
||||
- (void)setIOSUpgradeNagDate:(NSDate *)value
|
||||
{
|
||||
[self setValueForKey:OWSPreferencesKeyIOSUpgradeNagDate toValue:value];
|
||||
}
|
||||
|
||||
- (nullable NSDate *)iOSUpgradeNagDate
|
||||
{
|
||||
return [self tryGetValueForKey:OWSPreferencesKeyIOSUpgradeNagDate];
|
||||
}
|
||||
|
||||
- (BOOL)shouldShowUnidentifiedDeliveryIndicators
|
||||
{
|
||||
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyShouldShowUnidentifiedDeliveryIndicators];
|
||||
return preference ? [preference boolValue] : NO;
|
||||
}
|
||||
|
||||
- (void)setShouldShowUnidentifiedDeliveryIndicators:(BOOL)value
|
||||
{
|
||||
[self setValueForKey:OWSPreferencesKeyShouldShowUnidentifiedDeliveryIndicators toValue:@(value)];
|
||||
}
|
||||
|
||||
#pragma mark - Calling
|
||||
|
||||
#pragma mark CallKit
|
||||
|
||||
- (BOOL)isSystemCallLogEnabled
|
||||
{
|
||||
if (@available(iOS 11, *)) {
|
||||
// do nothing
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeySystemCallLogEnabled];
|
||||
return preference ? preference.boolValue : YES;
|
||||
}
|
||||
|
||||
- (void)setIsSystemCallLogEnabled:(BOOL)flag
|
||||
{
|
||||
if (@available(iOS 11, *)) {
|
||||
// do nothing
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
[self setValueForKey:OWSPreferencesKeySystemCallLogEnabled toValue:@(flag)];
|
||||
}
|
||||
|
||||
// In iOS 10.2.1, Apple fixed a bug wherein call history was backed up to iCloud.
|
||||
//
|
||||
// See: https://support.apple.com/en-us/HT207482
|
||||
//
|
||||
// In iOS 11, Apple introduced a property CXProviderConfiguration.includesCallsInRecents
|
||||
// that allows us to prevent Signal calls made with CallKit from showing up in the device's
|
||||
// call history.
|
||||
//
|
||||
// Therefore in versions of iOS after 11, we have no need of call privacy.
|
||||
#pragma mark Legacy CallKit
|
||||
|
||||
// Be a little conservative with system call logging with legacy users, even though it's
|
||||
// not synced to iCloud, users could be concerned to suddenly see caller names in their
|
||||
// recent calls list.
|
||||
- (void)applyCallLoggingSettingsForLegacyUsersWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
NSNumber *_Nullable callKitPreference =
|
||||
[self tryGetValueForKey:OWSPreferencesKeyCallKitEnabled transaction:transaction];
|
||||
BOOL wasUsingCallKit = callKitPreference ? [callKitPreference boolValue] : YES;
|
||||
|
||||
NSNumber *_Nullable callKitPrivacyPreference =
|
||||
[self tryGetValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled transaction:transaction];
|
||||
BOOL wasUsingCallKitPrivacy = callKitPrivacyPreference ? callKitPrivacyPreference.boolValue : YES;
|
||||
|
||||
BOOL shouldLogCallsInRecents = ^{
|
||||
if (wasUsingCallKit && !wasUsingCallKitPrivacy) {
|
||||
// User was using CallKit and explicitly opted in to showing names/numbers,
|
||||
// so it's OK to continue to show names/numbers in the system recents list.
|
||||
return YES;
|
||||
} else {
|
||||
// User was not previously showing names/numbers in the system
|
||||
// recents list, so don't opt them in.
|
||||
return NO;
|
||||
}
|
||||
}();
|
||||
|
||||
[self setValueForKey:OWSPreferencesKeySystemCallLogEnabled
|
||||
toValue:@(shouldLogCallsInRecents)
|
||||
transaction:transaction];
|
||||
|
||||
// We need to reload the callService.callUIAdapter here, but SignalMessaging doesn't know about CallService, so we use
|
||||
// notifications to decouple the code. This is admittedly awkward, but it only happens once, and the alternative would
|
||||
// be importing all the call related classes into SignalMessaging.
|
||||
[[NSNotificationCenter defaultCenter] postNotificationNameAsync:OWSPreferencesCallLoggingDidChangeNotification object:nil];
|
||||
}
|
||||
|
||||
- (BOOL)isCallKitEnabled
|
||||
{
|
||||
if (@available(iOS 11, *)) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitEnabled];
|
||||
return preference ? [preference boolValue] : YES;
|
||||
}
|
||||
|
||||
- (void)setIsCallKitEnabled:(BOOL)flag
|
||||
{
|
||||
if (@available(iOS 11, *)) {
|
||||
return;
|
||||
}
|
||||
|
||||
[self setValueForKey:OWSPreferencesKeyCallKitEnabled toValue:@(flag)];
|
||||
// Rev callUIAdaptee to get new setting
|
||||
}
|
||||
|
||||
- (BOOL)isCallKitEnabledSet
|
||||
{
|
||||
if (@available(iOS 11, *)) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitEnabled];
|
||||
return preference != nil;
|
||||
}
|
||||
|
||||
- (BOOL)isCallKitPrivacyEnabled
|
||||
{
|
||||
if (@available(iOS 11, *)) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSNumber *_Nullable preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled];
|
||||
if (preference) {
|
||||
return [preference boolValue];
|
||||
} else {
|
||||
// Private by default.
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setIsCallKitPrivacyEnabled:(BOOL)flag
|
||||
{
|
||||
if (@available(iOS 11, *)) {
|
||||
return;
|
||||
}
|
||||
|
||||
[self setValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled toValue:@(flag)];
|
||||
}
|
||||
|
||||
- (BOOL)isCallKitPrivacySet
|
||||
{
|
||||
if (@available(iOS 11, *)) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallKitPrivacyEnabled];
|
||||
return preference != nil;
|
||||
}
|
||||
|
||||
#pragma mark direct call connectivity (non-TURN)
|
||||
|
||||
// Allow callers to connect directly, when desirable, vs. enforcing TURN only proxy connectivity
|
||||
|
||||
- (BOOL)doCallsHideIPAddress
|
||||
{
|
||||
NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyCallsHideIPAddress];
|
||||
return preference ? [preference boolValue] : NO;
|
||||
}
|
||||
|
||||
- (void)setDoCallsHideIPAddress:(BOOL)flag
|
||||
{
|
||||
[self setValueForKey:OWSPreferencesKeyCallsHideIPAddress toValue:@(flag)];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue