diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index b9f7f6a93..ef2c72c63 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -4230,7 +4230,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 44; + CURRENT_PROJECT_VERSION = 45; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; @@ -4244,7 +4244,7 @@ INFOPLIST_FILE = SignalShareExtension/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.3; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.share-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -4292,7 +4292,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 44; + CURRENT_PROJECT_VERSION = 45; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = SUQ8J2PCT7; ENABLE_NS_ASSERTIONS = NO; @@ -4311,7 +4311,7 @@ INFOPLIST_FILE = SignalShareExtension/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.3; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.share-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -4346,7 +4346,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 44; + CURRENT_PROJECT_VERSION = 45; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4365,7 +4365,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.3; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.utilities"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -4415,7 +4415,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 44; + CURRENT_PROJECT_VERSION = 45; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = SUQ8J2PCT7; @@ -4439,7 +4439,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.3; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger.utilities"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; @@ -4624,7 +4624,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 44; + CURRENT_PROJECT_VERSION = 45; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -4659,7 +4659,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.3; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; PRODUCT_NAME = Session; @@ -4691,7 +4691,7 @@ CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 44; + CURRENT_PROJECT_VERSION = 45; DEVELOPMENT_TEAM = SUQ8J2PCT7; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -4726,7 +4726,7 @@ "$(SRCROOT)", ); LLVM_LTO = NO; - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.3; OTHER_LDFLAGS = "$(inherited)"; PRODUCT_BUNDLE_IDENTIFIER = "com.loki-project.loki-messenger"; PRODUCT_NAME = Session; diff --git a/Signal/src/Loki/View Controllers/DisplayNameVC.swift b/Signal/src/Loki/View Controllers/DisplayNameVC.swift index 264a5fd3d..7e2c0875f 100644 --- a/Signal/src/Loki/View Controllers/DisplayNameVC.swift +++ b/Signal/src/Loki/View Controllers/DisplayNameVC.swift @@ -155,7 +155,7 @@ final class DisplayNameVC : UIViewController { return showError(title: NSLocalizedString("Please pick a shorter display name", comment: "")) } TSAccountManager.sharedInstance().didRegister() - OWSProfileManager.shared().updateLocalProfileName(displayName, avatarImage: nil, success: { }, failure: { _ in }) // Try to save the user name but ignore the result + OWSProfileManager.shared().updateLocalProfileName(displayName, avatarImage: nil, success: { }, failure: { _ in }, requiresSync: false) // Try to save the user name but ignore the result let homeVC = HomeVC() navigationController!.setViewControllers([ homeVC ], animated: true) } diff --git a/Signal/src/Loki/View Controllers/HomeVC.swift b/Signal/src/Loki/View Controllers/HomeVC.swift index c4498d2a9..df587fff3 100644 --- a/Signal/src/Loki/View Controllers/HomeVC.swift +++ b/Signal/src/Loki/View Controllers/HomeVC.swift @@ -152,6 +152,7 @@ final class HomeVC : UIViewController, UITableViewDataSource, UITableViewDelegat // openGroupSuggestionSheet.modalTransitionStyle = .crossDissolve // present(openGroupSuggestionSheet, animated: true, completion: nil) // } + UserDefaults.standard.set(true, forKey: "hasLaunchedOnce") } override func viewWillDisappear(_ animated: Bool) { diff --git a/Signal/src/Loki/View Controllers/SettingsVC.swift b/Signal/src/Loki/View Controllers/SettingsVC.swift index 4e92331db..f2cf55625 100644 --- a/Signal/src/Loki/View Controllers/SettingsVC.swift +++ b/Signal/src/Loki/View Controllers/SettingsVC.swift @@ -288,7 +288,7 @@ final class SettingsVC : UIViewController, AvatarViewHelperDelegate { self?.present(alert, animated: true, completion: nil) } } - }) + }, requiresSync: true) } } diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 536a69d45..85ef8ea6c 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -428,7 +428,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat @"profile update fails.")]; }]; }); - }]; + } requiresSync:NO]; }]; } diff --git a/Signal/src/ViewControllers/Registration/OnboardingProfileViewController.swift b/Signal/src/ViewControllers/Registration/OnboardingProfileViewController.swift index 795bfd7e5..9543e204b 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingProfileViewController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingProfileViewController.swift @@ -177,7 +177,7 @@ public class OnboardingProfileViewController: OnboardingBaseViewController { comment: "Error message shown when a profile update fails.")) }) } - }) + }, requiresSync: false) } } diff --git a/Signal/src/util/Backup/OWSBackupImportJob.m b/Signal/src/util/Backup/OWSBackupImportJob.m index 2d94a7bc5..0cca6f2de 100644 --- a/Signal/src/util/Backup/OWSBackupImportJob.m +++ b/Signal/src/util/Backup/OWSBackupImportJob.m @@ -339,7 +339,8 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe failure:^(NSError *error) { // Ignore errors related to local profile. resolve(@(1)); - }]; + } + requiresSync:YES]; }]; } diff --git a/SignalMessaging/contacts/OWSSyncManager.m b/SignalMessaging/contacts/OWSSyncManager.m index 0c673d497..ba406ca04 100644 --- a/SignalMessaging/contacts/OWSSyncManager.m +++ b/SignalMessaging/contacts/OWSSyncManager.m @@ -225,9 +225,13 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag [AppReadiness runNowOrWhenAppDidBecomeReady:^{ if (!self.tsAccountManager.isRegisteredAndReady) { return; + } + + NSUserDefaults *userDefaults = NSUserDefaults.standardUserDefaults; + BOOL hasLaunchedOnce = [userDefaults boolForKey:@"hasLaunchedOnce"]; + if (hasLaunchedOnce) { // FIXME: Quick and dirty workaround to not do this on initial launch + [self sendConfigurationSyncMessage_AppReady]; } - - [self sendConfigurationSyncMessage_AppReady]; }]; } diff --git a/SignalMessaging/profiles/OWSProfileManager.h b/SignalMessaging/profiles/OWSProfileManager.h index 69d991906..28f361c39 100644 --- a/SignalMessaging/profiles/OWSProfileManager.h +++ b/SignalMessaging/profiles/OWSProfileManager.h @@ -50,7 +50,8 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter; - (void)updateLocalProfileName:(nullable NSString *)profileName avatarImage:(nullable UIImage *)avatarImage success:(void (^)(void))successBlock - failure:(void (^)(NSError *))failureBlock; + failure:(void (^)(NSError *))failureBlock + requiresSync:(BOOL)requiresSync; - (BOOL)isProfileNameTooLong:(nullable NSString *)profileName; diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index bc4376d20..bd2b6887e 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -230,6 +230,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); avatarImage:(nullable UIImage *)avatarImage success:(void (^)(void))successBlockParameter failure:(void (^)(NSError *))failureBlockParameter + requiresSync:(BOOL)requiresSync { OWSAssertDebug(successBlockParameter); OWSAssertDebug(failureBlockParameter); @@ -244,7 +245,9 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); // // NOTE: We also inform the desktop in the failure case, // since that _may have_ affected service state. - [[self.syncManager syncLocalContact] retainUntilComplete]; + if (requiresSync) { + [[self.syncManager syncLocalContact] retainUntilComplete]; + } dispatch_async(dispatch_get_main_queue(), ^{ failureBlockParameter(error); @@ -256,7 +259,9 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); // We use a "self-only" contact sync to indicate to desktop // that we've changed our profile and that it should do a // profile fetch for "self". - [[self.syncManager syncLocalContact] retainUntilComplete]; + if (requiresSync) { + [[self.syncManager syncLocalContact] retainUntilComplete]; + } dispatch_async(dispatch_get_main_queue(), ^{ successBlockParameter(); diff --git a/SignalMessaging/profiles/OWSUserProfile.m b/SignalMessaging/profiles/OWSUserProfile.m index 6eb0a0e1a..0119159e0 100644 --- a/SignalMessaging/profiles/OWSUserProfile.m +++ b/SignalMessaging/profiles/OWSUserProfile.m @@ -243,7 +243,10 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId"; // We populate an initial (empty) profile on launch of a new install, but until // we have a registered account, syncing will fail (and there could not be any // linked device to sync to at this point anyway). - if ([self.tsAccountManager isRegistered] && CurrentAppContext().isMainApp) { + + NSUserDefaults *userDefaults = NSUserDefaults.standardUserDefaults; + BOOL hasLaunchedOnce = [userDefaults boolForKey:@"hasLaunchedOnce"]; + if ([self.tsAccountManager isRegistered] && CurrentAppContext().isMainApp && hasLaunchedOnce) { [[self.syncManager syncLocalContact] retainUntilComplete]; } diff --git a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift index 53aae20c7..d6b061679 100644 --- a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift @@ -3,7 +3,7 @@ import SignalMetadataKit /// Base class for `LokiFileServerAPI` and `LokiPublicChatAPI`. public class LokiDotNetAPI : NSObject { - + // MARK: Convenience internal static let storage = OWSPrimaryStorage.shared() internal static let userKeyPair = OWSIdentityManager.shared().identityKeyPair()! @@ -41,6 +41,17 @@ public class LokiDotNetAPI : NSObject { return result } } + + internal static func getAuthToken(for server: String, in transaction: YapDatabaseReadWriteTransaction? = nil) -> Promise { + if let token = getAuthTokenFromDatabase(for: server, in: transaction) { + return Promise.value(token) + } else { + return requestNewAuthToken(for: server).then(on: DispatchQueue.global()) { submitAuthToken($0, for: server) }.map { token -> String in + setAuthToken(for: server, to: token, in: transaction) + return token + } + } + } private static func setAuthToken(for server: String, to newValue: String, in transaction: YapDatabaseReadWriteTransaction? = nil) { func setAuthTokenInternal(in transaction: YapDatabaseReadWriteTransaction) { @@ -159,18 +170,6 @@ public class LokiDotNetAPI : NSObject { } } } - - // MARK: Internal API - internal static func getAuthToken(for server: String, in transaction: YapDatabaseReadWriteTransaction? = nil) -> Promise { - if let token = getAuthTokenFromDatabase(for: server, in: transaction) { - return Promise.value(token) - } else { - return requestNewAuthToken(for: server).then(on: DispatchQueue.global()) { submitAuthToken($0, for: server) }.map { token -> String in - setAuthToken(for: server, to: token, in: transaction) - return token - } - } - } // MARK: Private API private static func requestNewAuthToken(for server: String) -> Promise {