diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 41654b539..30405927e 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -27,7 +27,7 @@ 34480B491FD0A60200BC14EF /* OWSMath.h in Headers */ = {isa = PBXBuildFile; fileRef = 34480B481FD0A60200BC14EF /* OWSMath.h */; settings = {ATTRIBUTES = (Public, ); }; }; 34480B521FD0A7A400BC14EF /* OWSLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = 34480B4A1FD0A7A200BC14EF /* OWSLogger.h */; settings = {ATTRIBUTES = (Public, ); }; }; 34480B531FD0A7A400BC14EF /* OWSLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 34480B4B1FD0A7A300BC14EF /* OWSLogger.m */; }; - 34480B551FD0A7A400BC14EF /* DebugLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = 34480B4D1FD0A7A300BC14EF /* DebugLogger.h */; }; + 34480B551FD0A7A400BC14EF /* DebugLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = 34480B4D1FD0A7A300BC14EF /* DebugLogger.h */; settings = {ATTRIBUTES = (Public, ); }; }; 34480B561FD0A7A400BC14EF /* DebugLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 34480B4E1FD0A7A300BC14EF /* DebugLogger.m */; }; 34480B571FD0A7A400BC14EF /* OWSScrubbingLogFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = 34480B4F1FD0A7A300BC14EF /* OWSScrubbingLogFormatter.h */; }; 34480B591FD0A7A400BC14EF /* OWSScrubbingLogFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 34480B511FD0A7A400BC14EF /* OWSScrubbingLogFormatter.m */; }; @@ -48,7 +48,7 @@ 3461293E1FD1D72B00532771 /* ExperienceUpgradeFinder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3461293D1FD1D72B00532771 /* ExperienceUpgradeFinder.swift */; }; 3461295A1FD1D74C00532771 /* Environment.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129401FD1D74B00532771 /* Environment.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3461295B1FD1D74C00532771 /* Environment.m in Sources */ = {isa = PBXBuildFile; fileRef = 346129411FD1D74B00532771 /* Environment.m */; }; - 3461296F1FD1D74C00532771 /* Release.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129561FD1D74B00532771 /* Release.h */; }; + 3461296F1FD1D74C00532771 /* Release.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129561FD1D74B00532771 /* Release.h */; settings = {ATTRIBUTES = (Public, ); }; }; 346129701FD1D74C00532771 /* Release.m in Sources */ = {isa = PBXBuildFile; fileRef = 346129571FD1D74B00532771 /* Release.m */; }; 346129711FD1D74C00532771 /* SignalKeyingStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129581FD1D74B00532771 /* SignalKeyingStorage.h */; }; 346129721FD1D74C00532771 /* SignalKeyingStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = 346129591FD1D74B00532771 /* SignalKeyingStorage.m */; }; @@ -71,7 +71,7 @@ 346129A01FD1EFE200532771 /* CryptoTools.m in Sources */ = {isa = PBXBuildFile; fileRef = 3461299E1FD1EFE200532771 /* CryptoTools.m */; }; 346129A51FD1F09100532771 /* OWSContactsManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129A21FD1F09100532771 /* OWSContactsManager.h */; }; 346129A61FD1F09100532771 /* OWSContactsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 346129A31FD1F09100532771 /* OWSContactsManager.m */; }; - 346129A91FD1F0E000532771 /* OWSFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129A81FD1F0DF00532771 /* OWSFormat.h */; }; + 346129A91FD1F0E000532771 /* OWSFormat.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129A81FD1F0DF00532771 /* OWSFormat.h */; settings = {ATTRIBUTES = (Public, ); }; }; 346129AB1FD1F0EE00532771 /* OWSFormat.m in Sources */ = {isa = PBXBuildFile; fileRef = 346129AA1FD1F0EE00532771 /* OWSFormat.m */; }; 346129AD1FD1F34E00532771 /* ImageCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346129AC1FD1F34E00532771 /* ImageCache.swift */; }; 346129AF1FD1F5D900532771 /* SystemContactsFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346129AE1FD1F5D900532771 /* SystemContactsFetcher.swift */; }; @@ -144,8 +144,6 @@ 34CCAF381F0C0599004084F4 /* AppUpdateNag.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CCAF371F0C0599004084F4 /* AppUpdateNag.m */; }; 34CCAF3B1F0C2748004084F4 /* OWSAddToContactViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CCAF3A1F0C2748004084F4 /* OWSAddToContactViewController.m */; }; 34CE88E71F2FB9A10098030F /* ProfileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CE88E61F2FB9A10098030F /* ProfileViewController.m */; }; - 34CE88EC1F3237260098030F /* OWSProfileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 34CE88EA1F3237260098030F /* OWSProfileManager.m */; }; - 34CE88ED1F3237260098030F /* ProfileFetcherJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34CE88EB1F3237260098030F /* ProfileFetcherJob.swift */; }; 34D1F0501F7D45A60066283D /* GifPickerCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D1F04F1F7D45A60066283D /* GifPickerCell.swift */; }; 34D1F0521F7E8EA30066283D /* GiphyDownloader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D1F0511F7E8EA30066283D /* GiphyDownloader.swift */; }; 34D1F0821F8678AA0066283D /* ConversationHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D1F0661F8678AA0066283D /* ConversationHeaderView.m */; }; @@ -850,7 +848,6 @@ 45847E861E4283C30080EAB3 /* Intents.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Intents.framework; path = System/Library/Frameworks/Intents.framework; sourceTree = SDKROOT; }; 45855F351D9498A40084F340 /* OWSContactAvatarBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSContactAvatarBuilder.h; sourceTree = ""; }; 45855F361D9498A40084F340 /* OWSContactAvatarBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSContactAvatarBuilder.m; sourceTree = ""; }; - 4585C4651ED5DF7A00896AEA /* ProfileFetcherJob.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProfileFetcherJob.swift; sourceTree = ""; }; 4585C4671ED8F8D200896AEA /* SafetyNumberConfirmationAlert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SafetyNumberConfirmationAlert.swift; sourceTree = ""; }; 4589670F1DC117CC00E9DD21 /* SignalTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SignalTests-Bridging-Header.h"; sourceTree = ""; }; 458967101DC117CC00E9DD21 /* AccountManagerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AccountManagerTest.swift; path = Models/AccountManagerTest.swift; sourceTree = ""; }; @@ -1641,7 +1638,6 @@ 451DE9FC1DC1A28200810E42 /* SyncPushTokensJob.swift */, 45D231761DC7E8F10034FA89 /* SessionResetJob.swift */, 452ECA4C1E087E7200E2F016 /* MessageFetcherJob.swift */, - 4585C4651ED5DF7A00896AEA /* ProfileFetcherJob.swift */, 451686AA1F520CDA00AC3D4B /* MultiDeviceProfileKeyUpdateJob.swift */, ); name = Jobs; @@ -2795,11 +2791,9 @@ 340CB2241EAC155C0001CAA1 /* ContactsViewHelper.m in Sources */, 45B72DDA1FD5E70600151AF6 /* ConversationSearcher.swift in Sources */, 34D1F0AB1F867BFC0066283D /* OWSContactOffersCell.m in Sources */, - 34CE88EC1F3237260098030F /* OWSProfileManager.m in Sources */, B60C16651988999D00E97A6C /* VersionMigrations.m in Sources */, 343A65981FC4CFE7000477A1 /* ConversationScrollButton.m in Sources */, B97940271832BD2400BD66CB /* UIUtil.m in Sources */, - 34CE88ED1F3237260098030F /* ProfileFetcherJob.swift in Sources */, 34B3F8791E8DF1700035BE1A /* CountryCodeViewController.m in Sources */, 34D1F0A91F867BFC0066283D /* ConversationViewCell.m in Sources */, 3461298B1FD1E2AB00532771 /* OWS102MoveLoggingPreferenceToUserDefaults.m in Sources */, diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 86fb79edf..654b8542c 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -14,18 +14,19 @@ #import "OWSContactsSyncing.h" #import "OWSNavigationController.h" #import "OWSPreferences.h" -#import "OWSProfileManager.h" #import "Pastelog.h" #import "PushManager.h" #import "RegistrationViewController.h" #import "Release.h" #import "SendExternalFileViewController.h" #import "Signal-Swift.h" +#import "SignalApp.h" #import "SignalsNavigationController.h" #import "VersionMigrations.h" #import "ViewControllerUtils.h" #import #import +#import #import #import #import @@ -170,9 +171,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [self prepareScreenProtection]; - self.contactsSyncing = [[OWSContactsSyncing alloc] initWithContactsManager:[Environment getCurrent].contactsManager + self.contactsSyncing = [[OWSContactsSyncing alloc] initWithContactsManager:[Environment current].contactsManager identityManager:[OWSIdentityManager sharedManager] - messageSender:[Environment getCurrent].messageSender + messageSender:[Environment current].messageSender profileManager:[OWSProfileManager sharedManager]]; [[NSNotificationCenter defaultCenter] addObserver:self @@ -291,17 +292,17 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [SessionCipher setSessionCipherDispatchQueue:[OWSDispatch sessionStoreQueue]]; TextSecureKitEnv *sharedEnv = - [[TextSecureKitEnv alloc] initWithCallMessageHandler:[Environment getCurrent].callMessageHandler - contactsManager:[Environment getCurrent].contactsManager - messageSender:[Environment getCurrent].messageSender - notificationsManager:[Environment getCurrent].notificationsManager + [[TextSecureKitEnv alloc] initWithCallMessageHandler:SignalApp.sharedApp.callMessageHandler + contactsManager:[Environment current].contactsManager + messageSender:[Environment current].messageSender + notificationsManager:SignalApp.sharedApp.notificationsManager profileManager:OWSProfileManager.sharedManager]; [TextSecureKitEnv setSharedEnv:sharedEnv]; [[TSStorageManager sharedManager] setupDatabaseWithSafeBlockingMigrations:^{ [VersionMigrations runSafeBlockingMigrations]; }]; - [[Environment getCurrent].contactsManager startObserving]; + [[Environment current].contactsManager startObserving]; } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken @@ -336,7 +337,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; annotation:(id)annotation { if ([url.scheme isEqualToString:kURLSchemeSGNLKey]) { if ([url.host hasPrefix:kURLHostVerifyPrefix] && ![TSAccountManager isRegistered]) { - id signupController = [Environment getCurrent].signUpFlowNavigationController; + id signupController = [Environment current].signUpFlowNavigationController; if ([signupController isKindOfClass:[UINavigationController class]]) { UINavigationController *navController = (UINavigationController *)signupController; UIViewController *controller = [navController.childViewControllers lastObject]; @@ -354,7 +355,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; } } else if ([url.scheme.lowercaseString isEqualToString:@"file"]) { - if ([Environment getCurrent].callService.call != nil) { + if (SignalApp.sharedApp.callService.call != nil) { DDLogWarn(@"%@ ignoring 'open with Signal' due to ongoing WebRTC call.", self.logTag); return NO; } @@ -494,9 +495,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; viewController.attachment = attachment; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; - [[[Environment getCurrent] homeViewController] presentTopLevelModalViewController:navigationController - animateDismissal:NO - animatePresentation:YES]; + [SignalApp.sharedApp.homeViewController presentTopLevelModalViewController:navigationController + animateDismissal:NO + animatePresentation:YES]; } - (void)applicationDidBecomeActive:(UIApplication *)application { @@ -563,7 +564,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // Avoid blocking app launch by putting all further possible DB access in async block dispatch_async(dispatch_get_main_queue(), ^{ [TSSocketManager requestSocketOpen]; - [[Environment getCurrent].contactsManager fetchSystemContactsOnceIfAlreadyAuthorized]; + [[Environment current].contactsManager fetchSystemContactsOnceIfAlreadyAuthorized]; // This will fetch new messages, if we're using domain fronting. [[PushManager sharedManager] applicationDidBecomeActive]; @@ -575,7 +576,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // "Background App Refresh" will not be able to obtain an APN token. Enabling those settings does not // restart the app, so we check every activation for users who haven't yet registered. __unused AnyPromise *promise = - [OWSSyncPushTokensJob runWithAccountManager:[Environment getCurrent].accountManager + [OWSSyncPushTokensJob runWithAccountManager:SignalApp.sharedApp.accountManager preferences:[Environment preferences]]; } }); @@ -596,7 +597,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // If app has not re-entered active, show screen protection if necessary. [self showScreenProtection]; } - [[[Environment getCurrent] homeViewController] updateInboxCountLabel]; + [SignalApp.sharedApp.homeViewController updateInboxCountLabel]; [application endBackgroundTask:bgTask]; }); } @@ -609,7 +610,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler { if ([TSAccountManager isRegistered]) { - [[Environment getCurrent].homeViewController showNewConversationView]; + [SignalApp.sharedApp.homeViewController showNewConversationView]; completionHandler(YES); } else { UIAlertController *controller = @@ -675,10 +676,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // * It can be received if the user taps the "video" button for a contact in the // contacts app. If so, the correct response is to try to initiate a new call // to that user - unless there already is another call in progress. - if ([Environment getCurrent].callService.call != nil) { - if ([phoneNumber isEqualToString:[Environment getCurrent].callService.call.remotePhoneNumber]) { + if (SignalApp.sharedApp.callService.call != nil) { + if ([phoneNumber isEqualToString:SignalApp.sharedApp.callService.call.remotePhoneNumber]) { DDLogWarn(@"%@ trying to upgrade ongoing call to video.", self.logTag); - [[Environment getCurrent].callService handleCallKitStartVideo]; + [SignalApp.sharedApp.callService handleCallKitStartVideo]; return YES; } else { DDLogWarn( @@ -687,7 +688,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; } } - OutboundCallInitiator *outboundCallInitiator = [Environment getCurrent].outboundCallInitiator; + OutboundCallInitiator *outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator; OWSAssert(outboundCallInitiator); return [outboundCallInitiator initiateCallWithHandle:phoneNumber]; } else if ([userActivity.activityType isEqualToString:@"INStartAudioCallIntent"]) { @@ -722,12 +723,12 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; } } - if ([Environment getCurrent].callService.call != nil) { + if (SignalApp.sharedApp.callService.call != nil) { DDLogWarn(@"%@ ignoring INStartAudioCallIntent due to ongoing WebRTC call.", self.logTag); return NO; } - OutboundCallInitiator *outboundCallInitiator = [Environment getCurrent].outboundCallInitiator; + OutboundCallInitiator *outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator; OWSAssert(outboundCallInitiator); return [outboundCallInitiator initiateCallWithHandle:phoneNumber]; } else { @@ -864,11 +865,11 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // Fetch messages as soon as possible after launching. In particular, when // launching from the background, without this, we end up waiting some extra // seconds before receiving an actionable push notification. - __unused AnyPromise *messagePromise = [[Environment getCurrent].messageFetcherJob run]; + __unused AnyPromise *messagePromise = [SignalApp.sharedApp.messageFetcherJob run]; // This should happen at any launch, background or foreground. __unused AnyPromise *pushTokenpromise = - [OWSSyncPushTokensJob runWithAccountManager:[Environment getCurrent].accountManager + [OWSSyncPushTokensJob runWithAccountManager:SignalApp.sharedApp.accountManager preferences:[Environment preferences]]; } @@ -899,7 +900,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [OWSProfileManager.sharedManager fetchLocalUsersProfile]; [[OWSReadReceiptManager sharedManager] prepareCachedValues]; - [[Environment getCurrent].contactsManager loadLastKnownContactRecipientIds]; + [[Environment current].contactsManager loadLastKnownContactRecipientIds]; } - (void)registrationStateDidChange diff --git a/Signal/src/Models/AccountManager.swift b/Signal/src/Models/AccountManager.swift index a779a56cd..41c0697a2 100644 --- a/Signal/src/Models/AccountManager.swift +++ b/Signal/src/Models/AccountManager.swift @@ -35,7 +35,7 @@ class AccountManager: NSObject { } func register(verificationCode: String) -> Promise { - guard verificationCode.characters.count > 0 else { + guard verificationCode.count > 0 else { let error = OWSErrorWithCodeDescription(.userError, NSLocalizedString("REGISTRATION_ERROR_BLANK_VERIFICATION_CODE", comment: "alert body during registration")) diff --git a/Signal/src/Models/CompareSafetyNumbersActivity.swift b/Signal/src/Models/CompareSafetyNumbersActivity.swift index cc11d1e5d..48eb88b59 100644 --- a/Signal/src/Models/CompareSafetyNumbersActivity.swift +++ b/Signal/src/Models/CompareSafetyNumbersActivity.swift @@ -60,7 +60,7 @@ class CompareSafetyNumbersActivity: UIActivity { defer { activityDidFinish(true) } let pasteboardString = numericOnly(string: UIPasteboard.general.string) - guard (pasteboardString != nil && pasteboardString!.characters.count == 60) else { + guard (pasteboardString != nil && pasteboardString!.count == 60) else { Logger.warn("\(TAG) no valid safety numbers found in pasteboard: \(String(describing: pasteboardString))") let error = OWSErrorWithCodeDescription(OWSErrorCode.userError, NSLocalizedString("PRIVACY_VERIFICATION_FAILED_NO_SAFETY_NUMBERS_IN_CLIPBOARD", comment: "Alert body for user error")) @@ -91,7 +91,7 @@ class CompareSafetyNumbersActivity: UIActivity { var numericOnly: String? if let regex = try? NSRegularExpression(pattern: "\\D", options: .caseInsensitive) { - numericOnly = regex.stringByReplacingMatches(in: string!, options: .withTransparentBounds, range: NSMakeRange(0, string!.characters.count), withTemplate: "") + numericOnly = regex.stringByReplacingMatches(in: string!, options: .withTransparentBounds, range: NSMakeRange(0, string!.count), withTemplate: "") } return numericOnly diff --git a/Signal/src/Models/SignalAttachment.swift b/Signal/src/Models/SignalAttachment.swift index 5fa80144c..3058fdd65 100644 --- a/Signal/src/Models/SignalAttachment.swift +++ b/Signal/src/Models/SignalAttachment.swift @@ -225,7 +225,7 @@ class SignalAttachment: NSObject { if let filename = sourceFilename { let fileExtension = (filename as NSString).pathExtension - if fileExtension.characters.count > 0 { + if fileExtension.count > 0 { if let mimeType = MIMETypeUtil.mimeType(forFileExtension:fileExtension) { // UTI types are an imperfect means of representing file type; // file extensions are also imperfect but far more reliable and @@ -273,7 +273,7 @@ class SignalAttachment: NSObject { var fileExtension: String? { if let filename = sourceFilename { let fileExtension = (filename as NSString).pathExtension - if fileExtension.characters.count > 0 { + if fileExtension.count > 0 { return fileExtension } } @@ -477,7 +477,7 @@ class SignalAttachment: NSObject { // NOTE: The attachment returned by this method may not be valid. // Check the attachment's error property. private class func imageAttachment(dataSource: DataSource?, dataUTI: String) -> SignalAttachment { - assert(dataUTI.characters.count > 0) + assert(dataUTI.count > 0) assert(dataSource != nil) guard let dataSource = dataSource else { @@ -577,7 +577,7 @@ class SignalAttachment: NSObject { // NOTE: The attachment returned by this method may nil or not be valid. // Check the attachment's error property. public class func imageAttachment(image: UIImage?, dataUTI: String, filename: String?) -> SignalAttachment { - assert(dataUTI.characters.count > 0) + assert(dataUTI.count > 0) guard let image = image else { let dataSource = DataSourceValue.emptyDataSource() @@ -779,7 +779,7 @@ class SignalAttachment: NSObject { dataUTI: String, validUTISet: Set?, maxFileSize: UInt) -> SignalAttachment { - assert(dataUTI.characters.count > 0) + assert(dataUTI.count > 0) assert(dataSource != nil) guard let dataSource = dataSource else { diff --git a/Signal/src/Signal-Bridging-Header.h b/Signal/src/Signal-Bridging-Header.h index 375b35647..ce1dcff18 100644 --- a/Signal/src/Signal-Bridging-Header.h +++ b/Signal/src/Signal-Bridging-Header.h @@ -2,13 +2,16 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // +#import +#import + +// Separate iOS Frameworks from other imports. #import "AppSettingsViewController.h" #import "AttachmentSharing.h" #import "ContactTableViewCell.h" #import "ConversationViewItem.h" #import "DateUtil.h" #import "DebugUIPage.h" -#import "Environment.h" #import "FingerprintViewController.h" #import "FullImageViewController.h" #import "HomeViewController.h" @@ -24,15 +27,14 @@ #import "OWSLogger.h" #import "OWSNavigationController.h" #import "OWSPreferences.h" -#import "OWSProfileManager.h" #import "OWSProgressView.h" #import "OWSViewController.h" #import "OWSWebRTCDataProtos.pb.h" #import "PrivacySettingsTableViewController.h" #import "ProfileViewController.h" #import "PushManager.h" -#import "Release.h" #import "RemoteVideoView.h" +#import "SignalApp.h" #import "ThreadUtil.h" #import "UIColor+OWS.h" #import "UIFont+OWS.h" @@ -42,7 +44,6 @@ #import "UIViewController+Permissions.h" #import "ViewControllerUtils.h" #import -#import #import #import #import @@ -51,6 +52,11 @@ #import #import #import +#import +#import +#import +#import +#import #import #import #import diff --git a/Signal/src/UIApplication+OWS.swift b/Signal/src/UIApplication+OWS.swift index 3e00699af..34c1bd2dd 100644 --- a/Signal/src/UIApplication+OWS.swift +++ b/Signal/src/UIApplication+OWS.swift @@ -16,8 +16,11 @@ extension UIApplication { internal func findFrontmostViewController(ignoringAlerts: Bool) -> UIViewController? { let window = UIApplication.shared.keyWindow - var viewController = window!.rootViewController - return viewController.findFrontmostViewController(ignoringAlerts:ignoringAlerts) + guard let viewController = window!.rootViewController else { + owsFail("\(self.logTag) in \(#function) Missing root view controller.") + return nil + } + return viewController.findFrontmostViewController(ignoringAlerts) } func openSystemSettings() { diff --git a/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift b/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift index 235592126..9fa2d9a1e 100644 --- a/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift +++ b/Signal/src/UserInterface/Notifications/CallNotificationsAdapter.swift @@ -22,7 +22,7 @@ class CallNotificationsAdapter: NSObject { // if #available(iOS 10.0, *) { // adaptee = UserNotificationsAdaptee() // } else { - adaptee = Environment.getCurrent().notificationsManager + adaptee = SignalApp.shared().notificationsManager // } } diff --git a/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift b/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift index 764bb8552..7180bbe8f 100644 --- a/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift +++ b/Signal/src/UserInterface/Notifications/UserNotificationsAdaptee.swift @@ -67,7 +67,7 @@ class UserNotificationsAdaptee: NSObject, OWSCallNotificationsAdaptee, UNUserNot private let center: UNUserNotificationCenter var previewType: NotificationType { - return Environment.getCurrent().preferences.notificationPreviewType() + return Environment.current().preferences.notificationPreviewType() } override init() { @@ -115,7 +115,7 @@ class UserNotificationsAdaptee: NSObject, OWSCallNotificationsAdaptee, UNUserNot case .noNameNoPreview: return CallStrings.missedCallNotificationBodyWithoutCallerName case .nameNoPreview, .namePreview: - return (Environment.getCurrent().preferences.isCallKitPrivacyEnabled() + return (Environment.current().preferences.isCallKitPrivacyEnabled() ? CallStrings.missedCallNotificationBodyWithoutCallerName : String(format: CallStrings.missedCallNotificationBodyWithCallerName, callerName)) }}() @@ -141,7 +141,7 @@ class UserNotificationsAdaptee: NSObject, OWSCallNotificationsAdaptee, UNUserNot case .noNameNoPreview: return CallStrings.missedCallWithIdentityChangeNotificationBodyWithoutCallerName case .nameNoPreview, .namePreview: - return (Environment.getCurrent().preferences.isCallKitPrivacyEnabled() + return (Environment.current().preferences.isCallKitPrivacyEnabled() ? CallStrings.missedCallWithIdentityChangeNotificationBodyWithoutCallerName : String(format: CallStrings.missedCallWithIdentityChangeNotificationBodyWithCallerName, callerName)) }}() @@ -167,7 +167,7 @@ class UserNotificationsAdaptee: NSObject, OWSCallNotificationsAdaptee, UNUserNot case .noNameNoPreview: return CallStrings.missedCallWithIdentityChangeNotificationBodyWithoutCallerName case .nameNoPreview, .namePreview: - return (Environment.getCurrent().preferences.isCallKitPrivacyEnabled() + return (Environment.current().preferences.isCallKitPrivacyEnabled() ? CallStrings.missedCallWithIdentityChangeNotificationBodyWithoutCallerName : String(format: CallStrings.missedCallWithIdentityChangeNotificationBodyWithCallerName, callerName)) }}() diff --git a/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m b/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m index c95c184e8..356958ebf 100644 --- a/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m +++ b/Signal/src/ViewControllers/AdvancedSettingsTableViewController.m @@ -240,9 +240,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)syncPushTokens { - OWSSyncPushTokensJob *job = - [[OWSSyncPushTokensJob alloc] initWithAccountManager:[Environment getCurrent].accountManager - preferences:[Environment preferences]]; + OWSSyncPushTokensJob *job = [[OWSSyncPushTokensJob alloc] initWithAccountManager:SignalApp.sharedApp.accountManager + preferences:[Environment preferences]]; job.uploadOnlyIfStale = NO; [job run] .then(^{ diff --git a/Signal/src/ViewControllers/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettingsViewController.m index 8474ccf9a..be92804ef 100644 --- a/Signal/src/ViewControllers/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettingsViewController.m @@ -48,7 +48,7 @@ return self; } - _contactsManager = [Environment getCurrent].contactsManager; + _contactsManager = [Environment current].contactsManager; return self; } @@ -60,7 +60,7 @@ return self; } - _contactsManager = [Environment getCurrent].contactsManager; + _contactsManager = [Environment current].contactsManager; return self; } @@ -381,7 +381,7 @@ canCancel:NO backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) { [TSAccountManager unregisterTextSecureWithSuccess:^{ - [Environment resetAppData]; + [SignalApp resetAppData]; } failure:^(NSError *error) { dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/Signal/src/ViewControllers/CallViewController.swift b/Signal/src/ViewControllers/CallViewController.swift index cf644c722..f170ebb39 100644 --- a/Signal/src/ViewControllers/CallViewController.swift +++ b/Signal/src/ViewControllers/CallViewController.swift @@ -124,8 +124,8 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver { @available(*, unavailable, message: "use init(call:) constructor instead.") required init?(coder aDecoder: NSCoder) { - contactsManager = Environment.getCurrent().contactsManager - callUIAdapter = Environment.getCurrent().callUIAdapter + contactsManager = Environment.current().contactsManager + callUIAdapter = SignalApp.shared().callUIAdapter allAudioSources = Set(callUIAdapter.audioService.availableInputs) self.call = SignalCall.outgoingCall(localId: UUID(), remotePhoneNumber: "+1234567890") self.thread = TSContactThread.getOrCreateThread(contactId: call.remotePhoneNumber) @@ -134,8 +134,8 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver { } required init(call: SignalCall) { - contactsManager = Environment.getCurrent().contactsManager - callUIAdapter = Environment.getCurrent().callUIAdapter + contactsManager = Environment.current().contactsManager + callUIAdapter = SignalApp.shared().callUIAdapter allAudioSources = Set(callUIAdapter.audioService.availableInputs) self.call = call self.thread = TSContactThread.getOrCreateThread(contactId: call.remotePhoneNumber) @@ -200,7 +200,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver { // Subscribe for future call updates call.addObserverAndSyncState(observer: self) - Environment.getCurrent().callService.addObserverAndSyncState(observer: self) + SignalApp.shared().callService.addObserverAndSyncState(observer: self) } // MARK: - Create Views @@ -927,7 +927,7 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver { private func markSettingsNagAsComplete() { Logger.info("\(TAG) called \(#function)") - let preferences = Environment.getCurrent().preferences! + let preferences = Environment.current().preferences! preferences.setIsCallKitEnabled(preferences.isCallKitEnabled()) preferences.setIsCallKitPrivacyEnabled(preferences.isCallKitPrivacyEnabled()) @@ -1008,13 +1008,13 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver { } else if !ignoreNag && call.direction == .incoming && UIDevice.current.supportsCallKit && - (!Environment.getCurrent().preferences.isCallKitEnabled() || - Environment.getCurrent().preferences.isCallKitPrivacyEnabled()) { + (!Environment.current().preferences.isCallKitEnabled() || + Environment.current().preferences.isCallKitPrivacyEnabled()) { isShowingSettingsNag = true // Update the nag view's copy to reflect the settings state. - if Environment.getCurrent().preferences.isCallKitEnabled() { + if Environment.current().preferences.isCallKitEnabled() { settingsNagDescriptionLabel.text = NSLocalizedString("CALL_VIEW_SETTINGS_NAG_DESCRIPTION_PRIVACY", comment: "Reminder to the user of the benefits of disabling CallKit privacy.") } else { @@ -1023,8 +1023,8 @@ class CallViewController: OWSViewController, CallObserver, CallServiceObserver { } settingsNagDescriptionLabel.superview?.setNeedsLayout() - if Environment.getCurrent().preferences.isCallKitEnabledSet() || - Environment.getCurrent().preferences.isCallKitPrivacySet() { + if Environment.current().preferences.isCallKitEnabledSet() || + Environment.current().preferences.isCallKitPrivacySet() { // User has already touched these preferences, only show // the "fleeting" nag, not the "blocking" nag. diff --git a/Signal/src/ViewControllers/CodeVerificationViewController.m b/Signal/src/ViewControllers/CodeVerificationViewController.m index ce25ed6e4..14de0d037 100644 --- a/Signal/src/ViewControllers/CodeVerificationViewController.m +++ b/Signal/src/ViewControllers/CodeVerificationViewController.m @@ -45,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN return self; } - _accountManager = [Environment getCurrent].accountManager; + _accountManager = SignalApp.sharedApp.accountManager; return self; } @@ -57,7 +57,7 @@ NS_ASSUME_NONNULL_BEGIN return self; } - _accountManager = [Environment getCurrent].accountManager; + _accountManager = SignalApp.sharedApp.accountManager; return self; } diff --git a/Signal/src/ViewControllers/ContactsPicker.swift b/Signal/src/ViewControllers/ContactsPicker.swift index ce99a980a..3deb4eb5f 100644 --- a/Signal/src/ViewControllers/ContactsPicker.swift +++ b/Signal/src/ViewControllers/ContactsPicker.swift @@ -109,12 +109,12 @@ open class ContactsPicker: OWSViewController, UITableViewDelegate, UITableViewDa // MARK: - Initializers init() { - contactsManager = Environment.getCurrent().contactsManager + contactsManager = Environment.current().contactsManager super.init(nibName: nil, bundle: nil) } required public init?(coder aDecoder: NSCoder) { - contactsManager = Environment.getCurrent().contactsManager + contactsManager = Environment.current().contactsManager super.init(coder: aDecoder) } @@ -321,7 +321,7 @@ open class ContactsPicker: OWSViewController, UITableViewDelegate, UITableViewDa open func updateSearchResults(searchText: String) { let predicate: NSPredicate - if searchText.characters.count == 0 { + if searchText.count == 0 { filteredSections = sections } else { do { diff --git a/Signal/src/ViewControllers/ContactsViewHelper.m b/Signal/src/ViewControllers/ContactsViewHelper.m index 7fc14b62a..fe24ad0c7 100644 --- a/Signal/src/ViewControllers/ContactsViewHelper.m +++ b/Signal/src/ViewControllers/ContactsViewHelper.m @@ -5,8 +5,8 @@ #import "ContactsViewHelper.h" #import "Environment.h" #import "NSString+OWS.h" -#import "OWSProfileManager.h" #import "Signal-Swift.h" +#import #import #import #import @@ -52,7 +52,7 @@ NS_ASSUME_NONNULL_BEGIN _blockedPhoneNumbers = [_blockingManager blockedPhoneNumbers]; _conversationSearcher = ConversationSearcher.shared; - _contactsManager = [Environment getCurrent].contactsManager; + _contactsManager = [Environment current].contactsManager; _profileManager = [OWSProfileManager sharedManager]; // We don't want to notify the delegate in the `updateContacts`. diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m index 0ef04d653..26d8fa5ea 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSSystemMessageCell.m @@ -193,7 +193,7 @@ NS_ASSUME_NONNULL_BEGIN OWSVerificationStateChangeMessage *message = (OWSVerificationStateChangeMessage *)interaction; BOOL isVerified = message.verificationState == OWSVerificationStateVerified; NSString *displayName = - [[Environment getCurrent].contactsManager displayNameForPhoneIdentifier:message.recipientId]; + [[Environment current].contactsManager displayNameForPhoneIdentifier:message.recipientId]; NSString *titleFormat = (isVerified ? (message.isLocalChange ? NSLocalizedString(@"VERIFICATION_STATE_CHANGE_FORMAT_VERIFIED_LOCAL", diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 297a95003..67a912785 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -263,10 +263,10 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { - (void)commonInit { - _contactsManager = [Environment getCurrent].contactsManager; - _contactsUpdater = [Environment getCurrent].contactsUpdater; - _messageSender = [Environment getCurrent].messageSender; - _outboundCallInitiator = [Environment getCurrent].outboundCallInitiator; + _contactsManager = [Environment current].contactsManager; + _contactsUpdater = [Environment current].contactsUpdater; + _messageSender = [Environment current].messageSender; + _outboundCallInitiator = SignalApp.sharedApp.outboundCallInitiator; _storageManager = [TSStorageManager sharedManager]; _messagesManager = [OWSMessageManager sharedManager]; _networkManager = [TSNetworkManager sharedManager]; diff --git a/Signal/src/ViewControllers/DebugUI/DebugUICalling.swift b/Signal/src/ViewControllers/DebugUI/DebugUICalling.swift index 37148c3b3..0b8875c13 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUICalling.swift +++ b/Signal/src/ViewControllers/DebugUI/DebugUICalling.swift @@ -13,10 +13,10 @@ class DebugUICalling: DebugUIPage { // MARK: Dependencies var notificationsAdapter: CallNotificationsAdapter { - return Environment.getCurrent().callService.notificationsAdapter + return SignalApp.shared().callService.notificationsAdapter } var messageSender: MessageSender { - return Environment.getCurrent().messageSender + return Environment.current().messageSender } // MARK: Overrides diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m index d4cedee0e..633a8cceb 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMessages.m @@ -244,7 +244,7 @@ NS_ASSUME_NONNULL_BEGIN OWSSyncGroupsRequestMessage *syncGroupsRequestMessage = [[OWSSyncGroupsRequestMessage alloc] initWithThread:thread groupId:[Randomness generateRandomBytes:16]]; - [[Environment getCurrent].messageSender enqueueMessage:syncGroupsRequestMessage + [[Environment current].messageSender enqueueMessage:syncGroupsRequestMessage success:^{ DDLogWarn(@"%@ Successfully sent Request Group Info message.", self.logTag); } @@ -292,7 +292,7 @@ NS_ASSUME_NONNULL_BEGIN NSString *randomText = [self randomText]; NSString *text = [[[@(counter) description] stringByAppendingString:@" "] stringByAppendingString:randomText]; - OWSMessageSender *messageSender = [Environment getCurrent].messageSender; + OWSMessageSender *messageSender = [Environment current].messageSender; TSOutgoingMessage *message = [ThreadUtil sendMessageWithText:text inThread:thread messageSender:messageSender]; DDLogError(@"%@ sendTextMessageInThread timestamp: %llu.", self.logTag, message.timestamp); } @@ -312,7 +312,7 @@ NS_ASSUME_NONNULL_BEGIN { NSString *randomText = [[self randomText] substringToIndex:arc4random_uniform(4)]; NSString *text = [[[@(counter) description] stringByAppendingString:@" "] stringByAppendingString:randomText]; - OWSMessageSender *messageSender = [Environment getCurrent].messageSender; + OWSMessageSender *messageSender = [Environment current].messageSender; [ThreadUtil sendMessageWithText:text inThread:thread messageSender:messageSender]; } @@ -373,7 +373,7 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert(filePath); OWSAssert(thread); - OWSMessageSender *messageSender = [Environment getCurrent].messageSender; + OWSMessageSender *messageSender = [Environment current].messageSender; NSString *filename = [filePath lastPathComponent]; NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:filename.pathExtension]; DataSource *_Nullable dataSource = [DataSourcePath dataSourceWithFilePath:filePath]; @@ -624,7 +624,7 @@ NS_ASSUME_NONNULL_BEGIN + (void)sendOversizeTextMessage:(TSThread *)thread { - OWSMessageSender *messageSender = [Environment getCurrent].messageSender; + OWSMessageSender *messageSender = [Environment current].messageSender; NSMutableString *message = [NSMutableString new]; for (int i = 0; i < 32; i++) { [message appendString:@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse rutrum, nulla " @@ -665,7 +665,7 @@ NS_ASSUME_NONNULL_BEGIN + (void)sendRandomAttachment:(TSThread *)thread uti:(NSString *)uti length:(NSUInteger)length { - OWSMessageSender *messageSender = [Environment getCurrent].messageSender; + OWSMessageSender *messageSender = [Environment current].messageSender; DataSource *_Nullable dataSource = [DataSourceValue dataSourceWithData:[self createRandomNSDataOfSize:length] utiType:uti]; SignalAttachment *attachment = [SignalAttachment attachmentWithDataSource:dataSource dataUTI:uti]; @@ -1125,7 +1125,7 @@ NS_ASSUME_NONNULL_BEGIN groupMetaMessage:TSGroupMessageNew]; [message updateWithCustomMessage:NSLocalizedString(@"GROUP_CREATED", nil)]; - OWSMessageSender *messageSender = [Environment getCurrent].messageSender; + OWSMessageSender *messageSender = [Environment current].messageSender; void (^completion)(void) = ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [ThreadUtil sendMessageWithText:[@(counter) description] inThread:thread messageSender:messageSender]; diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m b/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m index 8b7c8b465..74290ee75 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m @@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN { DDLogInfo(@"%@ re-registering.", self.logTag); [[TSAccountManager sharedInstance] resetForRegistration]; - [[Environment getCurrent].preferences unsetRecordedAPNSTokens]; + [[Environment current].preferences unsetRecordedAPNSTokens]; RegistrationViewController *viewController = [RegistrationViewController new]; OWSNavigationController *navigationController = diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIProfile.swift b/Signal/src/ViewControllers/DebugUI/DebugUIProfile.swift index e7a75801b..768269f7a 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIProfile.swift +++ b/Signal/src/ViewControllers/DebugUI/DebugUIProfile.swift @@ -13,7 +13,7 @@ class DebugUIProfile: DebugUIPage { // MARK: Dependencies var messageSender: MessageSender { - return Environment.getCurrent().messageSender + return Environment.current().messageSender } var profileManager: OWSProfileManager { return OWSProfileManager.shared() diff --git a/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m b/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m index 13604d19c..df792d91f 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m @@ -74,10 +74,9 @@ NS_ASSUME_NONNULL_BEGIN }], [OWSTableItem itemWithTitle:@"Send session reset" actionBlock:^{ - [OWSSessionResetJob - runWithContactThread:thread - messageSender:[Environment getCurrent].messageSender - storageManager:[TSStorageManager sharedManager]]; + [OWSSessionResetJob runWithContactThread:thread + messageSender:[Environment current].messageSender + storageManager:[TSStorageManager sharedManager]]; }] ]]; } diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIStress.m b/Signal/src/ViewControllers/DebugUI/DebugUIStress.m index 3e7f40549..25125c4fd 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIStress.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIStress.m @@ -436,8 +436,8 @@ NS_ASSUME_NONNULL_BEGIN + (void)sendStressMessage:(TSOutgoingMessage *)message { OWSAssert(message); - - OWSMessageSender *messageSender = [Environment getCurrent].messageSender; + + OWSMessageSender *messageSender = [Environment current].messageSender; [messageSender enqueueMessage:message success:^{ DDLogInfo(@"%@ Successfully sent message.", self.logTag); diff --git a/Signal/src/ViewControllers/DebugUI/DebugUISyncMessages.m b/Signal/src/ViewControllers/DebugUI/DebugUISyncMessages.m index b55efe54f..f5d3918f4 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUISyncMessages.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUISyncMessages.m @@ -8,9 +8,9 @@ #import "OWSTableViewController.h" #import "Signal-Swift.h" #import "ThreadUtil.h" -#import #import #import +#import #import #import #import @@ -66,12 +66,12 @@ NS_ASSUME_NONNULL_BEGIN + (OWSMessageSender *)messageSender { - return [Environment getCurrent].messageSender; + return [Environment current].messageSender; } + (OWSContactsManager *)contactsManager { - return [Environment getCurrent].contactsManager; + return [Environment current].contactsManager; } + (OWSIdentityManager *)identityManager diff --git a/Signal/src/ViewControllers/FingerprintViewController.m b/Signal/src/ViewControllers/FingerprintViewController.m index 15302b7c2..0b1c7c0a0 100644 --- a/Signal/src/ViewControllers/FingerprintViewController.m +++ b/Signal/src/ViewControllers/FingerprintViewController.m @@ -144,7 +144,7 @@ typedef void (^CustomLayoutBlock)(void); self.recipientId = recipientId; - OWSContactsManager *contactsManager = [Environment getCurrent].contactsManager; + OWSContactsManager *contactsManager = [Environment current].contactsManager; self.contactName = [contactsManager displayNameForPhoneIdentifier:recipientId]; OWSRecipientIdentity *_Nullable recipientIdentity = diff --git a/Signal/src/ViewControllers/FingerprintViewScanController.m b/Signal/src/ViewControllers/FingerprintViewScanController.m index e106224b6..8be8b9259 100644 --- a/Signal/src/ViewControllers/FingerprintViewScanController.m +++ b/Signal/src/ViewControllers/FingerprintViewScanController.m @@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN self.recipientId = recipientId; self.accountManager = [TSAccountManager sharedInstance]; - OWSContactsManager *contactsManager = [Environment getCurrent].contactsManager; + OWSContactsManager *contactsManager = [Environment current].contactsManager; self.contactName = [contactsManager displayNameForPhoneIdentifier:recipientId]; OWSRecipientIdentity *_Nullable recipientIdentity = diff --git a/Signal/src/ViewControllers/HomeViewController.m b/Signal/src/ViewControllers/HomeViewController.m index 6cb698425..5a734109e 100644 --- a/Signal/src/ViewControllers/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeViewController.m @@ -13,6 +13,7 @@ #import "ProfileViewController.h" #import "PushManager.h" #import "Signal-Swift.h" +#import "SignalApp.h" #import "TSAccountManager.h" #import "TSDatabaseView.h" #import "TSGroupThread.h" @@ -104,10 +105,10 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; - (void)commonInit { - _accountManager = [Environment getCurrent].accountManager; - _contactsManager = [Environment getCurrent].contactsManager; + _accountManager = SignalApp.sharedApp.accountManager; + _contactsManager = [Environment current].contactsManager; _messagesManager = [OWSMessageManager sharedManager]; - _messageSender = [Environment getCurrent].messageSender; + _messageSender = [Environment current].messageSender; _blockingManager = [OWSBlockingManager sharedManager]; _blockedPhoneNumberSet = [NSSet setWithArray:[_blockingManager blockedPhoneNumbers]]; @@ -175,7 +176,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; self.view.backgroundColor = [UIColor whiteColor]; // TODO: Remove this. - [[Environment getCurrent] setHomeViewController:self]; + [SignalApp.sharedApp setHomeViewController:self]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose @@ -628,7 +629,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; { OWSAssert([NSThread isMainThread]); DDLogInfo(@"%@ beggining refreshing.", self.logTag); - [[Environment getCurrent].messageFetcherJob run].always(^{ + [SignalApp.sharedApp.messageFetcherJob run].always(^{ DDLogInfo(@"%@ ending refreshing.", self.logTag); [refreshControl endRefreshing]; }); diff --git a/Signal/src/ViewControllers/MediaMessageView.swift b/Signal/src/ViewControllers/MediaMessageView.swift index a4e5a8e36..682dfef00 100644 --- a/Signal/src/ViewControllers/MediaMessageView.swift +++ b/Signal/src/ViewControllers/MediaMessageView.swift @@ -315,7 +315,7 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { return nil } let filename = sourceFilename.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) - guard filename.characters.count > 0 else { + guard filename.count > 0 else { return nil } return filename @@ -342,7 +342,7 @@ class MediaMessageView: UIView, OWSAudioAttachmentPlayerDelegate { let fileSize = attachment.dataLength label.text = String(format: NSLocalizedString("ATTACHMENT_APPROVAL_FILE_SIZE_FORMAT", comment: "Format string for file size label in call interstitial view. Embeds: {{file size as 'N mb' or 'N kb'}}."), - ViewControllerUtils.formatFileSize(UInt(fileSize))) + OWSFormat.formatFileSize(UInt(fileSize))) label.textColor = UIColor.ows_materialBlue() label.font = labelFont() diff --git a/Signal/src/ViewControllers/MessageDetailViewController.swift b/Signal/src/ViewControllers/MessageDetailViewController.swift index 4a307615d..001aed64e 100644 --- a/Signal/src/ViewControllers/MessageDetailViewController.swift +++ b/Signal/src/ViewControllers/MessageDetailViewController.swift @@ -56,7 +56,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate { } required init(viewItem: ConversationViewItem, message: TSMessage, mode: MessageMetadataViewMode) { - self.contactsManager = Environment.getCurrent().contactsManager + self.contactsManager = Environment.current().contactsManager self.viewItem = viewItem self.message = message self.mode = mode @@ -182,7 +182,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate { } var rows = [UIView]() - let contactsManager = Environment.getCurrent().contactsManager! + let contactsManager = Environment.current().contactsManager! let thread = message.thread // Content @@ -314,7 +314,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate { return nil } let messageBody = displayableText.fullText - guard messageBody.characters.count > 0 else { + guard messageBody.count > 0 else { return nil } return messageBody @@ -466,7 +466,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate { let fileSize = dataSource.dataLength() rows.append(valueRow(name: NSLocalizedString("MESSAGE_METADATA_VIEW_ATTACHMENT_FILE_SIZE", comment: "Label for file size of attachments in the 'message metadata' view."), - value: ViewControllerUtils.formatFileSize(UInt(fileSize)))) + value: OWSFormat.formatFileSize(UInt(fileSize)))) } return rows @@ -502,7 +502,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate { nameLabel.autoPinEdge(toSuperviewEdge: .top) valueLabel.autoPinEdge(toSuperviewEdge: .top) - if subtitle.characters.count > 0 { + if subtitle.count > 0 { let subtitleLabel = self.valueLabel(text: subtitle) subtitleLabel.textColor = UIColor.ows_darkGray() row.addSubview(subtitleLabel) @@ -510,7 +510,7 @@ class MessageDetailViewController: OWSViewController, UIScrollViewDelegate { subtitleLabel.autoPinLeading(toTrailingOf: nameLabel, margin: 10) subtitleLabel.autoPinEdge(.top, to: .bottom, of: valueLabel, withOffset: 1) subtitleLabel.autoPinEdge(toSuperviewEdge: .bottom) - } else if value.characters.count > 0 { + } else if value.count > 0 { valueLabel.autoPinEdge(toSuperviewEdge: .bottom) } else { nameLabel.autoPinEdge(toSuperviewEdge: .bottom) diff --git a/Signal/src/ViewControllers/NewContactThreadViewController.m b/Signal/src/ViewControllers/NewContactThreadViewController.m index 1b176dde5..2dc9a219c 100644 --- a/Signal/src/ViewControllers/NewContactThreadViewController.m +++ b/Signal/src/ViewControllers/NewContactThreadViewController.m @@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)stringForCollation { - OWSContactsManager *contactsManager = [Environment getCurrent].contactsManager; + OWSContactsManager *contactsManager = [Environment current].contactsManager; return [contactsManager comparableNameForSignalAccount:self]; } diff --git a/Signal/src/ViewControllers/NewGroupViewController.m b/Signal/src/ViewControllers/NewGroupViewController.m index 66a445b28..6ade586db 100644 --- a/Signal/src/ViewControllers/NewGroupViewController.m +++ b/Signal/src/ViewControllers/NewGroupViewController.m @@ -86,7 +86,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; - (void)commonInit { - _messageSender = [Environment getCurrent].messageSender; + _messageSender = [Environment current].messageSender; _contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self]; _avatarViewHelper = [AvatarViewHelper new]; _avatarViewHelper.delegate = self; diff --git a/Signal/src/ViewControllers/OWSAddToContactViewController.m b/Signal/src/ViewControllers/OWSAddToContactViewController.m index 7e2ed3c40..3f6acc38d 100644 --- a/Signal/src/ViewControllers/OWSAddToContactViewController.m +++ b/Signal/src/ViewControllers/OWSAddToContactViewController.m @@ -63,7 +63,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)commonInit { - _contactsManager = [Environment getCurrent].contactsManager; + _contactsManager = [Environment current].contactsManager; _contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self]; } diff --git a/Signal/src/ViewControllers/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/OWSConversationSettingsViewController.m index 8da25bb3c..2be9265ec 100644 --- a/Signal/src/ViewControllers/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/OWSConversationSettingsViewController.m @@ -11,7 +11,6 @@ #import "OWSAvatarBuilder.h" #import "OWSBlockingManager.h" #import "OWSContactsManager.h" -#import "OWSProfileManager.h" #import "PhoneNumber.h" #import "ShowGroupMembersViewController.h" #import "Signal-Swift.h" @@ -20,6 +19,7 @@ #import "UIView+OWS.h" #import "UpdateGroupViewController.h" #import +#import #import #import #import @@ -94,8 +94,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)commonInit { _accountManager = [TSAccountManager sharedInstance]; - _contactsManager = [Environment getCurrent].contactsManager; - _messageSender = [Environment getCurrent].messageSender; + _contactsManager = [Environment current].contactsManager; + _messageSender = [Environment current].messageSender; _blockingManager = [OWSBlockingManager sharedManager]; _contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self]; diff --git a/Signal/src/ViewControllers/OWSLinkDeviceViewController.m b/Signal/src/ViewControllers/OWSLinkDeviceViewController.m index 81385f76e..471823d7a 100644 --- a/Signal/src/ViewControllers/OWSLinkDeviceViewController.m +++ b/Signal/src/ViewControllers/OWSLinkDeviceViewController.m @@ -6,8 +6,8 @@ #import "Cryptography.h" #import "OWSDeviceProvisioningURLParser.h" #import "OWSLinkedDevicesTableViewController.h" -#import "OWSProfileManager.h" #import "Signal-Swift.h" +#import #import #import #import diff --git a/Signal/src/ViewControllers/PrivacySettingsTableViewController.m b/Signal/src/ViewControllers/PrivacySettingsTableViewController.m index e949be7d4..c27491fa2 100644 --- a/Signal/src/ViewControllers/PrivacySettingsTableViewController.m +++ b/Signal/src/ViewControllers/PrivacySettingsTableViewController.m @@ -164,15 +164,15 @@ NS_ASSUME_NONNULL_BEGIN - (void)didToggleEnableCallKitSwitch:(UISwitch *)sender { DDLogInfo(@"%@ user toggled call kit preference: %@", self.logTag, (sender.isOn ? @"ON" : @"OFF")); - [[Environment getCurrent].preferences setIsCallKitEnabled:sender.isOn]; + [[Environment current].preferences setIsCallKitEnabled:sender.isOn]; // rebuild callUIAdapter since CallKit vs not changed. - [[Environment getCurrent].callService createCallUIAdapter]; + [SignalApp.sharedApp.callService createCallUIAdapter]; [self updateTableContents]; } - (void)didToggleEnableCallKitPrivacySwitch:(UISwitch *)sender { DDLogInfo(@"%@ user toggled call kit privacy preference: %@", self.logTag, (sender.isOn ? @"ON" : @"OFF")); - [[Environment getCurrent].preferences setIsCallKitPrivacyEnabled:!sender.isOn]; + [[Environment current].preferences setIsCallKitPrivacyEnabled:!sender.isOn]; } #pragma mark - Log util diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 026c54186..9d25acc0f 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -8,13 +8,13 @@ #import "HomeViewController.h" #import "NSString+OWS.h" #import "OWSNavigationController.h" -#import "OWSProfileManager.h" #import "Signal-Swift.h" #import "SignalsNavigationController.h" #import "UIColor+OWS.h" #import "UIFont+OWS.h" #import "UIView+OWS.h" #import "UIViewController+OWS.h" +#import #import #import diff --git a/Signal/src/ViewControllers/RegistrationViewController.m b/Signal/src/ViewControllers/RegistrationViewController.m index 3ac304cfd..ceba79316 100644 --- a/Signal/src/ViewControllers/RegistrationViewController.m +++ b/Signal/src/ViewControllers/RegistrationViewController.m @@ -50,7 +50,7 @@ NSString *const kKeychainKey_LastRegisteredPhoneNumber = @"kKeychainKey_LastRegi // Do any additional setup after loading the view. [self populateDefaultCountryNameAndCode]; - [[Environment getCurrent] setSignUpFlowNavigationController:self.navigationController]; + [[Environment current] setSignUpFlowNavigationController:self.navigationController]; } - (void)viewDidLoad { diff --git a/Signal/src/ViewControllers/SendExternalFileViewController.m b/Signal/src/ViewControllers/SendExternalFileViewController.m index b6b152fd2..ac0b96e2d 100644 --- a/Signal/src/ViewControllers/SendExternalFileViewController.m +++ b/Signal/src/ViewControllers/SendExternalFileViewController.m @@ -38,8 +38,8 @@ NS_ASSUME_NONNULL_BEGIN { [super loadView]; - _contactsManager = [Environment getCurrent].contactsManager; - _messageSender = [Environment getCurrent].messageSender; + _contactsManager = [Environment current].contactsManager; + _messageSender = [Environment current].messageSender; self.title = NSLocalizedString(@"SEND_EXTERNAL_FILE_VIEW_TITLE", @"Title for the 'send external file' view."); } diff --git a/Signal/src/ViewControllers/UpdateGroupViewController.m b/Signal/src/ViewControllers/UpdateGroupViewController.m index fb5c9cb97..42dea3041 100644 --- a/Signal/src/ViewControllers/UpdateGroupViewController.m +++ b/Signal/src/ViewControllers/UpdateGroupViewController.m @@ -84,7 +84,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)commonInit { - _messageSender = [Environment getCurrent].messageSender; + _messageSender = [Environment current].messageSender; _contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self]; _avatarViewHelper = [AvatarViewHelper new]; _avatarViewHelper.delegate = self; diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index dca545bf8..205b5d219 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -304,7 +304,7 @@ protocol CallServiceObserver: class { throw CallError.assertionError(description: errorDescription) } - let useTurnOnly = Environment.getCurrent().preferences.doCallsHideIPAddress() + let useTurnOnly = Environment.current().preferences.doCallsHideIPAddress() let peerConnectionClient = PeerConnectionClient(iceServers: iceServers, delegate: self, callDirection: .outgoing, useTurnOnly: useTurnOnly) Logger.debug("\(self.TAG) setting peerConnectionClient in \(#function) for call: \(call.identifiersForLogs)") @@ -609,7 +609,7 @@ protocol CallServiceObserver: class { // a TURN connection, so as not to reveal any connectivity information (IP/port) to the caller. let unknownCaller = self.contactsManager.signalAccount(forRecipientId: thread.contactIdentifier()) == nil - let useTurnOnly = unknownCaller || Environment.getCurrent().preferences.doCallsHideIPAddress() + let useTurnOnly = unknownCaller || Environment.current().preferences.doCallsHideIPAddress() Logger.debug("\(self.TAG) setting peerConnectionClient in \(#function) for: \(newCall.identifiersForLogs)") let peerConnectionClient = PeerConnectionClient(iceServers: iceServers, delegate: self, callDirection: .incoming, useTurnOnly: useTurnOnly) diff --git a/Signal/src/call/OutboundCallInitiator.swift b/Signal/src/call/OutboundCallInitiator.swift index c51a72565..2bca5a7d0 100644 --- a/Signal/src/call/OutboundCallInitiator.swift +++ b/Signal/src/call/OutboundCallInitiator.swift @@ -42,7 +42,7 @@ import SignalMessaging public func initiateCall(recipientId: String) -> Bool { // Rather than an init-assigned dependency property, we access `callUIAdapter` via Environment // because it can change after app launch due to user settings - guard let callUIAdapter = Environment.getCurrent().callUIAdapter else { + guard let callUIAdapter = SignalApp.shared().callUIAdapter else { owsFail("\(TAG) can't initiate call because callUIAdapter is nil") return false } diff --git a/Signal/src/call/PeerConnectionClient.swift b/Signal/src/call/PeerConnectionClient.swift index 1ddc6e83c..367409db0 100644 --- a/Signal/src/call/PeerConnectionClient.swift +++ b/Signal/src/call/PeerConnectionClient.swift @@ -794,12 +794,12 @@ class HardenedRTCSessionDescription { // Enforce Constant bit rate. let cbrRegex = try! NSRegularExpression(pattern:"(a=fmtp:111 ((?!cbr=).)*)\r?\n", options:.caseInsensitive) - description = cbrRegex.stringByReplacingMatches(in: description, options: [], range: NSMakeRange(0, description.characters.count), withTemplate: "$1;cbr=1\r\n") + description = cbrRegex.stringByReplacingMatches(in: description, options: [], range: NSMakeRange(0, description.count), withTemplate: "$1;cbr=1\r\n") // Strip plaintext audio-level details // https://tools.ietf.org/html/rfc6464 let audioLevelRegex = try! NSRegularExpression(pattern:".+urn:ietf:params:rtp-hdrext:ssrc-audio-level.*\r?\n", options:.caseInsensitive) - description = audioLevelRegex.stringByReplacingMatches(in: description, options: [], range: NSMakeRange(0, description.characters.count), withTemplate: "") + description = audioLevelRegex.stringByReplacingMatches(in: description, options: [], range: NSMakeRange(0, description.count), withTemplate: "") return RTCSessionDescription.init(type: rtcSessionDescription.type, sdp: description) } diff --git a/Signal/src/call/Speakerbox/CallKitCallManager.swift b/Signal/src/call/Speakerbox/CallKitCallManager.swift index 3c91e18f5..b44fc931d 100644 --- a/Signal/src/call/Speakerbox/CallKitCallManager.swift +++ b/Signal/src/call/Speakerbox/CallKitCallManager.swift @@ -25,7 +25,7 @@ final class CallKitCallManager: NSObject { func startCall(_ call: SignalCall) { var handle: CXHandle - if Environment.getCurrent().preferences.isCallKitPrivacyEnabled() { + if Environment.current().preferences.isCallKitPrivacyEnabled() { let callKitId = CallKitCallManager.kAnonymousCallHandlePrefix + call.localId.uuidString handle = CXHandle(type: .generic, value: callKitId) TSStorageManager.shared().setPhoneNumber(call.remotePhoneNumber, forCallKitId:callKitId) diff --git a/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift b/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift index 2562c1366..73da4b39f 100644 --- a/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift +++ b/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift @@ -103,7 +103,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate { // Construct a CXCallUpdate describing the incoming call, including the caller. let update = CXCallUpdate() - if Environment.getCurrent().preferences.isCallKitPrivacyEnabled() { + if Environment.current().preferences.isCallKitPrivacyEnabled() { let callKitId = CallKitCallManager.kAnonymousCallHandlePrefix + call.localId.uuidString update.remoteHandle = CXHandle(type: .generic, value: callKitId) TSStorageManager.shared().setPhoneNumber(call.remotePhoneNumber, forCallKitId:callKitId) @@ -245,7 +245,7 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate { action.fulfill() self.provider.reportOutgoingCall(with: call.localId, startedConnectingAt: nil) - if Environment.getCurrent().preferences.isCallKitPrivacyEnabled() { + if Environment.current().preferences.isCallKitPrivacyEnabled() { // Update the name used in the CallKit UI for outgoing calls. let update = CXCallUpdate() update.localizedCallerName = NSLocalizedString("CALLKIT_ANONYMOUS_CONTACT_NAME", diff --git a/Signal/src/call/UserInterface/CallUIAdapter.swift b/Signal/src/call/UserInterface/CallUIAdapter.swift index 560041591..352bc79e1 100644 --- a/Signal/src/call/UserInterface/CallUIAdapter.swift +++ b/Signal/src/call/UserInterface/CallUIAdapter.swift @@ -39,7 +39,7 @@ extension CallUIAdaptee { let callViewController = CallViewController(call: call) callViewController.modalTransitionStyle = .crossDissolve - guard let presentingViewController = Environment.getCurrent().homeViewController else { + guard let presentingViewController = UIApplication.shared.frontmostViewControllerIgnoringAlerts else { owsFail("in \(#function) view controller unexpectedly nil") return } @@ -91,7 +91,7 @@ extension CallUIAdaptee { // So we use the non-CallKit call UI. Logger.info("\(TAG) choosing non-callkit adaptee for simulator.") adaptee = NonCallKitCallUIAdaptee(callService: callService, notificationsAdapter: notificationsAdapter) - } else if #available(iOS 10.0, *), Environment.getCurrent().preferences.isCallKitEnabled() { + } else if #available(iOS 10.0, *), Environment.current().preferences.isCallKitEnabled() { Logger.info("\(TAG) choosing callkit adaptee for iOS10+") adaptee = CallKitCallUIAdaptee(callService: callService, contactsManager: contactsManager, notificationsAdapter: notificationsAdapter) } else { diff --git a/Signal/src/environment/Migrations/OWS106EnsureProfileComplete.swift b/Signal/src/environment/Migrations/OWS106EnsureProfileComplete.swift index 0099420c7..d0b252e8f 100644 --- a/Signal/src/environment/Migrations/OWS106EnsureProfileComplete.swift +++ b/Signal/src/environment/Migrations/OWS106EnsureProfileComplete.swift @@ -90,7 +90,7 @@ class OWS106EnsureProfileComplete: OWSDatabaseMigration { let (promise, fulfill, reject) = Promise.pending() - guard let networkManager = Environment.getCurrent().networkManager else { + guard let networkManager = Environment.current().networkManager else { owsFail("\(TAG) network manager was unexpectedly not set") return Promise(error: OWSErrorMakeAssertionError()) } diff --git a/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.m b/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.m index 8dc01a374..d391294a7 100644 --- a/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.m +++ b/Signal/src/environment/Migrations/OWSDatabaseMigrationRunner.m @@ -3,6 +3,7 @@ // #import "OWSDatabaseMigrationRunner.h" +#import "OWS104CreateRecipientIdentities.h" #import "OWSDatabaseMigration.h" #import "Signal-Swift.h" #import diff --git a/Signal/src/environment/NotificationsManager.m b/Signal/src/environment/NotificationsManager.m index 4025d1187..13fe9ad76 100644 --- a/Signal/src/environment/NotificationsManager.m +++ b/Signal/src/environment/NotificationsManager.m @@ -116,9 +116,9 @@ NSString *const kNotificationsManagerNewMesssageSoundName = @"NewMessage.aifc"; case NotificationNameNoPreview: case NotificationNamePreview: { alertMessage = (([UIDevice currentDevice].supportsCallKit && - [[Environment getCurrent].preferences isCallKitPrivacyEnabled]) - ? [CallStrings missedCallNotificationBodyWithoutCallerName] - : [NSString stringWithFormat:[CallStrings missedCallNotificationBodyWithCallerName], callerName]); + [[Environment current].preferences isCallKitPrivacyEnabled]) + ? [CallStrings missedCallNotificationBodyWithoutCallerName] + : [NSString stringWithFormat:[CallStrings missedCallNotificationBodyWithCallerName], callerName]); break; } } @@ -155,7 +155,7 @@ NSString *const kNotificationsManagerNewMesssageSoundName = @"NewMessage.aifc"; case NotificationNameNoPreview: case NotificationNamePreview: { alertMessage = (([UIDevice currentDevice].supportsCallKit && - [[Environment getCurrent].preferences isCallKitPrivacyEnabled]) + [[Environment current].preferences isCallKitPrivacyEnabled]) ? [CallStrings missedCallWithIdentityChangeNotificationBodyWithoutCallerName] : [NSString stringWithFormat:[CallStrings missedCallWithIdentityChangeNotificationBodyWithCallerName], @@ -195,7 +195,7 @@ NSString *const kNotificationsManagerNewMesssageSoundName = @"NewMessage.aifc"; case NotificationNameNoPreview: case NotificationNamePreview: { alertMessage = (([UIDevice currentDevice].supportsCallKit && - [[Environment getCurrent].preferences isCallKitPrivacyEnabled]) + [[Environment current].preferences isCallKitPrivacyEnabled]) ? [CallStrings missedCallWithIdentityChangeNotificationBodyWithoutCallerName] : [NSString stringWithFormat:[CallStrings missedCallWithIdentityChangeNotificationBodyWithCallerName], @@ -387,7 +387,7 @@ NSString *const kNotificationsManagerNewMesssageSoundName = @"NewMessage.aifc"; - (NotificationType)notificationPreviewType { - OWSPreferences *prefs = [Environment getCurrent].preferences; + OWSPreferences *prefs = [Environment current].preferences; return prefs.notificationPreviewType; } diff --git a/Signal/src/environment/SignalApp.h b/Signal/src/environment/SignalApp.h index 1ed86e9a9..d83cfc44b 100644 --- a/Signal/src/environment/SignalApp.h +++ b/Signal/src/environment/SignalApp.h @@ -14,7 +14,9 @@ @interface SignalApp : NSObject -@property (nonatomic) HomeViewController *homeViewController; +@property (nonatomic, weak) HomeViewController *homeViewController; + +// TODO: Convert to singletons? @property (nonatomic, readonly) OWSWebRTCCallMessageHandler *callMessageHandler; @property (nonatomic, readonly) CallService *callService; @property (nonatomic, readonly) CallUIAdapter *callUIAdapter; diff --git a/Signal/src/environment/SignalApp.m b/Signal/src/environment/SignalApp.m index 1f583c8b2..acd786008 100644 --- a/Signal/src/environment/SignalApp.m +++ b/Signal/src/environment/SignalApp.m @@ -6,6 +6,8 @@ #import "ConversationViewController.h" #import "HomeViewController.h" #import "Signal-Swift.h" +#import +#import #import #import #import @@ -56,9 +58,10 @@ @synchronized(self) { if (!_callMessageHandler) { - _callMessageHandler = [[OWSWebRTCCallMessageHandler alloc] initWithAccountManager:self.accountManager - callService:self.callService - messageSender:self.messageSender]; + _callMessageHandler = + [[OWSWebRTCCallMessageHandler alloc] initWithAccountManager:self.accountManager + callService:self.callService + messageSender:Environment.current.messageSender]; } } @@ -71,11 +74,11 @@ { if (!_callService) { OWSAssert(self.accountManager); - OWSAssert(self.contactsManager); - OWSAssert(self.messageSender); + OWSAssert(Environment.current.contactsManager); + OWSAssert(Environment.current.messageSender); _callService = [[CallService alloc] initWithAccountManager:self.accountManager - contactsManager:self.contactsManager - messageSender:self.messageSender + contactsManager:Environment.current.contactsManager + messageSender:Environment.current.messageSender notificationsAdapter:[OWSCallNotificationsAdapter new]]; } } @@ -93,10 +96,11 @@ @synchronized(self) { if (!_outboundCallInitiator) { - OWSAssert(self.contactsManager); - OWSAssert(self.contactsUpdater); - _outboundCallInitiator = [[OutboundCallInitiator alloc] initWithContactsManager:self.contactsManager - contactsUpdater:self.contactsUpdater]; + OWSAssert(Environment.current.contactsManager); + OWSAssert(Environment.current.contactsUpdater); + _outboundCallInitiator = + [[OutboundCallInitiator alloc] initWithContactsManager:Environment.current.contactsManager + contactsUpdater:Environment.current.contactsUpdater]; } } @@ -110,7 +114,7 @@ if (!_messageFetcherJob) { _messageFetcherJob = [[OWSMessageFetcherJob alloc] initWithMessageReceiver:[OWSMessageReceiver sharedInstance] - networkManager:self.networkManager + networkManager:Environment.current.networkManager signalService:[OWSSignalService sharedInstance]]; } } @@ -135,7 +139,7 @@ { if (!_accountManager) { _accountManager = [[AccountManager alloc] initWithTextSecureAccountManager:[TSAccountManager sharedInstance] - preferences:self.preferences]; + preferences:Environment.current.preferences]; } } diff --git a/Signal/src/environment/VersionMigrations.m b/Signal/src/environment/VersionMigrations.m index ebf2caf29..423ce5afd 100644 --- a/Signal/src/environment/VersionMigrations.m +++ b/Signal/src/environment/VersionMigrations.m @@ -31,7 +31,7 @@ { // performUpdateCheck must be invoked after Environment has been initialized because // upgrade process may depend on Environment. - OWSAssert([Environment getCurrent]); + OWSAssert([Environment current]); NSString *previousVersion = AppVersion.instance.lastAppVersion; NSString *currentVersion = AppVersion.instance.currentAppVersion; diff --git a/Signal/src/network/GiphyAPI.swift b/Signal/src/network/GiphyAPI.swift index 09f295a3f..dbcb09b17 100644 --- a/Signal/src/network/GiphyAPI.swift +++ b/Signal/src/network/GiphyAPI.swift @@ -375,7 +375,7 @@ extension GiphyError: LocalizedError { Logger.warn("\(TAG) Image dict missing id.") return nil } - guard giphyId.characters.count > 0 else { + guard giphyId.count > 0 else { Logger.warn("\(TAG) Image dict has invalid id.") return nil } @@ -433,7 +433,7 @@ extension GiphyError: LocalizedError { guard let urlString = renditionDict["url"] as? String else { return nil } - guard urlString.characters.count > 0 else { + guard urlString.count > 0 else { Logger.warn("\(TAG) Rendition has invalid url.") return nil } diff --git a/Signal/src/network/PushManager.m b/Signal/src/network/PushManager.m index a259d1d5a..d8f7b61c3 100644 --- a/Signal/src/network/PushManager.m +++ b/Signal/src/network/PushManager.m @@ -54,11 +54,11 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe - (instancetype)initDefault { - return [self initWithMessageFetcherJob:[Environment getCurrent].messageFetcherJob + return [self initWithMessageFetcherJob:SignalApp.sharedApp.messageFetcherJob storageManager:[TSStorageManager sharedManager] - callUIAdapter:[Environment getCurrent].callService.callUIAdapter - messageSender:[Environment getCurrent].messageSender - notificationsManager:[Environment getCurrent].notificationsManager]; + callUIAdapter:SignalApp.sharedApp.callService.callUIAdapter + messageSender:[Environment current].messageSender + notificationsManager:SignalApp.sharedApp.notificationsManager]; } - (instancetype)initWithMessageFetcherJob:(OWSMessageFetcherJob *)messageFetcherJob @@ -276,7 +276,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe [thread markAllAsReadWithTransaction:transaction]; } completionBlock:^{ - [[[Environment getCurrent] homeViewController] updateInboxCountLabel]; + [SignalApp.sharedApp.homeViewController updateInboxCountLabel]; [self cancelNotificationsWithThreadId:threadId]; completionHandler(); diff --git a/Signal/src/util/DisplayableText.swift b/Signal/src/util/DisplayableText.swift index 2d12ebd49..a0120a6a1 100644 --- a/Signal/src/util/DisplayableText.swift +++ b/Signal/src/util/DisplayableText.swift @@ -185,7 +185,7 @@ extension String { if string == "" { return 0 } - if string.characters.count > Int(kMaxJumbomojiCount * kMaxCharactersPerEmojiCount) { + if string.count > Int(kMaxJumbomojiCount * kMaxCharactersPerEmojiCount) { return 0 } guard string.containsOnlyEmoji else { diff --git a/Signal/src/util/MainAppContext.m b/Signal/src/util/MainAppContext.m index eccf1e995..68ae19818 100644 --- a/Signal/src/util/MainAppContext.m +++ b/Signal/src/util/MainAppContext.m @@ -6,9 +6,11 @@ #import "OWS100RemoveTSRecipientsMigration.h" #import "OWS102MoveLoggingPreferenceToUserDefaults.h" #import "OWS103EnableVideoCalling.h" -#import "OWS104CreateRecipientIdentities.h" #import "OWS105AttachmentFilePaths.h" #import "Signal-Swift.h" +#import +#import +#import NS_ASSUME_NONNULL_BEGIN @@ -53,13 +55,14 @@ NS_ASSUME_NONNULL_BEGIN - (NSArray *)allMigrations { + TSStorageManager *storageManager = TSStorageManager.sharedManager; return @[ - [[OWS100RemoveTSRecipientsMigration alloc] initWithStorageManager:self.storageManager], - [[OWS102MoveLoggingPreferenceToUserDefaults alloc] initWithStorageManager:self.storageManager], - [[OWS103EnableVideoCalling alloc] initWithStorageManager:self.storageManager], + [[OWS100RemoveTSRecipientsMigration alloc] initWithStorageManager:storageManager], + [[OWS102MoveLoggingPreferenceToUserDefaults alloc] initWithStorageManager:storageManager], + [[OWS103EnableVideoCalling alloc] initWithStorageManager:storageManager], // OWS104CreateRecipientIdentities is run separately. See runSafeBlockingMigrations. - [[OWS105AttachmentFilePaths alloc] initWithStorageManager:self.storageManager], - [[OWS106EnsureProfileComplete alloc] initWithStorageManager:self.storageManager] + [[OWS105AttachmentFilePaths alloc] initWithStorageManager:storageManager], + [[OWS106EnsureProfileComplete alloc] initWithStorageManager:storageManager] ]; } @@ -73,6 +76,16 @@ NS_ASSUME_NONNULL_BEGIN [UIApplication.sharedApplication openSystemSettings]; } +- (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey +{ + OWSAssert(profileKey); + + [MultiDeviceProfileKeyUpdateJob runWithProfileKey:profileKey + identityManager:OWSIdentityManager.sharedManager + messageSender:Environment.current.messageSender + profileManager:OWSProfileManager.sharedManager]; +} + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/util/OWSContactsSyncing.m b/Signal/src/util/OWSContactsSyncing.m index 4f778ccd5..78a489281 100644 --- a/Signal/src/util/OWSContactsSyncing.m +++ b/Signal/src/util/OWSContactsSyncing.m @@ -4,8 +4,8 @@ #import "OWSContactsSyncing.h" #import "OWSContactsManager.h" -#import "OWSProfileManager.h" #import "TSAccountManager.h" +#import #import #import #import diff --git a/Signal/src/util/TextFieldHelper.swift b/Signal/src/util/TextFieldHelper.swift index 6819aff95..e58572c58 100644 --- a/Signal/src/util/TextFieldHelper.swift +++ b/Signal/src/util/TextFieldHelper.swift @@ -29,7 +29,7 @@ import UIKit } // Don't allow any change if inserting a single char is already over the limit (typically this means typing) - if (replacementString.characters.count < 2) { + if (replacementString.count < 2) { return false } diff --git a/Signal/src/util/ThreadUtil.m b/Signal/src/util/ThreadUtil.m index 048e03a86..8e41f5887 100644 --- a/Signal/src/util/ThreadUtil.m +++ b/Signal/src/util/ThreadUtil.m @@ -5,9 +5,9 @@ #import "ThreadUtil.h" #import "OWSContactOffersInteraction.h" #import "OWSContactsManager.h" -#import "OWSProfileManager.h" #import "Signal-Swift.h" #import "TSUnreadIndicatorInteraction.h" +#import #import #import #import diff --git a/SignalMessaging/SignalMessaging.h b/SignalMessaging/SignalMessaging.h index 27b71fe4a..20d378835 100644 --- a/SignalMessaging/SignalMessaging.h +++ b/SignalMessaging/SignalMessaging.h @@ -11,7 +11,11 @@ FOUNDATION_EXPORT double SignalMessagingVersionNumber; FOUNDATION_EXPORT const unsigned char SignalMessagingVersionString[]; // The public headers of the framework +#import #import #import +#import #import +#import #import +#import diff --git a/SignalMessaging/environment/Environment.h b/SignalMessaging/environment/Environment.h index c29daaf93..db61340f9 100644 --- a/SignalMessaging/environment/Environment.h +++ b/SignalMessaging/environment/Environment.h @@ -36,8 +36,8 @@ @property (nonatomic, readonly, weak) UINavigationController *signUpFlowNavigationController; -+ (Environment *)getCurrent; -+ (void)setCurrent:(Environment *)curEnvironment; ++ (Environment *)current; ++ (void)setCurrent:(Environment *)environment; + (OWSPreferences *)preferences; diff --git a/SignalMessaging/environment/Environment.m b/SignalMessaging/environment/Environment.m index 5e030103a..aa82d96d5 100644 --- a/SignalMessaging/environment/Environment.m +++ b/SignalMessaging/environment/Environment.m @@ -12,7 +12,7 @@ #import #import -static Environment *environment = nil; +static Environment *sharedEnvironment = nil; @interface Environment () @@ -22,6 +22,7 @@ static Environment *environment = nil; @property (nonatomic) OWSMessageSender *messageSender; @property (nonatomic) OWSPreferences *preferences; +// TODO: Move to SignalApp. @property (nonatomic, weak) UINavigationController *signUpFlowNavigationController; @end @@ -30,15 +31,19 @@ static Environment *environment = nil; @implementation Environment -+ (Environment *)getCurrent ++ (Environment *)current { - NSAssert((environment != nil), @"Environment is not defined."); - return environment; + OWSAssert(sharedEnvironment); + + return sharedEnvironment; } -+ (void)setCurrent:(Environment *)curEnvironment ++ (void)setCurrent:(Environment *)environment { - environment = curEnvironment; + OWSAssert(!sharedEnvironment); + OWSAssert(environment); + + sharedEnvironment = environment; } - (instancetype)initWithContactsManager:(OWSContactsManager *)contactsManager @@ -91,12 +96,12 @@ static Environment *environment = nil; + (OWSPreferences *)preferences { - OWSAssert([Environment getCurrent]); - OWSAssert([Environment getCurrent].preferences); + OWSAssert([Environment current].preferences); - return [Environment getCurrent].preferences; + return [Environment current].preferences; } +// TODO: Convert to singleton? - (OWSPreferences *)preferences { @synchronized(self) diff --git a/SignalMessaging/environment/Release.h b/SignalMessaging/environment/Release.h index 531003768..e95d22a79 100644 --- a/SignalMessaging/environment/Release.h +++ b/SignalMessaging/environment/Release.h @@ -2,7 +2,7 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import "Environment.h" +@class Environment; @interface Release : NSObject diff --git a/SignalMessaging/environment/Release.m b/SignalMessaging/environment/Release.m index f0beab21f..9daae7734 100644 --- a/SignalMessaging/environment/Release.m +++ b/SignalMessaging/environment/Release.m @@ -3,6 +3,7 @@ // #import "Release.h" +#import "Environment.h" #import "NotificationsManager.h" #import "OWSContactsManager.h" #import diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index b5948f0b5..908e1d4eb 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -8,7 +8,9 @@ #import "UIImage+OWS.h" #import #import +#import #import +#import #import #import #import @@ -21,6 +23,7 @@ #import #import #import +#import #import #import #import @@ -154,8 +157,8 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; - (instancetype)initDefault { TSStorageManager *storageManager = [TSStorageManager sharedManager]; - OWSMessageSender *messageSender = [Environment getCurrent].messageSender; - TSNetworkManager *networkManager = [Environment getCurrent].networkManager; + OWSMessageSender *messageSender = [Environment current].messageSender; + TSNetworkManager *networkManager = [Environment current].networkManager; return [self initWithStorageManager:storageManager messageSender:messageSender networkManager:networkManager]; } @@ -262,10 +265,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; // we have a registered account, syncing will fail (and there could not be any // linked device to sync to at this point anyway). if ([TSAccountManager isRegistered]) { - [MultiDeviceProfileKeyUpdateJob runWithProfileKey:userProfile.profileKey - identityManager:self.identityManager - messageSender:self.messageSender - profileManager:self]; + [CurrentAppContext() doMultiDeviceUpdateWithProfileKey:userProfile.profileKey]; } [[NSNotificationCenter defaultCenter] diff --git a/SignalMessaging/profiles/ProfileFetcherJob.swift b/SignalMessaging/profiles/ProfileFetcherJob.swift index 770edae07..8b4f9e0e1 100644 --- a/SignalMessaging/profiles/ProfileFetcherJob.swift +++ b/SignalMessaging/profiles/ProfileFetcherJob.swift @@ -19,15 +19,17 @@ public class ProfileFetcherJob: NSObject { let ignoreThrottling: Bool + @objc public class func run(thread: TSThread, networkManager: TSNetworkManager) { ProfileFetcherJob(networkManager: networkManager).run(recipientIds: thread.recipientIdentifiers) } + @objc public class func run(recipientId: String, networkManager: TSNetworkManager, ignoreThrottling: Bool) { ProfileFetcherJob(networkManager: networkManager, ignoreThrottling:ignoreThrottling).run(recipientIds: [recipientId]) } - init(networkManager: TSNetworkManager, ignoreThrottling: Bool = false) { + public init(networkManager: TSNetworkManager, ignoreThrottling: Bool = false) { self.networkManager = networkManager self.storageManager = TSStorageManager.shared() self.ignoreThrottling = ignoreThrottling @@ -137,7 +139,7 @@ public class ProfileFetcherJob: NSObject { public class SignalServiceProfile: NSObject { let TAG = "[SignalServiceProfile]" - enum ValidationError: Error { + public enum ValidationError: Error { case invalid(description: String) case invalidIdentityKey(description: String) case invalidProfileName(description: String) diff --git a/SignalMessaging/utils/WeakTimer.swift b/SignalMessaging/utils/WeakTimer.swift index 094d56d2c..073cdba86 100644 --- a/SignalMessaging/utils/WeakTimer.swift +++ b/SignalMessaging/utils/WeakTimer.swift @@ -9,7 +9,7 @@ * Solution modified from * http://stackoverflow.com/questions/16821736/weak-reference-to-nstimer-target-to-prevent-retain-cycle/41003985#41003985 */ -final class WeakTimer { +public final class WeakTimer { fileprivate weak var timer: Timer? fileprivate weak var target: AnyObject? @@ -25,7 +25,7 @@ final class WeakTimer { repeats: repeats) } - class func scheduledTimer(timeInterval: TimeInterval, target: AnyObject, userInfo: Any?, repeats: Bool, action: @escaping (Timer) -> Void) -> Timer { + public class func scheduledTimer(timeInterval: TimeInterval, target: AnyObject, userInfo: Any?, repeats: Bool, action: @escaping (Timer) -> Void) -> Timer { return WeakTimer(timeInterval: timeInterval, target: target, userInfo: userInfo, diff --git a/SignalMessaging/views/CommonStrings.swift b/SignalMessaging/views/CommonStrings.swift index 4624f5bc0..99d546b9c 100644 --- a/SignalMessaging/views/CommonStrings.swift +++ b/SignalMessaging/views/CommonStrings.swift @@ -8,40 +8,55 @@ import Foundation * Strings re-used in multiple places should be added here. */ -@objc class CommonStrings: NSObject { - static let dismissButton = NSLocalizedString("DISMISS_BUTTON_TEXT", comment: "Short text to dismiss current modal / actionsheet / screen") - static let cancelButton = NSLocalizedString("TXT_CANCEL_TITLE", comment:"Label for the cancel button in an alert or action sheet.") - static let retryButton = NSLocalizedString("RETRY_BUTTON_TEXT", comment:"Generic text for button that retries whatever the last action was.") +@objc public class CommonStrings: NSObject { + @objc + static public let dismissButton = NSLocalizedString("DISMISS_BUTTON_TEXT", comment: "Short text to dismiss current modal / actionsheet / screen") + @objc + static public let cancelButton = NSLocalizedString("TXT_CANCEL_TITLE", comment:"Label for the cancel button in an alert or action sheet.") + @objc + static public let retryButton = NSLocalizedString("RETRY_BUTTON_TEXT", comment:"Generic text for button that retries whatever the last action was.") } -@objc class MessageStrings: NSObject { - static let newGroupDefaultTitle = NSLocalizedString("NEW_GROUP_DEFAULT_TITLE", comment: "Used in place of the group name when a group has not yet been named.") +@objc public class MessageStrings: NSObject { + @objc + static public let newGroupDefaultTitle = NSLocalizedString("NEW_GROUP_DEFAULT_TITLE", comment: "Used in place of the group name when a group has not yet been named.") } -@objc class CallStrings: NSObject { +@objc public class CallStrings: NSObject { + @objc + static public let callStatusFormat = NSLocalizedString("CALL_STATUS_FORMAT", comment: "embeds {{Call Status}} in call screen label. For ongoing calls, {{Call Status}} is a seconds timer like 01:23, otherwise {{Call Status}} is a short text like 'Ringing', 'Busy', or 'Failed Call'") - static let callStatusFormat = NSLocalizedString("CALL_STATUS_FORMAT", comment: "embeds {{Call Status}} in call screen label. For ongoing calls, {{Call Status}} is a seconds timer like 01:23, otherwise {{Call Status}} is a short text like 'Ringing', 'Busy', or 'Failed Call'") + @objc + static public let confirmAndCallButtonTitle = NSLocalizedString("SAFETY_NUMBER_CHANGED_CONFIRM_CALL_ACTION", comment: "alert button text to confirm placing an outgoing call after the recipients Safety Number has changed.") - static let confirmAndCallButtonTitle = NSLocalizedString("SAFETY_NUMBER_CHANGED_CONFIRM_CALL_ACTION", comment: "alert button text to confirm placing an outgoing call after the recipients Safety Number has changed.") - - static let callBackAlertTitle = NSLocalizedString("CALL_USER_ALERT_TITLE", comment: "Title for alert offering to call a user.") - static let callBackAlertMessageFormat = NSLocalizedString("CALL_USER_ALERT_MESSAGE_FORMAT", comment: "Message format for alert offering to call a user. Embeds {{the user's display name or phone number}}.") - static let callBackAlertCallButton = NSLocalizedString("CALL_USER_ALERT_CALL_BUTTON", comment: "Label for call button for alert offering to call a user.") + @objc + static public let callBackAlertTitle = NSLocalizedString("CALL_USER_ALERT_TITLE", comment: "Title for alert offering to call a user.") + @objc + static public let callBackAlertMessageFormat = NSLocalizedString("CALL_USER_ALERT_MESSAGE_FORMAT", comment: "Message format for alert offering to call a user. Embeds {{the user's display name or phone number}}.") + @objc + static public let callBackAlertCallButton = NSLocalizedString("CALL_USER_ALERT_CALL_BUTTON", comment: "Label for call button for alert offering to call a user.") // MARK: Notification actions - static let callBackButtonTitle = NSLocalizedString("CALLBACK_BUTTON_TITLE", comment: "notification action") - static let showThreadButtonTitle = NSLocalizedString("SHOW_THREAD_BUTTON_TITLE", comment: "notification action") + @objc + static public let callBackButtonTitle = NSLocalizedString("CALLBACK_BUTTON_TITLE", comment: "notification action") + @objc + static public let showThreadButtonTitle = NSLocalizedString("SHOW_THREAD_BUTTON_TITLE", comment: "notification action") // MARK: Missed Call Notification - static let missedCallNotificationBodyWithoutCallerName = NSLocalizedString("MISSED_CALL", comment: "notification title") - static let missedCallNotificationBodyWithCallerName = NSLocalizedString("MSGVIEW_MISSED_CALL_WITH_NAME", comment: "notification title. Embeds {{caller's name or phone number}}") + @objc + static public let missedCallNotificationBodyWithoutCallerName = NSLocalizedString("MISSED_CALL", comment: "notification title") + @objc + static public let missedCallNotificationBodyWithCallerName = NSLocalizedString("MSGVIEW_MISSED_CALL_WITH_NAME", comment: "notification title. Embeds {{caller's name or phone number}}") // MARK: Missed with changed identity notification (for not previously verified identity) - static let missedCallWithIdentityChangeNotificationBodyWithoutCallerName = NSLocalizedString("MISSED_CALL_WITH_CHANGED_IDENTITY_BODY_WITHOUT_CALLER_NAME", comment: "notification title") - static let missedCallWithIdentityChangeNotificationBodyWithCallerName = NSLocalizedString("MISSED_CALL_WITH_CHANGED_IDENTITY_BODY_WITH_CALLER_NAME", comment: "notification title. Embeds {{caller's name or phone number}}") + @objc + static public let missedCallWithIdentityChangeNotificationBodyWithoutCallerName = NSLocalizedString("MISSED_CALL_WITH_CHANGED_IDENTITY_BODY_WITHOUT_CALLER_NAME", comment: "notification title") + @objc + static public let missedCallWithIdentityChangeNotificationBodyWithCallerName = NSLocalizedString("MISSED_CALL_WITH_CHANGED_IDENTITY_BODY_WITH_CALLER_NAME", comment: "notification title. Embeds {{caller's name or phone number}}") } -@objc class SafetyNumberStrings: NSObject { - static let confirmSendButton = NSLocalizedString("SAFETY_NUMBER_CHANGED_CONFIRM_SEND_ACTION", +@objc public class SafetyNumberStrings: NSObject { + @objc + static public let confirmSendButton = NSLocalizedString("SAFETY_NUMBER_CHANGED_CONFIRM_SEND_ACTION", comment: "button title to confirm sending to a recipient whose safety number recently changed") } diff --git a/SignalMessaging/views/OWSAlerts.swift b/SignalMessaging/views/OWSAlerts.swift index 9bf94e289..cb12ea4b9 100644 --- a/SignalMessaging/views/OWSAlerts.swift +++ b/SignalMessaging/views/OWSAlerts.swift @@ -4,10 +4,11 @@ import Foundation -@objc class OWSAlerts: NSObject { +@objc public class OWSAlerts: NSObject { let TAG = "[OWSAlerts]" /// Cleanup and present alert for no permissions + @objc public class func showNoMicrophonePermissionAlert() { let alertTitle = NSLocalizedString("CALL_AUDIO_PERMISSION_TITLE", comment:"Alert title when calling and permissions for microphone are missing") let alertMessage = NSLocalizedString("CALL_AUDIO_PERMISSION_MESSAGE", comment:"Alert message when calling and permissions for microphone are missing") @@ -22,16 +23,19 @@ import Foundation CurrentAppContext().frontmostViewController()?.present(alertController, animated: true, completion: nil) } + @objc public class func showAlert(withTitle title: String) { self.showAlert(withTitle: title, message: nil, buttonTitle: nil) } + @objc public class func showAlert(withTitle title: String, message: String) { self.showAlert(withTitle: title, message: message, buttonTitle: nil) } + @objc public class func showAlert(withTitle title: String, message: String? = nil, buttonTitle: String? = nil) { - assert(title.characters.count > 0) + assert(title.count > 0) let actionTitle = buttonTitle ?? NSLocalizedString("OK", comment: "") @@ -40,8 +44,9 @@ import Foundation CurrentAppContext().frontmostViewController()?.present(alert, animated: true, completion: nil) } + @objc public class func showConfirmationAlert(withTitle title: String, message: String? = nil, proceedTitle: String? = nil, proceedAction: @escaping (UIAlertAction) -> Void) { - assert(title.characters.count > 0) + assert(title.count > 0) let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) alert.addAction(self.cancelAction) @@ -52,6 +57,7 @@ import Foundation CurrentAppContext().frontmostViewController()?.present(alert, animated: true, completion: nil) } + @objc public class var cancelAction: UIAlertAction { let action = UIAlertAction(title: CommonStrings.cancelButton, style: .cancel) { _ in Logger.debug("Cancel item") diff --git a/SignalServiceKit/src/Util/AppContext.h b/SignalServiceKit/src/Util/AppContext.h index 8b94a4111..9abd2c4e2 100755 --- a/SignalServiceKit/src/Util/AppContext.h +++ b/SignalServiceKit/src/Util/AppContext.h @@ -6,6 +6,7 @@ NS_ASSUME_NONNULL_BEGIN typedef void (^BackgroundTaskExpirationHandler)(void); +@class OWSAES256Key; @class OWSDatabaseMigration; @protocol AppContext @@ -38,6 +39,10 @@ typedef void (^BackgroundTaskExpirationHandler)(void); // Should only be called if isMainApp is YES. - (void)openSystemSettings; +// Should only be called if isMainApp is YES, +// but should only be necessary to call if isMainApp is YES. +- (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey; + @end id CurrentAppContext(void); diff --git a/SignalShareExtension/ShareViewController.swift b/SignalShareExtension/ShareViewController.swift index ccf57b58f..57592451a 100644 --- a/SignalShareExtension/ShareViewController.swift +++ b/SignalShareExtension/ShareViewController.swift @@ -14,7 +14,7 @@ class ShareViewController: UINavigationController, SAELoadViewDelegate { super.loadView() // This should be the first thing we do. - SetCurrentAppContext(ShareAppExtensionContext(with:self)) + SetCurrentAppContext(ShareAppExtensionContext(rootViewController:self)) DebugLogger.shared().enableTTYLogging() if _isDebugAssertConfiguration() { @@ -38,9 +38,9 @@ class ShareViewController: UINavigationController, SAELoadViewDelegate { // // // // This block will be cleared in databaseViewRegistrationComplete. // [DeviceSleepManager.sharedInstance addBlockWithBlockObject:self]; -// -// [self setupEnvironment]; -// + + setupEnvironment() + // [UIUtil applySignalAppearence]; // // if (getenv("runningTests_dontStartApp")) { @@ -67,9 +67,9 @@ class ShareViewController: UINavigationController, SAELoadViewDelegate { // // [self prepareScreenProtection]; // -// self.contactsSyncing = [[OWSContactsSyncing alloc] initWithContactsManager:[Environment getCurrent].contactsManager +// self.contactsSyncing = [[OWSContactsSyncing alloc] initWithContactsManager:[Environment current].contactsManager // identityManager:[OWSIdentityManager sharedManager] -// messageSender:[Environment getCurrent].messageSender +// messageSender:[Environment current].messageSender // profileManager:[OWSProfileManager sharedManager]]; // // [[NSNotificationCenter defaultCenter] addObserver:self @@ -119,23 +119,24 @@ class ShareViewController: UINavigationController, SAELoadViewDelegate { } func setupEnvironment() { - [Environment setCurrent:[Release releaseEnvironment]] + Environment.setCurrent(Release.releaseEnvironment()) + // TODO: // // Encryption/Descryption mutates session state and must be synchronized on a serial queue. // [SessionCipher setSessionCipherDispatchQueue:[OWSDispatch sessionStoreQueue]]; // // TextSecureKitEnv *sharedEnv = -// [[TextSecureKitEnv alloc] initWithCallMessageHandler:[Environment getCurrent].callMessageHandler -// contactsManager:[Environment getCurrent].contactsManager -// messageSender:[Environment getCurrent].messageSender -// notificationsManager:[Environment getCurrent].notificationsManager +// [[TextSecureKitEnv alloc] initWithCallMessageHandler:SignalApp.sharedApp.callMessageHandler +// contactsManager:[Environment current].contactsManager +// messageSender:[Environment current].messageSender +// notificationsManager:SignalApp.sharedApp.notificationsManager // profileManager:OWSProfileManager.sharedManager]; // [TextSecureKitEnv setSharedEnv:sharedEnv]; // // [[TSStorageManager sharedManager] setupDatabaseWithSafeBlockingMigrations:^{ // [VersionMigrations runSafeBlockingMigrations]; // }]; -// [[Environment getCurrent].contactsManager startObserving]; +// [[Environment current].contactsManager startObserving]; } // MARK: View Lifecycle diff --git a/SignalShareExtension/SignalShareExtension-Bridging-Header.h b/SignalShareExtension/SignalShareExtension-Bridging-Header.h index a37721728..e929e3e8c 100644 --- a/SignalShareExtension/SignalShareExtension-Bridging-Header.h +++ b/SignalShareExtension/SignalShareExtension-Bridging-Header.h @@ -2,17 +2,24 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // +#import +#import + +// Separate iOS Frameworks from other imports. #import "DebugLogger.h" +#import "Environment.h" #import "OWSLogger.h" +#import "OWSMath.h" +#import "OWSPreferences.h" +#import "Release.h" #import "ShareAppExtensionContext.h" #import "UIColor+OWS.h" #import "UIFont+OWS.h" #import "UIView+OWS.h" -#import -#import -#import + +//#import +//#import #import #import #import #import -#import diff --git a/SignalShareExtension/utils/ShareAppExtensionContext.m b/SignalShareExtension/utils/ShareAppExtensionContext.m index c6797b858..ffd47f4d0 100644 --- a/SignalShareExtension/utils/ShareAppExtensionContext.m +++ b/SignalShareExtension/utils/ShareAppExtensionContext.m @@ -92,6 +92,11 @@ NS_ASSUME_NONNULL_BEGIN OWSFail(@"%@ called %s.", self.logTag, __PRETTY_FUNCTION__); } +- (void)doMultiDeviceUpdateWithProfileKey:(OWSAES256Key *)profileKey +{ + OWSFail(@"%@ called %s.", self.logTag, __PRETTY_FUNCTION__); +} + @end NS_ASSUME_NONNULL_END