Migrate environment to SignalMessaging.

This commit is contained in:
Matthew Chen 2017-12-04 10:35:47 -05:00
parent a16058e477
commit b4e8df79da
72 changed files with 318 additions and 244 deletions

View File

@ -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 = "<group>"; };
45855F361D9498A40084F340 /* OWSContactAvatarBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSContactAvatarBuilder.m; sourceTree = "<group>"; };
4585C4651ED5DF7A00896AEA /* ProfileFetcherJob.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProfileFetcherJob.swift; sourceTree = "<group>"; };
4585C4671ED8F8D200896AEA /* SafetyNumberConfirmationAlert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SafetyNumberConfirmationAlert.swift; sourceTree = "<group>"; };
4589670F1DC117CC00E9DD21 /* SignalTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SignalTests-Bridging-Header.h"; sourceTree = "<group>"; };
458967101DC117CC00E9DD21 /* AccountManagerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AccountManagerTest.swift; path = Models/AccountManagerTest.swift; sourceTree = "<group>"; };
@ -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 */,

View File

@ -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 <AxolotlKit/SessionCipher.h>
#import <SignalMessaging/OWSMath.h>
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalMessaging/SignalMessaging.h>
#import <SignalServiceKit/NSUserDefaults+OWS.h>
#import <SignalServiceKit/OWSBatchMessageProcessor.h>
@ -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

View File

@ -35,7 +35,7 @@ class AccountManager: NSObject {
}
func register(verificationCode: String) -> Promise<Void> {
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"))

View File

@ -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

View File

@ -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<String>?,
maxFileSize: UInt) -> SignalAttachment {
assert(dataUTI.characters.count > 0)
assert(dataUTI.count > 0)
assert(dataSource != nil)
guard let dataSource = dataSource else {

View File

@ -2,13 +2,16 @@
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
// 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 <AxolotlKit/NSData+keyVersionByte.h>
#import <Foundation/Foundation.h>
#import <JSQMessagesViewController/JSQMediaItem.h>
#import <JSQMessagesViewController/JSQMessagesBubbleImage.h>
#import <JSQMessagesViewController/JSQMessagesBubbleImageFactory.h>
@ -51,6 +52,11 @@
#import <JSQSystemSoundPlayer/JSQSystemSoundPlayer.h>
#import <PureLayout/PureLayout.h>
#import <Reachability/Reachability.h>
#import <SignalMessaging/Environment.h>
#import <SignalMessaging/OWSFormat.h>
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalMessaging/Release.h>
#import <SignalMessaging/UIViewController+OWS.h>
#import <SignalServiceKit/AppVersion.h>
#import <SignalServiceKit/Asserts.h>
#import <SignalServiceKit/Contact.h>

View File

@ -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() {

View File

@ -22,7 +22,7 @@ class CallNotificationsAdapter: NSObject {
// if #available(iOS 10.0, *) {
// adaptee = UserNotificationsAdaptee()
// } else {
adaptee = Environment.getCurrent().notificationsManager
adaptee = SignalApp.shared().notificationsManager
// }
}

View File

@ -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))
}}()

View File

