diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index c8bfee916..97c2c0957 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -58,30 +58,28 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD Environment.shared.audioSession.setup() SSKEnvironment.shared.reachabilityManager.setup() - if !Environment.shared.preferences.hasGeneratedThumbnails() { - - // Disable the SAE until the main app has successfully completed launch process - // at least once in the post-SAE world. - OWSPreferences.setIsReadyForAppExtensions() - - // Setup the UI - self?.ensureRootViewController() - - if Identity.userExists() { - let appVersion: AppVersion = AppVersion.sharedInstance() + GRDBStorage.shared.writeAsync { db in + // Disable the SAE until the main app has successfully completed launch process + // at least once in the post-SAE world. + db[.isReadyForAppExtensions] = true - // If the device needs to sync config or the user updated to a new version - if - needsConfigSync || ( // TODO: 'needsConfigSync' logic for migrations - (appVersion.lastAppVersion?.count ?? 0) > 0 && - appVersion.lastAppVersion != appVersion.currentAppVersion - ) - { - GRDBStorage.shared.write { db in + if Identity.userExists(db) { + let appVersion: AppVersion = AppVersion.sharedInstance() + + // If the device needs to sync config or the user updated to a new version + if + needsConfigSync || ( + (appVersion.lastAppVersion?.count ?? 0) > 0 && + appVersion.lastAppVersion != appVersion.currentAppVersion + ) + { try MessageSender.syncConfiguration(db, forceSyncNow: true).retainUntilComplete() } } } + + // Setup the UI + self?.ensureRootViewController() } ) diff --git a/SessionMessagingKit/Database/LegacyDatabase/SMKLegacy.swift b/SessionMessagingKit/Database/LegacyDatabase/SMKLegacy.swift index 948c40449..06d6b7816 100644 --- a/SessionMessagingKit/Database/LegacyDatabase/SMKLegacy.swift +++ b/SessionMessagingKit/Database/LegacyDatabase/SMKLegacy.swift @@ -59,6 +59,7 @@ public enum SMKLegacy { internal static let preferencesKeyNotificationSoundInForeground = "NotificationSoundInForeground" internal static let preferencesKeyHasSavedThreadKey = "hasSavedThread" internal static let preferencesKeyHasSentAMessageKey = "User has sent a message" + internal static let preferencesKeyIsReadyForAppExtensions = "isReadyForAppExtensions_5" internal static let readReceiptManagerCollection = "OWSReadReceiptManagerCollection" internal static let readReceiptManagerAreReadReceiptsEnabled = "areReadReceiptsEnabled" diff --git a/SessionMessagingKit/Database/Migrations/_003_YDBToGRDBMigration.swift b/SessionMessagingKit/Database/Migrations/_003_YDBToGRDBMigration.swift index ce84fbd95..6f323bb51 100644 --- a/SessionMessagingKit/Database/Migrations/_003_YDBToGRDBMigration.swift +++ b/SessionMessagingKit/Database/Migrations/_003_YDBToGRDBMigration.swift @@ -1420,6 +1420,7 @@ enum _003_YDBToGRDBMigration: Migration { .bool(forKey: SMKLegacy.userDefaultsHasHiddenMessageRequests) db[.hasSavedThread] = (legacyPreferences[SMKLegacy.preferencesKeyHasSavedThreadKey] as? Bool == true) db[.hasSentAMessage] = (legacyPreferences[SMKLegacy.preferencesKeyHasSentAMessageKey] as? Bool == true) + db[.isReadyForAppExtensions] = CurrentAppContext().appUserDefaults().bool(forKey: SMKLegacy.preferencesKeyIsReadyForAppExtensions) print("RAWR [\(Date().timeIntervalSince1970)] - Process preferences inserts - End") diff --git a/SessionMessagingKit/Utilities/OWSPreferences.h b/SessionMessagingKit/Utilities/OWSPreferences.h index 895d13d75..39904bd44 100644 --- a/SessionMessagingKit/Utilities/OWSPreferences.h +++ b/SessionMessagingKit/Utilities/OWSPreferences.h @@ -36,9 +36,6 @@ extern NSString *const OWSPreferencesCallLoggingDidChangeNotification; #pragma mark - Specific Preferences -+ (BOOL)isReadyForAppExtensions; -+ (void)setIsReadyForAppExtensions; - - (BOOL)hasSentAMessage; - (void)setHasSentAMessage:(BOOL)enabled; @@ -48,9 +45,6 @@ extern NSString *const OWSPreferencesCallLoggingDidChangeNotification; - (void)setIOSUpgradeNagDate:(NSDate *)value; - (nullable NSDate *)iOSUpgradeNagDate; -- (BOOL)hasGeneratedThumbnails; -- (void)setHasGeneratedThumbnails:(BOOL)value; - - (BOOL)shouldShowUnidentifiedDeliveryIndicators; - (void)setShouldShowUnidentifiedDeliveryIndicators:(BOOL)value; diff --git a/SessionMessagingKit/Utilities/OWSPreferences.m b/SessionMessagingKit/Utilities/OWSPreferences.m index 3aa051865..80779d80d 100644 --- a/SessionMessagingKit/Utilities/OWSPreferences.m +++ b/SessionMessagingKit/Utilities/OWSPreferences.m @@ -12,11 +12,9 @@ NSString *const OWSPreferencesKeyCallKitEnabled = @"CallKitEnabled"; NSString *const OWSPreferencesKeyCallKitPrivacyEnabled = @"CallKitPrivacyEnabled"; NSString *const OWSPreferencesKeyCallsHideIPAddress = @"CallsHideIPAddress"; NSString *const OWSPreferencesKeyHasDeclinedNoContactsView = @"hasDeclinedNoContactsView"; -NSString *const OWSPreferencesKeyHasGeneratedThumbnails = @"OWSPreferencesKeyHasGeneratedThumbnails"; NSString *const OWSPreferencesKeyShouldShowUnidentifiedDeliveryIndicators = @"OWSPreferencesKeyShouldShowUnidentifiedDeliveryIndicators"; NSString *const OWSPreferencesKeyIOSUpgradeNagDate = @"iOSUpgradeNagDate"; -NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExtensions_5"; NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySystemCallLogEnabled"; @implementation OWSPreferences @@ -68,23 +66,6 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste #pragma mark - Specific Preferences -+ (BOOL)isReadyForAppExtensions -{ - NSNumber *preference = [NSUserDefaults.appUserDefaults objectForKey:OWSPreferencesKey_IsReadyForAppExtensions]; - - if (preference) { - return [preference boolValue]; - } else { - return NO; - } -} - -+ (void)setIsReadyForAppExtensions -{ - [NSUserDefaults.appUserDefaults setObject:@(YES) forKey:OWSPreferencesKey_IsReadyForAppExtensions]; - [NSUserDefaults.appUserDefaults synchronize]; -} - - (BOOL)hasDeclinedNoContactsView { NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyHasDeclinedNoContactsView]; @@ -97,18 +78,6 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste [self setValueForKey:OWSPreferencesKeyHasDeclinedNoContactsView toValue:@(value)]; } -- (BOOL)hasGeneratedThumbnails -{ - NSNumber *preference = [self tryGetValueForKey:OWSPreferencesKeyHasGeneratedThumbnails]; - // Default to NO. - return preference ? [preference boolValue] : NO; -} - -- (void)setHasGeneratedThumbnails:(BOOL)value -{ - [self setValueForKey:OWSPreferencesKeyHasGeneratedThumbnails toValue:@(value)]; -} - - (void)setIOSUpgradeNagDate:(NSDate *)value { [self setValueForKey:OWSPreferencesKeyIOSUpgradeNagDate toValue:value]; diff --git a/SessionMessagingKit/Utilities/Preferences.swift b/SessionMessagingKit/Utilities/Preferences.swift index 022c1e4c6..913b76f92 100644 --- a/SessionMessagingKit/Utilities/Preferences.swift +++ b/SessionMessagingKit/Utilities/Preferences.swift @@ -49,6 +49,9 @@ public extension Setting.BoolKey { /// A flag indicating whether the user has ever send a message static let hasSentAMessage: Setting.BoolKey = "hasSentAMessageKey" + + /// A flag indicating whether the app is ready for app extensions to run + static let isReadyForAppExtensions: Setting.BoolKey = "isReadyForAppExtensions" } public extension Setting.StringKey { diff --git a/SessionNotificationServiceExtension/NotificationServiceExtension.swift b/SessionNotificationServiceExtension/NotificationServiceExtension.swift index 8d53f5262..6c3c60b47 100644 --- a/SessionNotificationServiceExtension/NotificationServiceExtension.swift +++ b/SessionNotificationServiceExtension/NotificationServiceExtension.swift @@ -112,7 +112,7 @@ public final class NotificationServiceExtension : UNNotificationServiceExtension // this path should never occur. However, the service does have our push token // so it is possible that could change in the future. If it does, do nothing // and don't disturb the user. Messages will be processed when they open the app. - guard OWSPreferences.isReadyForAppExtensions() else { return completeSilenty() } + guard GRDBStorage.shared[.isReadyForAppExtensions] else { return completeSilenty() } AppSetup.setupEnvironment( appSpecificSingletonBlock: {