UserSettings.m 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2012-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "UserSettings.h"
  21. #import "AppGroup.h"
  22. #import "LicenseStore.h"
  23. #import "DatabaseManager.h"
  24. #import "ServerConnector.h"
  25. #import "MyIdentityStore.h"
  26. #import "AvatarMaker.h"
  27. #import "ValidationLogger.h"
  28. #import "PushSetting.h"
  29. #import "EntityManager.h"
  30. #import "EntityFetcher.h"
  31. #import "NSString+Hex.h"
  32. #import "Conversation.h"
  33. #import "Contact.h"
  34. @implementation UserSettings {
  35. NSUserDefaults *defaults;
  36. }
  37. @synthesize sendReadReceipts;
  38. @synthesize syncContacts;
  39. @synthesize syncExclusionList;
  40. @synthesize blacklist;
  41. @synthesize workIdentities;
  42. @synthesize pushSettingsList;
  43. @synthesize sendTypingIndicator;
  44. @synthesize blockUnknown;
  45. @synthesize enablePoi;
  46. @synthesize hideStaleContacts;
  47. @synthesize inAppSounds;
  48. @synthesize inAppVibrate;
  49. @synthesize inAppPreview;
  50. @synthesize pushSound;
  51. @synthesize pushGroupGenerated;
  52. @synthesize pushGroupSound;
  53. @synthesize pushDecrypt;
  54. @synthesize pushShowNickname;
  55. @synthesize imageSize;
  56. @synthesize videoQuality;
  57. @synthesize autoSaveMedia;
  58. @synthesize chatFontSize;
  59. @synthesize useDynamicFontSize;
  60. @synthesize disableBigEmojis;
  61. @synthesize wallpaper;
  62. @synthesize showReceivedTimestamps;
  63. @synthesize returnToSend;
  64. @synthesize darkTheme;
  65. @synthesize useSystemTheme;
  66. @synthesize showProfilePictures;
  67. @synthesize sortOrderFirstName;
  68. @synthesize displayOrderFirstName;
  69. @synthesize validationLogging;
  70. @synthesize enableIPv6;
  71. @synthesize companyDirectory;
  72. @synthesize askedForPushDecryption;
  73. @synthesize sendProfilePicture;
  74. @synthesize profilePictureContactList;
  75. @synthesize profilePictureRequestList;
  76. @synthesize showGalleryPreview;
  77. @synthesize disableProximityMonitoring;
  78. @synthesize enableThreemaCall;
  79. @synthesize alwaysRelayCalls;
  80. @synthesize enableCallKit;
  81. @synthesize previewLimit;
  82. @synthesize acceptedPrivacyPolicyDate;
  83. @synthesize acceptedPrivacyPolicyVariant;
  84. @synthesize voIPSound;
  85. @synthesize threemaWeb;
  86. @synthesize openPlusIconInChat;
  87. @synthesize safeConfig;
  88. @synthesize safeIntroShown;
  89. @synthesize workInfoShown;
  90. @synthesize videoCallInChatInfoShown;
  91. @synthesize videoCallInfoShown;
  92. @synthesize videoCallSpeakerInfoShown;
  93. @synthesize sentryAppDevice;
  94. @synthesize enableMasterDnd;
  95. @synthesize masterDndWorkingDays;
  96. @synthesize masterDndStartTime;
  97. @synthesize masterDndEndTime;
  98. @synthesize enableVideoCall;
  99. @synthesize threemaVideoCallQualitySetting;
  100. @synthesize quoteV2Active;
  101. static UserSettings *instance;
  102. + (UserSettings*)sharedUserSettings {
  103. @synchronized (self) {
  104. if (!instance)
  105. instance = [[UserSettings alloc] init];
  106. }
  107. return instance;
  108. }
  109. + (void)resetSharedInstance {
  110. [instance initFromUserDefaults];
  111. }
  112. - (id)init
  113. {
  114. self = [super init];
  115. if (self) {
  116. defaults = [AppGroup userDefaults];
  117. /* Push group sound migration */
  118. if ([defaults stringForKey:@"PushGroupSound"] == nil) {
  119. [self setPushGroupSound:[defaults stringForKey:@"PushSound"]];
  120. }
  121. if ([defaults stringForKey:@"VoIPSound"] == nil) {
  122. [self setVoIPSound:@"threema_best"];
  123. }
  124. NSMutableOrderedSet *tmpNoPushIdentities = [NSMutableOrderedSet orderedSetWithArray:[defaults arrayForKey:@"NoPushIdentities"]];
  125. if (tmpNoPushIdentities.array.count > 0) {
  126. [self pushSettingsMigration:tmpNoPushIdentities];
  127. }
  128. BOOL defaultDarkTheme = NO;
  129. BOOL defaultUseSystemTheme = true;
  130. BOOL defaultWorkInfoShown = false;
  131. if ([LicenseStore requiresLicenseKey]) {
  132. defaultDarkTheme = YES;
  133. defaultUseSystemTheme = false;
  134. defaultWorkInfoShown = true;
  135. }
  136. NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
  137. [NSNumber numberWithBool:YES], @"SendReadReceipts",
  138. [NSNumber numberWithBool:NO], @"SyncContacts",
  139. [NSArray array], @"SyncExclusionList",
  140. [NSArray array], @"Blacklist",
  141. [NSArray array], @"WorkIdentities",
  142. [NSArray array], @"PushSettingsList",
  143. [NSNumber numberWithBool:YES], @"SendTypingIndicator",
  144. [NSNumber numberWithBool:YES], @"InAppSounds",
  145. [NSNumber numberWithBool:YES], @"InAppVibrate",
  146. [NSNumber numberWithBool:YES], @"InAppPreview",
  147. [NSNumber numberWithBool:NO], @"BlockUnknown",
  148. [NSNumber numberWithBool:YES], @"EnablePOI",
  149. [NSNumber numberWithBool:NO], @"HideStaleContacts",
  150. @"large", @"ImageSize",
  151. @"high", @"VideoQuality",
  152. [NSNumber numberWithBool:NO], @"AutoSaveMedia",
  153. [NSNumber numberWithFloat:16.0f], @"ChatFontSize",
  154. [NSNumber numberWithBool:YES], @"UseDynamicFontSize",
  155. [NSNumber numberWithBool:NO], @"DisableBigEmojis",
  156. [NSNumber numberWithBool:YES], @"ShowReceivedTimestamps",
  157. [NSNumber numberWithBool:NO], @"ReturnToSend",
  158. [NSNumber numberWithBool:defaultDarkTheme], @"DarkTheme",
  159. [NSNumber numberWithBool:defaultUseSystemTheme], @"UseSystemTheme",
  160. [NSNumber numberWithBool:YES], @"ShowProfilePictures",
  161. [NSNumber numberWithBool:NO], @"SortOrderFirstName",
  162. [NSNumber numberWithBool:YES], @"DisplayOrderFirstName",
  163. @"default", @"PushSound",
  164. [NSNumber numberWithBool:NO], @"PushGroupGenerated",
  165. @"default", @"PushGroupSound",
  166. [NSNumber numberWithBool:NO], @"PushDecrypt",
  167. [NSNumber numberWithBool:NO], @"PushShowNickname",
  168. [NSNumber numberWithBool:NO], @"ValidationLogging",
  169. [NSNumber numberWithBool:YES], @"EnableIPv6",
  170. [NSNumber numberWithBool:NO], @"CompanyDirectory",
  171. [NSNumber numberWithBool:NO], @"AskedForPushDecryption",
  172. [NSNumber numberWithInt:SendProfilePictureNone], @"SendProfilePicture",
  173. [NSArray array], @"ProfilePictureContactList",
  174. [NSArray array], @"ProfilePictureRequestList",
  175. [NSNumber numberWithBool:YES], @"ShowGalleryPreview",
  176. [NSNumber numberWithBool:NO], @"DisableProximityMonitoring",
  177. [NSNumber numberWithBool:YES], @"EnableThreemaCall",
  178. [NSNumber numberWithBool:NO], @"AlwaysRelayCalls",
  179. [NSNumber numberWithBool:YES], @"EnableCallKit",
  180. [NSNumber numberWithFloat:50.0], @"PreviewLimit",
  181. [NSNumber numberWithBool:YES], @"ThreemaWeb",
  182. [NSNumber numberWithBool:NO], @"OpenPlusIconInChat",
  183. [NSData data], @"SafeConfig",
  184. [NSNumber numberWithBool:NO], @"SafeIntroShown",
  185. [NSNumber numberWithBool:defaultWorkInfoShown], @"WorkInfoShown",
  186. [NSNumber numberWithBool:NO], @"VideoCallInChatInfoShown",
  187. [NSNumber numberWithBool:NO], @"VideoCallInfoShown",
  188. [NSNumber numberWithBool:NO], @"VideoCallSpeakerInfoShown",
  189. [NSNumber numberWithBool:NO], @"EnableMasterDnd",
  190. [NSArray array], @"MasterDNDWorkingDays",
  191. @"08:00", @"MasterDNDStartTime",
  192. @"17:00", @"MasterDNDEndTime",
  193. [NSNumber numberWithBool:YES], @"EnableVideoCall",
  194. [NSNumber numberWithBool:NO], @"QuoteV2Active",
  195. [NSNumber numberWithInt:ThreemaVideoCallQualitySettingAuto], @"ThreemaVideoCallQualitySetting",
  196. @"", @"SentryAppDevice",
  197. nil];
  198. [defaults registerDefaults:appDefaults];
  199. [self initFromUserDefaults];
  200. }
  201. return self;
  202. }
  203. - (void)initFromUserDefaults {
  204. sendReadReceipts = [defaults boolForKey:@"SendReadReceipts"];
  205. syncContacts = [defaults boolForKey:@"SyncContacts"];
  206. syncExclusionList = [defaults arrayForKey:@"SyncExclusionList"];
  207. blacklist = [NSOrderedSet orderedSetWithArray:[defaults arrayForKey:@"Blacklist"]];
  208. workIdentities = [NSOrderedSet orderedSetWithArray:[defaults arrayForKey:@"WorkIdentities"]];
  209. pushSettingsList = [NSOrderedSet orderedSetWithArray:[defaults arrayForKey:@"PushSettingsList"]];
  210. sendTypingIndicator = [defaults boolForKey:@"SendTypingIndicator"];
  211. blockUnknown = [defaults boolForKey:@"BlockUnknown"];
  212. enablePoi = [defaults boolForKey:@"EnablePOI"];
  213. hideStaleContacts = [defaults boolForKey:@"HideStaleContacts"];
  214. inAppSounds = [defaults boolForKey:@"InAppSounds"];
  215. inAppVibrate = [defaults boolForKey:@"InAppVibrate"];
  216. inAppPreview = [defaults boolForKey:@"InAppPreview"];
  217. pushSound = [defaults stringForKey:@"PushSound"];
  218. pushGroupGenerated = [defaults boolForKey:@"PushGroupGenerated"];
  219. pushGroupSound = [defaults stringForKey:@"PushGroupSound"];
  220. pushDecrypt = [defaults boolForKey:@"PushDecrypt"];
  221. pushShowNickname = [defaults boolForKey:@"PushShowNickname"];
  222. imageSize = [defaults stringForKey:@"ImageSize"];
  223. videoQuality = [defaults stringForKey:@"VideoQuality"];
  224. autoSaveMedia = [defaults boolForKey:@"AutoSaveMedia"];
  225. chatFontSize = [defaults floatForKey:@"ChatFontSize"];
  226. useDynamicFontSize = [defaults boolForKey:@"UseDynamicFontSize"];
  227. disableBigEmojis = [defaults boolForKey:@"DisableBigEmojis"];
  228. showReceivedTimestamps = [defaults boolForKey:@"ShowReceivedTimestamps"];
  229. returnToSend = [defaults boolForKey:@"ReturnToSend"];
  230. darkTheme = [defaults boolForKey:@"DarkTheme"];
  231. useSystemTheme = [defaults boolForKey:@"UseSystemTheme"];
  232. showProfilePictures = [defaults boolForKey:@"ShowProfilePictures"];
  233. NSString *wallpaperPath = [self wallpaperPath];
  234. if ([[NSFileManager defaultManager] fileExistsAtPath:wallpaperPath]) {
  235. wallpaper = [UIImage imageWithContentsOfFile:wallpaperPath];
  236. }
  237. sortOrderFirstName = [defaults boolForKey:@"SortOrderFirstName"];
  238. displayOrderFirstName = [defaults boolForKey:@"DisplayOrderFirstName"];
  239. validationLogging = [defaults boolForKey:@"ValidationLogging"];
  240. enableIPv6 = [defaults boolForKey:@"EnableIPv6"];
  241. companyDirectory = [defaults boolForKey:@"CompanyDirectory"];
  242. askedForPushDecryption = [defaults boolForKey:@"AskedForPushDecryption"];
  243. sendProfilePicture = [[defaults objectForKey:@"SendProfilePicture"] intValue];
  244. profilePictureContactList = [defaults arrayForKey:@"ProfilePictureContactList"];
  245. profilePictureRequestList = [defaults arrayForKey:@"ProfilePictureRequestList"];
  246. showGalleryPreview = [defaults boolForKey:@"ShowGalleryPreview"];
  247. disableProximityMonitoring = [defaults boolForKey:@"DisableProximityMonitoring"];
  248. enableThreemaCall = [defaults boolForKey:@"EnableThreemaCall"];
  249. alwaysRelayCalls = [defaults boolForKey:@"AlwaysRelayCalls"];
  250. enableCallKit = [defaults boolForKey:@"EnableCallKit"];
  251. previewLimit = [defaults floatForKey:@"PreviewLimit"];
  252. acceptedPrivacyPolicyDate = [defaults objectForKey:@"AcceptedPrivacyPolicyDate"];
  253. acceptedPrivacyPolicyVariant = [[defaults objectForKey:@"AcceptedPrivacyPolicyVariant"] intValue];
  254. voIPSound = [defaults stringForKey:@"VoIPSound"];
  255. threemaWeb = [defaults boolForKey:@"ThreemaWeb"];
  256. openPlusIconInChat = [defaults boolForKey:@"OpenPlusIconInChat"];
  257. safeConfig = [defaults dataForKey:@"SafeConfig"];
  258. safeIntroShown = [defaults boolForKey:@"SafeIntroShown"];
  259. workInfoShown = [defaults boolForKey:@"WorkInfoShown"];
  260. videoCallInChatInfoShown = [defaults boolForKey:@"VideoCallInChatInfoShown"];
  261. videoCallInfoShown = [defaults boolForKey:@"VideoCallInfoShown"];
  262. videoCallSpeakerInfoShown = [defaults boolForKey:@"VideoCallSpeakerInfoShown"];
  263. NSString *tmpSentryAppDevice = [defaults stringForKey:@"SentryAppDevice"];
  264. if (tmpSentryAppDevice != nil) {
  265. if ([tmpSentryAppDevice isEqualToString:@""]) {
  266. sentryAppDevice = nil;
  267. } else {
  268. sentryAppDevice = [defaults stringForKey:@"SentryAppDevice"];
  269. }
  270. } else {
  271. sentryAppDevice = nil;
  272. }
  273. enableMasterDnd = [defaults boolForKey:@"EnableMasterDnd"];
  274. masterDndWorkingDays = [NSOrderedSet orderedSetWithArray:[defaults arrayForKey:@"MasterDNDWorkingDays"]];
  275. masterDndStartTime = [defaults objectForKey:@"MasterDNDStartTime"];
  276. masterDndEndTime = [defaults objectForKey:@"MasterDNDEndTime"];
  277. enableVideoCall = [defaults boolForKey:@"EnableVideoCall"];
  278. threemaVideoCallQualitySetting = [[defaults objectForKey:@"ThreemaVideoCallQualitySetting"] intValue];
  279. #ifdef DEBUG
  280. quoteV2Active = [defaults boolForKey:@"QuoteV2Active"];
  281. #else
  282. quoteV2Active = false;
  283. #endif
  284. }
  285. - (void)pushSettingsMigration:(NSOrderedSet *)tmpNoPushIdentities {
  286. NSMutableOrderedSet *pushSettings = [NSMutableOrderedSet new];
  287. for (NSString *identity in tmpNoPushIdentities.array) {
  288. PushSetting *tmpPushSetting = [PushSetting new];
  289. tmpPushSetting.identity = identity;
  290. tmpPushSetting.type = kPushSettingTypeOff;
  291. tmpPushSetting.periodOffTime = 0;
  292. tmpPushSetting.periodOffTillDate = nil;
  293. tmpPushSetting.silent = false;
  294. tmpPushSetting.mentions = false;
  295. [pushSettings addObject:tmpPushSetting.buildDict];
  296. }
  297. [self setPushSettingsList:pushSettings];
  298. [defaults removeObjectForKey:@"NoPushIdentities"];
  299. [defaults synchronize];
  300. }
  301. - (void)setSendReadReceipts:(BOOL)newSendReadReceipts {
  302. sendReadReceipts = newSendReadReceipts;
  303. [[ValidationLogger sharedValidationLogger] logString:[NSString stringWithFormat:@"Read receipts bug: set flag to %@", newSendReadReceipts ? @"true" : @"false"]];
  304. [defaults setBool:sendReadReceipts forKey:@"SendReadReceipts"];
  305. [defaults synchronize];
  306. [[ValidationLogger sharedValidationLogger] logString:[NSString stringWithFormat:@"Read receipts bug: It's now set to %@", [defaults boolForKey:@"SendReadReceipts"] ? @"true" : @"false"]];
  307. }
  308. - (void)setSyncContacts:(BOOL)newSyncContacts {
  309. syncContacts = newSyncContacts;
  310. [defaults setBool:syncContacts forKey:@"SyncContacts"];
  311. [defaults synchronize];
  312. }
  313. - (void)setSyncExclusionList:(NSArray *)newSyncExclusionList {
  314. syncExclusionList = newSyncExclusionList;
  315. [defaults setObject:syncExclusionList forKey:@"SyncExclusionList"];
  316. [defaults synchronize];
  317. }
  318. - (void)setBlacklist:(NSOrderedSet *)newBlacklist {
  319. blacklist = newBlacklist;
  320. [defaults setObject:blacklist.array forKey:@"Blacklist"];
  321. [defaults synchronize];
  322. }
  323. - (void)setWorkIdentities:(NSOrderedSet *)newWorkIdentities {
  324. workIdentities = newWorkIdentities;
  325. [defaults setObject:workIdentities.array forKey:@"WorkIdentities"];
  326. [defaults synchronize];
  327. }
  328. - (void)setPushSettingsList:(NSOrderedSet *)newPushSettingsList {
  329. pushSettingsList = newPushSettingsList;
  330. [defaults setObject:pushSettingsList.array forKey:@"PushSettingsList"];
  331. [defaults synchronize];
  332. }
  333. - (void)setSendTypingIndicator:(BOOL)newSendTypingIndicator {
  334. sendTypingIndicator = newSendTypingIndicator;
  335. [defaults setBool:sendTypingIndicator forKey:@"SendTypingIndicator"];
  336. [defaults synchronize];
  337. }
  338. - (void)setBlockUnknown:(BOOL)newBlockUnknown {
  339. blockUnknown = newBlockUnknown;
  340. [defaults setBool:blockUnknown forKey:@"BlockUnknown"];
  341. [defaults synchronize];
  342. }
  343. - (void)setEnablePoi:(BOOL)newEnablePoi {
  344. enablePoi = newEnablePoi;
  345. [defaults setBool:enablePoi forKey:@"EnablePOI"];
  346. [defaults synchronize];
  347. }
  348. - (void)setHideStaleContacts:(BOOL)newHideStaleContacts {
  349. hideStaleContacts = newHideStaleContacts;
  350. [defaults setBool:hideStaleContacts forKey:@"HideStaleContacts"];
  351. [defaults synchronize];
  352. }
  353. - (void)setInAppSounds:(BOOL)newInAppSounds {
  354. inAppSounds = newInAppSounds;
  355. [defaults setBool:inAppSounds forKey:@"InAppSounds"];
  356. [defaults synchronize];
  357. }
  358. - (void)setInAppVibrate:(BOOL)newInAppVibrate {
  359. inAppVibrate = newInAppVibrate;
  360. [defaults setBool:inAppVibrate forKey:@"InAppVibrate"];
  361. [defaults synchronize];
  362. }
  363. - (void)setInAppPreview:(BOOL)newInAppPreview {
  364. inAppPreview = newInAppPreview;
  365. [defaults setBool:inAppPreview forKey:@"InAppPreview"];
  366. [defaults synchronize];
  367. }
  368. - (void)setPushSound:(NSString *)newPushSound {
  369. pushSound = newPushSound;
  370. [defaults setObject:pushSound forKey:@"PushSound"];
  371. [defaults synchronize];
  372. }
  373. - (void)setPushGroupGenerated:(BOOL)newPushGroupGenerated {
  374. pushGroupGenerated = newPushGroupGenerated;
  375. [defaults setBool:newPushGroupGenerated forKey:@"PushGroupGenerated"];
  376. [defaults synchronize];
  377. }
  378. - (void)setPushGroupSound:(NSString *)newPushGroupSound {
  379. pushGroupSound = newPushGroupSound;
  380. [defaults setObject:pushGroupSound forKey:@"PushGroupSound"];
  381. [defaults synchronize];
  382. }
  383. - (void)setPushDecrypt:(BOOL)newPushDecrypt {
  384. pushDecrypt = newPushDecrypt;
  385. [defaults setBool:pushDecrypt forKey:@"PushDecrypt"];
  386. [defaults synchronize];
  387. }
  388. - (void)setPushShowNickname:(BOOL)newPushShowNickname {
  389. pushShowNickname = newPushShowNickname;
  390. [defaults setBool:pushShowNickname forKey:@"PushShowNickname"];
  391. [defaults synchronize];
  392. }
  393. - (void)setImageSize:(NSString *)newImageSize {
  394. imageSize = newImageSize;
  395. [defaults setObject:imageSize forKey:@"ImageSize"];
  396. [defaults synchronize];
  397. }
  398. - (void)setVideoQuality:(NSString *)newVideoQuality {
  399. videoQuality = newVideoQuality;
  400. [defaults setObject:videoQuality forKey:@"VideoQuality"];
  401. [defaults synchronize];
  402. }
  403. - (void)setAutoSaveMedia:(BOOL)newAutoSaveMedia {
  404. autoSaveMedia = newAutoSaveMedia;
  405. [defaults setBool:autoSaveMedia forKey:@"AutoSaveMedia"];
  406. [defaults synchronize];
  407. }
  408. - (void)setChatFontSize:(float)newChatFontSize {
  409. chatFontSize = newChatFontSize;
  410. [defaults setFloat:chatFontSize forKey:@"ChatFontSize"];
  411. [defaults synchronize];
  412. [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationFontSizeChanged object:nil];
  413. }
  414. - (float)chatFontSize {
  415. if (useDynamicFontSize) {
  416. UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
  417. CGFloat size = fontDescriptor.pointSize;
  418. return size;
  419. } else {
  420. return chatFontSize;
  421. }
  422. }
  423. - (void)setUseDynamicFontSize:(BOOL)newUseDynamicFontSize {
  424. useDynamicFontSize = newUseDynamicFontSize;
  425. [defaults setBool:useDynamicFontSize forKey:@"UseDynamicFontSize"];
  426. [defaults synchronize];
  427. [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationFontSizeChanged object:nil];
  428. }
  429. - (void)setShowReceivedTimestamps:(BOOL)newShowReceivedTimestamps {
  430. showReceivedTimestamps = newShowReceivedTimestamps;
  431. [defaults setBool:showReceivedTimestamps forKey:@"ShowReceivedTimestamps"];
  432. [defaults synchronize];
  433. [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationShowTimestampSettingsChanged object:nil];
  434. }
  435. - (void)setReturnToSend:(BOOL)newReturnToSend {
  436. returnToSend = newReturnToSend;
  437. [defaults setBool:returnToSend forKey:@"ReturnToSend"];
  438. [defaults synchronize];
  439. }
  440. - (void)setDarkTheme:(BOOL)newDarkTheme {
  441. darkTheme = newDarkTheme;
  442. [defaults setBool:darkTheme forKey:@"DarkTheme"];
  443. [defaults synchronize];
  444. [StyleKit resetThemedCache];
  445. [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationColorThemeChanged object:nil];
  446. }
  447. - (void)setUseSystemTheme:(BOOL)newUseSystemTheme {
  448. useSystemTheme = newUseSystemTheme;
  449. [defaults setBool:useSystemTheme forKey:@"UseSystemTheme"];
  450. [defaults synchronize];
  451. }
  452. - (void)setShowProfilePictures:(BOOL)newShowProfilePictures {
  453. showProfilePictures = newShowProfilePictures;
  454. [defaults setBool:showProfilePictures forKey:@"ShowProfilePictures"];
  455. [defaults synchronize];
  456. [[AvatarMaker sharedAvatarMaker] clearCacheForProfilePicture];
  457. [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationShowProfilePictureChanged object:nil];
  458. }
  459. - (void)setWallpaper:(UIImage *)_wallpaper {
  460. wallpaper = _wallpaper;
  461. if (_wallpaper != nil) {
  462. NSData *wallpaperData = UIImagePNGRepresentation(wallpaper);
  463. [wallpaperData writeToFile:[self wallpaperPath] atomically:NO];
  464. [[ValidationLogger sharedValidationLogger] logString:@"Wallpaper: Set wallpaper"];
  465. } else {
  466. [[NSFileManager defaultManager] removeItemAtPath:[self wallpaperPath] error:nil];
  467. [[ValidationLogger sharedValidationLogger] logString:@"Wallpaper: Removed wallpaper"];
  468. }
  469. [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationWallpaperChanged object:nil];
  470. }
  471. - (void)checkWallpaper {
  472. if (wallpaper == nil) {
  473. NSString *wallpaperPath = [self wallpaperPath];
  474. if ([[NSFileManager defaultManager] fileExistsAtPath:wallpaperPath]) {
  475. wallpaper = [UIImage imageWithContentsOfFile:wallpaperPath];
  476. }
  477. }
  478. }
  479. - (void)setSortOrderFirstName:(BOOL)newSortOrderFirstName displayOrderFirstName:(BOOL)newDisplayOrderFirstName {
  480. if (sortOrderFirstName == newSortOrderFirstName && displayOrderFirstName == newDisplayOrderFirstName)
  481. return;
  482. sortOrderFirstName = newSortOrderFirstName;
  483. displayOrderFirstName = newDisplayOrderFirstName;
  484. [defaults setBool:sortOrderFirstName forKey:@"SortOrderFirstName"];
  485. [defaults setBool:displayOrderFirstName forKey:@"DisplayOrderFirstName"];
  486. [defaults synchronize];
  487. [[NSNotificationCenter defaultCenter] postNotificationName:@"ThreemaContactsOrderChanged" object:nil];
  488. }
  489. - (void)setSortOrderFirstName:(BOOL)newSortOrderFirstName {
  490. if (sortOrderFirstName == newSortOrderFirstName)
  491. return;
  492. sortOrderFirstName = newSortOrderFirstName;
  493. [defaults setBool:sortOrderFirstName forKey:@"SortOrderFirstName"];
  494. [defaults synchronize];
  495. [[NSNotificationCenter defaultCenter] postNotificationName:@"ThreemaContactsOrderChanged" object:nil];
  496. }
  497. - (void)setDisplayOrderFirstName:(BOOL)newDisplayOrderFirstName {
  498. if (displayOrderFirstName == newDisplayOrderFirstName)
  499. return;
  500. displayOrderFirstName = newDisplayOrderFirstName;
  501. [defaults setBool:displayOrderFirstName forKey:@"DisplayOrderFirstName"];
  502. [defaults synchronize];
  503. [[NSNotificationCenter defaultCenter] postNotificationName:@"ThreemaContactsOrderChanged" object:nil];
  504. }
  505. - (NSString*)wallpaperPath {
  506. NSString *documentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
  507. return [documentsDir stringByAppendingPathComponent:@"wallpaper"];
  508. }
  509. - (void)setValidationLogging:(BOOL)newValidationLogging {
  510. validationLogging = newValidationLogging;
  511. [defaults setBool:validationLogging forKey:@"ValidationLogging"];
  512. [defaults synchronize];
  513. }
  514. - (void)setEnableIPv6:(BOOL)newEnableIPv6 {
  515. enableIPv6 = newEnableIPv6;
  516. [defaults setBool:enableIPv6 forKey:@"EnableIPv6"];
  517. [defaults synchronize];
  518. }
  519. - (void)setCompanyDirectory:(BOOL)newCompanyDirectory {
  520. companyDirectory = newCompanyDirectory;
  521. [defaults setBool:companyDirectory forKey:@"CompanyDirectory"];
  522. [defaults synchronize];
  523. }
  524. - (void)setDisableBigEmojis:(BOOL)newDisableBigEmojis {
  525. disableBigEmojis = newDisableBigEmojis;
  526. [defaults setBool:disableBigEmojis forKey:@"DisableBigEmojis"];
  527. [defaults synchronize];
  528. [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationFontSizeChanged object:nil];
  529. }
  530. - (void)setAskedForPushDecryption:(BOOL)newAskedForPushDecryption {
  531. askedForPushDecryption = newAskedForPushDecryption;
  532. [defaults setBool:askedForPushDecryption forKey:@"AskedForPushDecryption"];
  533. [defaults synchronize];
  534. }
  535. - (void)setSendProfilePicture:(enum SendProfilePicture)newSendProfilePicture {
  536. sendProfilePicture = newSendProfilePicture;
  537. [defaults setObject:[NSNumber numberWithInt:newSendProfilePicture] forKey:@"SendProfilePicture"];
  538. [defaults synchronize];
  539. }
  540. - (void)setProfilePictureContactList:(NSArray *)newProfilePictureContactList {
  541. profilePictureContactList = newProfilePictureContactList;
  542. [defaults setObject:profilePictureContactList forKey:@"ProfilePictureContactList"];
  543. [defaults synchronize];
  544. }
  545. - (void)setProfilePictureRequestList:(NSArray *)newProfilePictureRequestList {
  546. profilePictureRequestList = newProfilePictureRequestList;
  547. [defaults setObject:profilePictureRequestList forKey:@"ProfilePictureRequestList"];
  548. [defaults synchronize];
  549. }
  550. - (void)setShowGalleryPreview:(BOOL)newShowGalleryPreview {
  551. showGalleryPreview = newShowGalleryPreview;
  552. [defaults setBool:showGalleryPreview forKey:@"ShowGalleryPreview"];
  553. [defaults synchronize];
  554. }
  555. - (void)setDisableProximityMonitoring:(BOOL)newDisableProximityMonitoring {
  556. disableProximityMonitoring = newDisableProximityMonitoring;
  557. [defaults setBool:disableProximityMonitoring forKey:@"DisableProximityMonitoring"];
  558. [defaults synchronize];
  559. }
  560. - (void)setEnableThreemaCall:(BOOL)newEnableThreemaCall {
  561. enableThreemaCall = newEnableThreemaCall;
  562. [defaults setBool:enableThreemaCall forKey:@"EnableThreemaCall"];
  563. [defaults synchronize];
  564. }
  565. - (void)setAlwaysRelayCalls:(BOOL)newAlwaysRelayCalls {
  566. alwaysRelayCalls = newAlwaysRelayCalls;
  567. [defaults setBool:alwaysRelayCalls forKey:@"AlwaysRelayCalls"];
  568. [defaults synchronize];
  569. }
  570. - (void)setEnableCallKit:(BOOL)newEnableCallKit {
  571. enableCallKit = newEnableCallKit;
  572. [defaults setBool:enableCallKit forKey:@"EnableCallKit"];
  573. [defaults synchronize];
  574. }
  575. - (void)setPreviewLimit:(float)newPreviewLimit {
  576. previewLimit = newPreviewLimit;
  577. [defaults setFloat:previewLimit forKey:@"PreviewLimit"];
  578. [defaults synchronize];
  579. }
  580. - (void)setAcceptedPrivacyPolicyDate:(NSDate *)newAcceptedPrivacyPolicyDate {
  581. acceptedPrivacyPolicyDate = newAcceptedPrivacyPolicyDate;
  582. [defaults setObject:acceptedPrivacyPolicyDate forKey:@"AcceptedPrivacyPolicyDate"];
  583. [defaults synchronize];
  584. }
  585. - (void)setAcceptedPrivacyPolicyVariant:(enum AcceptPrivacyPolicyVariant)newAcceptedPrivacyPolicyVariant {
  586. acceptedPrivacyPolicyVariant = newAcceptedPrivacyPolicyVariant;
  587. [defaults setObject:[NSNumber numberWithInt:acceptedPrivacyPolicyVariant] forKey:@"AcceptedPrivacyPolicyVariant"];
  588. [defaults synchronize];
  589. }
  590. - (void)setVoIPSound:(NSString *)newVoIPSound {
  591. voIPSound = newVoIPSound;
  592. [defaults setObject:voIPSound forKey:@"VoIPSound"];
  593. [defaults synchronize];
  594. }
  595. - (NSInteger)largeTitleDisplayMode {
  596. return UINavigationItemLargeTitleDisplayModeAlways;
  597. }
  598. - (void)setThreemaWeb:(BOOL)newThreemaWeb {
  599. threemaWeb = newThreemaWeb;
  600. [defaults setBool:threemaWeb forKey:@"ThreemaWeb"];
  601. [defaults synchronize];
  602. }
  603. - (void)setOpenPlusIconInChat:(BOOL)newOpenPlusIconInChat {
  604. openPlusIconInChat = newOpenPlusIconInChat;
  605. [defaults setBool:openPlusIconInChat forKey:@"OpenPlusIconInChat"];
  606. [defaults synchronize];
  607. }
  608. - (void)setSafeConfig:(NSData *)newSafeConfig {
  609. safeConfig = newSafeConfig;
  610. [defaults setObject:safeConfig forKey:@"SafeConfig"];
  611. [defaults synchronize];
  612. }
  613. - (void)setSafeIntroShown:(BOOL)newSafeIntroShown {
  614. safeIntroShown = newSafeIntroShown;
  615. [defaults setBool:safeIntroShown forKey:@"SafeIntroShown"];
  616. [defaults synchronize];
  617. }
  618. - (void)setWorkInfoShown:(BOOL)newWorkInfoShown {
  619. workInfoShown = newWorkInfoShown;
  620. [defaults setBool:workInfoShown forKey:@"WorkInfoShown"];
  621. [defaults synchronize];
  622. }
  623. - (void)setVideoCallInChatInfoShown:(BOOL)newVideoCallInChatInfoShown {
  624. videoCallInChatInfoShown = newVideoCallInChatInfoShown;
  625. [defaults setBool:videoCallInChatInfoShown forKey:@"VideoCallInChatInfoShown"];
  626. [defaults synchronize];
  627. }
  628. - (void)setVideoCallInfoShown:(BOOL)newVideoCallInfoShown {
  629. videoCallInfoShown = newVideoCallInfoShown;
  630. [defaults setBool:videoCallInfoShown forKey:@"VideoCallInfoShown"];
  631. [defaults synchronize];
  632. }
  633. - (void)setVideoCallSpeakerInfoShown:(BOOL)newVideoCallSpeakerInfoShown {
  634. videoCallSpeakerInfoShown = newVideoCallSpeakerInfoShown;
  635. [defaults setBool:videoCallSpeakerInfoShown forKey:@"VideoCallSpeakerInfoShown"];
  636. [defaults synchronize];
  637. }
  638. - (void)setSentryAppDevice:(NSString *)newSentryAppDevice {
  639. sentryAppDevice = newSentryAppDevice;
  640. [defaults setObject:sentryAppDevice forKey:@"SentryAppDevice"];
  641. [defaults synchronize];
  642. }
  643. - (void)setEnableMasterDnd:(BOOL)newEnableMasterDnd {
  644. enableMasterDnd = newEnableMasterDnd;
  645. [defaults setBool:enableMasterDnd forKey:@"EnableMasterDnd"];
  646. [defaults synchronize];
  647. }
  648. - (void)setMasterDndWorkingDays:(NSOrderedSet *)newMasterDndWorkingDays {
  649. masterDndWorkingDays = newMasterDndWorkingDays;
  650. [defaults setObject:masterDndWorkingDays.array forKey:@"MasterDNDWorkingDays"];
  651. [defaults synchronize];
  652. }
  653. - (void)setMasterDndStartTime:(NSString *)newMasterDndStartTime {
  654. masterDndStartTime = newMasterDndStartTime;
  655. [defaults setObject:masterDndStartTime forKey:@"MasterDNDStartTime"];
  656. [defaults synchronize];
  657. }
  658. - (void)setMasterDndEndTime:(NSString *)newMasterDndEndTime {
  659. masterDndEndTime = newMasterDndEndTime;
  660. [defaults setObject:masterDndEndTime forKey:@"MasterDNDEndTime"];
  661. [defaults synchronize];
  662. }
  663. - (void)setEnableVideoCall:(BOOL)newEnableVideoCall {
  664. enableVideoCall = newEnableVideoCall;
  665. [defaults setBool:enableVideoCall forKey:@"EnableVideoCall"];
  666. [defaults synchronize];
  667. }
  668. - (void)setThreemaVideoCallQualitySetting:(enum ThreemaVideoCallQualitySetting)newThreemaVideoCallQualitySetting {
  669. threemaVideoCallQualitySetting = newThreemaVideoCallQualitySetting;
  670. [defaults setObject:[NSNumber numberWithInt:threemaVideoCallQualitySetting] forKey:@"ThreemaVideoCallQualitySetting"];
  671. [defaults synchronize];
  672. }
  673. - (void)setQuoteV2Active:(BOOL)newQuoteV2Active {
  674. quoteV2Active = newQuoteV2Active;
  675. [defaults setBool:quoteV2Active forKey:@"QuoteV2Active"];
  676. [defaults synchronize];
  677. }
  678. @end