mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
4.4 KiB
Objective-C
111 lines
4.4 KiB
Objective-C
#import "PreferencesUtil.h"
|
|
#import "CryptoTools.h"
|
|
#import "Constraints.h"
|
|
#import "PhoneNumber.h"
|
|
#import "Util.h"
|
|
|
|
#import "NotificationManifest.h"
|
|
|
|
#define CALL_STREAM_DES_BUFFER_LEVEL_KEY @"CallStreamDesiredBufferLevel"
|
|
|
|
#define PHONE_DIRECTORY_BLOOM_FILTER_HASH_COUNT_KEY @"Directory Bloom Hash Count"
|
|
#define PHONE_DIRECTORY_BLOOM_FILTER_DATA_KEY @"Directory Bloom Data"
|
|
#define PHONE_DIRECTORY_EXPIRATION @"Directory Expiration"
|
|
|
|
#define DEFAULT_CALL_STREAM_DES_BUFFER_LEVEL 0.5
|
|
|
|
#define SETTINGS_EXPANDED_ROW_PREF_DICT_KEY @"Settings Expanded Row Pref Dict Key"
|
|
|
|
#define FRESH_INSTALL_TUTORIALS_ENABLED_KEY @"Fresh Install Tutorials Enabled Key"
|
|
#define CONTACT_IMAGES_ENABLED_KEY @"Contact Images Enabled Key"
|
|
#define AUTOCORRECT_ENABLED_KEY @"Autocorrect Enabled Key"
|
|
#define HISTORY_LOG_ENABLED_KEY @"History Log Enabled Key"
|
|
|
|
@implementation PropertyListPreferences (PropertyUtil)
|
|
|
|
-(PhoneNumberDirectoryFilter*) tryGetSavedPhoneNumberDirectory {
|
|
NSUInteger hashCount = [[self tryGetValueForKey:PHONE_DIRECTORY_BLOOM_FILTER_HASH_COUNT_KEY] unsignedIntegerValue];
|
|
NSData* data = [self tryGetValueForKey:PHONE_DIRECTORY_BLOOM_FILTER_DATA_KEY];
|
|
NSDate* expiration = [self tryGetValueForKey:PHONE_DIRECTORY_EXPIRATION];
|
|
if (hashCount == 0 || [data length] == 0 || expiration == nil) return nil;
|
|
BloomFilter* bloomFilter = [BloomFilter bloomFilterWithHashCount:hashCount andData:data];
|
|
return [PhoneNumberDirectoryFilter phoneNumberDirectoryFilterWithBloomFilter:bloomFilter
|
|
andExpirationDate:expiration];
|
|
}
|
|
-(void) setSavedPhoneNumberDirectory:(PhoneNumberDirectoryFilter*)phoneNumberDirectoryFilter {
|
|
[self setValueForKey:PHONE_DIRECTORY_BLOOM_FILTER_DATA_KEY toValue:nil];
|
|
[self setValueForKey:PHONE_DIRECTORY_BLOOM_FILTER_HASH_COUNT_KEY toValue:nil];
|
|
[self setValueForKey:PHONE_DIRECTORY_EXPIRATION toValue:nil];
|
|
if (phoneNumberDirectoryFilter == nil) return;
|
|
|
|
NSData* data = [[phoneNumberDirectoryFilter bloomFilter] data];
|
|
NSNumber* hashCount = [NSNumber numberWithUnsignedInteger:[[phoneNumberDirectoryFilter bloomFilter] hashCount]];
|
|
NSDate* expiry = [phoneNumberDirectoryFilter getExpirationDate];
|
|
[self setValueForKey:PHONE_DIRECTORY_BLOOM_FILTER_DATA_KEY toValue:data];
|
|
[self setValueForKey:PHONE_DIRECTORY_BLOOM_FILTER_HASH_COUNT_KEY toValue:hashCount];
|
|
[self setValueForKey:PHONE_DIRECTORY_EXPIRATION toValue:expiry];
|
|
[self sendDirectoryUpdateNotification];
|
|
}
|
|
|
|
-(void) sendDirectoryUpdateNotification{
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_DIRECTORY_UPDATE object:nil];
|
|
}
|
|
|
|
-(NSTimeInterval) getCachedOrDefaultDesiredBufferDepth {
|
|
id v = [self tryGetValueForKey:CALL_STREAM_DES_BUFFER_LEVEL_KEY];
|
|
if (v == nil) return DEFAULT_CALL_STREAM_DES_BUFFER_LEVEL;
|
|
return [v doubleValue];
|
|
}
|
|
-(void) setCachedDesiredBufferDepth:(double)value {
|
|
require(value >= 0);
|
|
[self setValueForKey:CALL_STREAM_DES_BUFFER_LEVEL_KEY toValue:[NSNumber numberWithDouble:value]];
|
|
}
|
|
|
|
-(BOOL) getFreshInstallTutorialsEnabled {
|
|
NSNumber *preference = [self tryGetValueForKey:FRESH_INSTALL_TUTORIALS_ENABLED_KEY];
|
|
if (preference) {
|
|
return [preference boolValue];
|
|
} else {
|
|
return YES;
|
|
}
|
|
}
|
|
-(BOOL) getContactImagesEnabled {
|
|
NSNumber *preference = [self tryGetValueForKey:CONTACT_IMAGES_ENABLED_KEY];
|
|
if (preference) {
|
|
return [preference boolValue];
|
|
} else {
|
|
return YES;
|
|
}
|
|
}
|
|
-(BOOL) getAutocorrectEnabled {
|
|
NSNumber *preference = [self tryGetValueForKey:AUTOCORRECT_ENABLED_KEY];
|
|
if (preference) {
|
|
return [preference boolValue];
|
|
} else {
|
|
return YES;
|
|
}
|
|
}
|
|
-(BOOL) getHistoryLogEnabled {
|
|
NSNumber *preference = [self tryGetValueForKey:HISTORY_LOG_ENABLED_KEY];
|
|
if (preference) {
|
|
return [preference boolValue];
|
|
} else {
|
|
return YES;
|
|
}
|
|
}
|
|
|
|
-(void) setFreshInstallTutorialsEnabled:(BOOL)enabled {
|
|
[self setValueForKey:FRESH_INSTALL_TUTORIALS_ENABLED_KEY toValue:[NSNumber numberWithBool:enabled]];
|
|
}
|
|
-(void) setContactImagesEnabled:(BOOL)enabled {
|
|
[self setValueForKey:CONTACT_IMAGES_ENABLED_KEY toValue:[NSNumber numberWithBool:enabled]];
|
|
}
|
|
-(void) setAutocorrectEnabled:(BOOL)enabled {
|
|
[self setValueForKey:AUTOCORRECT_ENABLED_KEY toValue:[NSNumber numberWithBool:enabled]];
|
|
}
|
|
-(void) setHistoryLogEnabled:(BOOL)enabled {
|
|
[self setValueForKey:HISTORY_LOG_ENABLED_KEY toValue:[NSNumber numberWithBool:enabled]];
|
|
}
|
|
|
|
@end
|