@ -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(^{

View File

@ -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(), ^{

View File

@ -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.

View File

@ -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;
}

View File

@ -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 {

View File

@ -5,8 +5,8 @@
#import "ContactsViewHelper.h"
#import "Environment.h"
#import "NSString+OWS.h"
#import "OWSProfileManager.h"
#import "Signal-Swift.h"
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalServiceKit/Contact.h>
#import <SignalServiceKit/OWSBlockingManager.h>
#import <SignalServiceKit/PhoneNumber.h>
@ -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`.

View File

@ -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",

View File

@ -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];

View File

@ -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

View File

@ -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];

View File

@ -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 =

View File

@ -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()

View File

@ -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]];
}]
]];
}

View File

@ -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);

View File

@ -8,9 +8,9 @@
#import "OWSTableViewController.h"
#import "Signal-Swift.h"
#import "ThreadUtil.h"
#import <Curve25519Kit/Randomness.h>
#import <AFNetworking/AFNetworking.h>
#import <AxolotlKit/PreKeyBundle.h>
#import <Curve25519Kit/Randomness.h>
#import <SignalServiceKit/OWSBatchMessageProcessor.h>
#import <SignalServiceKit/OWSBlockingManager.h>
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
@ -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

View File

@ -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 =

View File

@ -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 =

View File

@ -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];
});

View File

@ -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()

View File

@ -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)

View File

@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
- (NSString *)stringForCollation
{
OWSContactsManager *contactsManager = [Environment getCurrent].contactsManager;
OWSContactsManager *contactsManager = [Environment current].contactsManager;
return [contactsManager comparableNameForSignalAccount:self];
}

View File

@ -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;

View File

@ -63,7 +63,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)commonInit
{
_contactsManager = [Environment getCurrent].contactsManager;
_contactsManager = [Environment current].contactsManager;
_contactsViewHelper = [[ContactsViewHelper alloc] initWithDelegate:self];
}

View File

@ -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 <Curve25519Kit/Curve25519.h>
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalServiceKit/NSDate+OWS.h>
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
@ -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];

View File

@ -6,8 +6,8 @@
#import "Cryptography.h"
#import "OWSDeviceProvisioningURLParser.h"
#import "OWSLinkedDevicesTableViewController.h"
#import "OWSProfileManager.h"
#import "Signal-Swift.h"
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalServiceKit/ECKeyPair+OWSPrivateKey.h>
#import <SignalServiceKit/OWSDevice.h>
#import <SignalServiceKit/OWSDeviceProvisioner.h>

View File

@ -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

View File

@ -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 <SignalMessaging/OWSProfileManager.h>
#import <SignalServiceKit/NSDate+OWS.h>
#import <SignalServiceKit/TSStorageManager.h>

View File

@ -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 {

View File

@ -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.");
}

View File

@ -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;

View File

@ -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)

View File

@ -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
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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",

View File

@ -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 {

View File

@ -90,7 +90,7 @@ class OWS106EnsureProfileComplete: OWSDatabaseMigration {
let (promise, fulfill, reject) = Promise<Void>.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())
}

View File

@ -3,6 +3,7 @@
//
#import "OWSDatabaseMigrationRunner.h"
#import "OWS104CreateRecipientIdentities.h"
#import "OWSDatabaseMigration.h"
#import "Signal-Swift.h"
#import <SignalServiceKit/AppContext.h>

View File

@ -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;
}

View File

@ -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;

View File

@ -6,6 +6,8 @@
#import "ConversationViewController.h"
#import "HomeViewController.h"
#import "Signal-Swift.h"
#import <SignalMessaging/DebugLogger.h>
#import <SignalMessaging/Environment.h>
#import <SignalServiceKit/TSContactThread.h>
#import <SignalServiceKit/TSGroupThread.h>
#import <SignalServiceKit/TSStorageManager.h>
@ -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];
}
}

View File

@ -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;

View File

@ -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
}

View File

@ -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();

View File

@ -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 {

View File

@ -6,9 +6,11 @@
#import "OWS100RemoveTSRecipientsMigration.h"
#import "OWS102MoveLoggingPreferenceToUserDefaults.h"
#import "OWS103EnableVideoCalling.h"
#import "OWS104CreateRecipientIdentities.h"
#import "OWS105AttachmentFilePaths.h"
#import "Signal-Swift.h"
#import <SignalMessaging/Environment.h>
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalServiceKit/OWSIdentityManager.h>
NS_ASSUME_NONNULL_BEGIN
@ -53,13 +55,14 @@ NS_ASSUME_NONNULL_BEGIN
- (NSArray<OWSDatabaseMigration *> *)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

View File

@ -4,8 +4,8 @@
#import "OWSContactsSyncing.h"
#import "OWSContactsManager.h"
#import "OWSProfileManager.h"
#import "TSAccountManager.h"
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalServiceKit/DataSource.h>
#import <SignalServiceKit/MIMETypeUtil.h>
#import <SignalServiceKit/OWSMessageSender.h>

View File

@ -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
}

View File

@ -5,9 +5,9 @@
#import "ThreadUtil.h"
#import "OWSContactOffersInteraction.h"
#import "OWSContactsManager.h"
#import "OWSProfileManager.h"
#import "Signal-Swift.h"
#import "TSUnreadIndicatorInteraction.h"
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalServiceKit/NSDate+OWS.h>
#import <SignalServiceKit/OWSAddToContactsOfferMessage.h>
#import <SignalServiceKit/OWSAddToProfileWhitelistOfferMessage.h>

View File

@ -11,7 +11,11 @@ FOUNDATION_EXPORT double SignalMessagingVersionNumber;
FOUNDATION_EXPORT const unsigned char SignalMessagingVersionString[];
// The public headers of the framework
#import <SignalMessaging/DebugLogger.h>
#import <SignalMessaging/Environment.h>
#import <SignalMessaging/OWSDatabaseMigration.h>
#import <SignalMessaging/OWSFormat.h>
#import <SignalMessaging/OWSLogger.h>
#import <SignalMessaging/OWSMath.h>
#import <SignalMessaging/OWSProfileManager.h>
#import <SignalMessaging/Rel.h>

View File

@ -36,8 +36,8 @@
@property (nonatomic, readonly, weak) UINavigationController *signUpFlowNavigationController;
+ (Environment *)getCurrent;
+ (void)setCurrent:(Environment *)curEnvironment;
+ (Environment *)current;
+ (void)setCurrent:(Environment *)environment;
+ (OWSPreferences *)preferences;

View File

@ -12,7 +12,7 @@
#import <SignalServiceKit/TSGroupThread.h>
#import <SignalServiceKit/Threading.h>
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)

View File

@ -2,7 +2,7 @@
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "Environment.h"
@class Environment;
@interface Release : NSObject

View File

@ -3,6 +3,7 @@
//
#import "Release.h"
#import "Environment.h"
#import "NotificationsManager.h"
#import "OWSContactsManager.h"
#import <SignalServiceKit/ContactsUpdater.h>

View File

@ -8,7 +8,9 @@
#import "UIImage+OWS.h"
#import <AFNetworking/AFNetworking.h>
#import <SignalMessaging/SignalMessaging-Swift.h>
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/Cryptography.h>
#import <SignalServiceKit/MIMETypeUtil.h>
#import <SignalServiceKit/NSData+Image.h>
#import <SignalServiceKit/NSData+hexString.h>
#import <SignalServiceKit/NSDate+OWS.h>
@ -21,6 +23,7 @@
#import <SignalServiceKit/SecurityUtils.h>
#import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSGroupThread.h>
#import <SignalServiceKit/TSNetworkManager.h>
#import <SignalServiceKit/TSProfileAvatarUploadFormRequest.h>
#import <SignalServiceKit/TSStorageManager.h>
#import <SignalServiceKit/TSThread.h>
@ -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]

View File

@ -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)

View File

@ -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,

View File

@ -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")
}

View File

@ -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")

View File

@ -6,6 +6,7 @@ NS_ASSUME_NONNULL_BEGIN
typedef void (^BackgroundTaskExpirationHandler)(void);
@class OWSAES256Key;
@class OWSDatabaseMigration;
@protocol AppContext <NSObject>
@ -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<AppContext> CurrentAppContext(void);

View File

@ -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

View File

@ -2,17 +2,24 @@
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
// 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 <Foundation/Foundation.h>
#import <SignalMessaging/OWSMath.h>
#import <SignalMessaging/OWSPreferences.h>
//#import <SignalMessaging/OWSMath.h>
//#import <SignalMessaging/OWSPreferences.h>
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/AppVersion.h>
#import <SignalServiceKit/Asserts.h>
#import <SignalServiceKit/NSObject+OWS.h>
#import <UIKit/UIKit.h>

View File

@ -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