Merge branch 'charlesmchen/singletonAgain'

pull/1/head
Matthew Chen 7 years ago
commit d5aa72a228

@ -50,46 +50,18 @@ import SignalMessaging
public var pushRegistrationManager: PushRegistrationManager
@objc
public init(callMessageHandler: WebRTCCallMessageHandler,
callService: CallService,
outboundCallInitiator: OutboundCallInitiator,
messageFetcherJob: MessageFetcherJob,
notificationsManager: NotificationsManager,
accountManager: AccountManager,
callNotificationsAdapter: CallNotificationsAdapter,
pushRegistrationManager: PushRegistrationManager) {
self.callMessageHandler = callMessageHandler
self.callService = callService
self.outboundCallInitiator = outboundCallInitiator
self.messageFetcherJob = messageFetcherJob
self.notificationsManager = notificationsManager
self.accountManager = accountManager
self.callNotificationsAdapter = callNotificationsAdapter
self.pushRegistrationManager = pushRegistrationManager
super.init()
SwiftSingletons.register(self)
}
public var pushManager: PushManager
private override init() {
let accountManager = AccountManager()
let notificationsManager = NotificationsManager()
let callNotificationsAdapter = CallNotificationsAdapter()
let callService = CallService()
let callMessageHandler = WebRTCCallMessageHandler()
let outboundCallInitiator = OutboundCallInitiator()
let messageFetcherJob = MessageFetcherJob()
let pushRegistrationManager = PushRegistrationManager()
self.callMessageHandler = callMessageHandler
self.callService = callService
self.outboundCallInitiator = outboundCallInitiator
self.messageFetcherJob = messageFetcherJob
self.notificationsManager = notificationsManager
self.accountManager = accountManager
self.callNotificationsAdapter = callNotificationsAdapter
self.pushRegistrationManager = pushRegistrationManager
self.callMessageHandler = WebRTCCallMessageHandler()
self.callService = CallService()
self.outboundCallInitiator = OutboundCallInitiator()
self.messageFetcherJob = MessageFetcherJob()
self.notificationsManager = NotificationsManager()
self.accountManager = AccountManager()
self.callNotificationsAdapter = CallNotificationsAdapter()
self.pushRegistrationManager = PushRegistrationManager()
self.pushManager = PushManager()
super.init()

@ -15,8 +15,6 @@ NS_ASSUME_NONNULL_BEGIN
@interface NotificationsManager : NSObject <NotificationsProtocol, OWSCallNotificationsAdaptee>
- (void)clearAllNotifications;
#ifdef DEBUG
+ (void)presentDebugNotification;

@ -39,8 +39,6 @@ typedef void (^pushTokensSuccessBlock)(NSString *pushToken, NSString *voipToken)
@property (nonatomic) BOOL hasPresentedConversationSinceLastDeactivation;
- (instancetype)init NS_UNAVAILABLE;
+ (PushManager *)sharedManager;
/**

@ -35,47 +35,26 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
@property (nonatomic) NSMutableArray *currentNotifications;
@property (nonatomic) UIBackgroundTaskIdentifier callBackgroundTask;
@property (nonatomic, readonly) OWSMessageSender *messageSender;
@property (nonatomic, readonly) OWSMessageFetcherJob *messageFetcherJob;
@property (nonatomic, readonly) NotificationsManager *notificationsManager;
@end
@implementation PushManager
+ (instancetype)sharedManager {
static PushManager *sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedManager = [[self alloc] initDefault];
});
return sharedManager;
}
OWSAssertDebug(AppEnvironment.shared.pushManager);
- (instancetype)initDefault
{
return [self initWithMessageFetcherJob:AppEnvironment.shared.messageFetcherJob
primaryStorage:[OWSPrimaryStorage sharedManager]
messageSender:SSKEnvironment.shared.messageSender
notificationsManager:AppEnvironment.shared.notificationsManager];
return AppEnvironment.shared.pushManager;
}
- (instancetype)initWithMessageFetcherJob:(OWSMessageFetcherJob *)messageFetcherJob
primaryStorage:(OWSPrimaryStorage *)primaryStorage
messageSender:(OWSMessageSender *)messageSender
notificationsManager:(NotificationsManager *)notificationsManager
{
- (instancetype)init {
self = [super init];
if (!self) {
return self;
}
_messageSender = messageSender;
_messageFetcherJob = messageFetcherJob;
_callBackgroundTask = UIBackgroundTaskInvalid;
// TODO: consolidate notification tracking with NotificationsManager, which also maintains a list of notifications.
_currentNotifications = [NSMutableArray array];
_notificationsManager = notificationsManager;
OWSSingletonAssert();
@ -87,6 +66,22 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
return self;
}
#pragma mark - Dependencies
- (OWSMessageSender *)messageSender {
return SSKEnvironment.shared.messageSender;
}
- (OWSMessageFetcherJob *)messageFetcherJob {
return AppEnvironment.shared.messageFetcherJob;
}
- (id<NotificationsProtocol>)notificationsManager {
return SSKEnvironment.shared.notificationsManager;
}
#pragma mark -
- (CallUIAdapter *)callUIAdapter
{
return AppEnvironment.shared.callService.callUIAdapter;

@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setUp
{
NSLog(@"%@ setUp", self.logTag);
OWSLogInfo(@"");
[super setUp];
@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)tearDown
{
NSLog(@"%@ tearDown", self.logTag);
OWSLogInfo(@"");
[super tearDown];
}

@ -156,7 +156,7 @@ NS_ASSUME_NONNULL_BEGIN
[self waitForExpectationsWithTimeout:5.0
handler:^(NSError *error) {
if (error) {
NSLog(@"Timeout Error: %@", error);
OWSLogInfo(@"Timeout Error: %@", error);
}
}];
}

@ -103,7 +103,7 @@
NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateStyle = NSDateFormatterLongStyle;
formatter.timeStyle = NSDateFormatterLongStyle;
NSLog(@"now: %@", [formatter stringFromDate:now]);
OWSLogInfo(@"now: %@", [formatter stringFromDate:now]);
NSDate *oneSecondAgo =
[NSDate dateWithTimeIntervalSinceReferenceDate:[now timeIntervalSinceReferenceDate] - kSecondInterval];
@ -135,7 +135,7 @@
NSDate *twoYearsAhead =
[NSDate dateWithTimeIntervalSinceReferenceDate:[now timeIntervalSinceReferenceDate] + kYearInterval * 2];
NSLog(@"oneSecondAgo: %@", [formatter stringFromDate:oneSecondAgo]);
OWSLogInfo(@"oneSecondAgo: %@", [formatter stringFromDate:oneSecondAgo]);
XCTAssertTrue([DateUtil dateIsToday:oneSecondAgo now:now]);
XCTAssertTrue([DateUtil dateIsToday:oneMinuteAgo now:now]);
@ -236,13 +236,13 @@
formatter.timeStyle = NSDateFormatterLongStyle;
NSDate *yesterdayBeforeMidnight = [self dateWithYear:2015 month:8 day:10 hour:23 minute:55];
NSLog(@"yesterdayBeforeMidnight: %@", [formatter stringFromDate:yesterdayBeforeMidnight]);
OWSLogInfo(@"yesterdayBeforeMidnight: %@", [formatter stringFromDate:yesterdayBeforeMidnight]);
NSDate *todayAfterMidnight = [self dateWithYear:2015 month:8 day:11 hour:0 minute:5];
NSLog(@"todayAfterMidnight: %@", [formatter stringFromDate:todayAfterMidnight]);
OWSLogInfo(@"todayAfterMidnight: %@", [formatter stringFromDate:todayAfterMidnight]);
NSDate *todayNoon = [self dateWithYear:2015 month:8 day:11 hour:12 minute:0];
NSLog(@"todayNoon: %@", [formatter stringFromDate:todayNoon]);
OWSLogInfo(@"todayNoon: %@", [formatter stringFromDate:todayNoon]);
// Before Midnight, after Midnight.
XCTAssertFalse([DateUtil dateIsToday:yesterdayBeforeMidnight now:todayAfterMidnight]);

@ -18,4 +18,8 @@ public class NoopNotificationsManager: NSObject, NotificationsProtocol {
public func notifyUser(forThreadlessErrorMessage error: TSErrorMessage, transaction: YapDatabaseReadWriteTransaction) {
Logger.warn("skipping notification for: \(error.description)")
}
public func clearAllNotifications() {
Logger.warn("clearAllNotifications")
}
}

@ -4,6 +4,7 @@
#import "OWSDatabaseMigration.h"
#import <SignalServiceKit/OWSPrimaryStorage.h>
#import <SignalServiceKit/SSKEnvironment.h>
NS_ASSUME_NONNULL_BEGIN
@ -81,13 +82,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (YapDatabaseConnection *)dbReadWriteConnection
{
static dispatch_once_t onceToken;
static YapDatabaseConnection *sharedDBConnection;
dispatch_once(&onceToken, ^{
sharedDBConnection = [OWSPrimaryStorage sharedManager].newDatabaseConnection;
});
return sharedDBConnection;
return SSKEnvironment.shared.migrationDBConnection;
}
- (YapDatabaseConnection *)dbReadConnection

@ -220,12 +220,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
+ (YapDatabaseConnection *)dbMigrationConnection
{
static YapDatabaseConnection *connection = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
connection = [[OWSPrimaryStorage sharedManager] newDatabaseConnection];
});
return connection;
return SSKEnvironment.shared.migrationDBConnection;
}
+ (instancetype)outgoingMessageInThread:(nullable TSThread *)thread

@ -26,6 +26,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)notifyUserForThreadlessErrorMessage:(TSErrorMessage *)error
transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)clearAllNotifications;
@end
NS_ASSUME_NONNULL_END

@ -90,6 +90,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (atomic, nullable) id<NotificationsProtocol> notificationsManager;
@property (atomic, readonly) YapDatabaseConnection *objectReadWriteConnection;
@property (atomic, readonly) YapDatabaseConnection *sessionStoreDBConnection;
@property (atomic, readonly) YapDatabaseConnection *migrationDBConnection;
@property (atomic, readonly) YapDatabaseConnection *analyticsDBConnection;
- (BOOL)isComplete;

@ -42,6 +42,9 @@ static SSKEnvironment *sharedSSKEnvironment;
@synthesize callMessageHandler = _callMessageHandler;
@synthesize notificationsManager = _notificationsManager;
@synthesize objectReadWriteConnection = _objectReadWriteConnection;
@synthesize sessionStoreDBConnection = _sessionStoreDBConnection;
@synthesize migrationDBConnection = _migrationDBConnection;
@synthesize analyticsDBConnection = _analyticsDBConnection;
- (instancetype)initWithContactsManager:(id<ContactsManagerProtocol>)contactsManager
messageSender:(OWSMessageSender *)messageSender
@ -188,6 +191,34 @@ static SSKEnvironment *sharedSSKEnvironment;
return _objectReadWriteConnection;
}
}
- (YapDatabaseConnection *)sessionStoreDBConnection {
@synchronized(self) {
if (!_sessionStoreDBConnection) {
_sessionStoreDBConnection = self.primaryStorage.newDatabaseConnection;
}
return _sessionStoreDBConnection;
}
}
- (YapDatabaseConnection *)migrationDBConnection {
@synchronized(self) {
if (!_migrationDBConnection) {
_migrationDBConnection = self.primaryStorage.newDatabaseConnection;
}
return _migrationDBConnection;
}
}
- (YapDatabaseConnection *)analyticsDBConnection {
@synchronized(self) {
if (!_analyticsDBConnection) {
_analyticsDBConnection = self.primaryStorage.newDatabaseConnection;
}
return _analyticsDBConnection;
}
}
@end
NS_ASSUME_NONNULL_END

@ -2,8 +2,9 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSPrimaryStorage+SessionStore.h"
#import "OWSFileSystem.h"
#import "OWSPrimaryStorage+SessionStore.h"
#import "SSKEnvironment.h"
#import "YapDatabaseConnection+OWS.h"
#import "YapDatabaseTransaction+OWS.h"
#import <AxolotlKit/SessionRecord.h>
@ -23,14 +24,7 @@ NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
*/
+ (YapDatabaseConnection *)sessionStoreDBConnection
{
static dispatch_once_t onceToken;
static YapDatabaseConnection *sessionStoreDBConnection;
dispatch_once(&onceToken, ^{
sessionStoreDBConnection = [OWSPrimaryStorage sharedManager].newDatabaseConnection;
sessionStoreDBConnection.objectCacheEnabled = NO;
});
return sessionStoreDBConnection;
return SSKEnvironment.shared.sessionStoreDBConnection;
}
- (YapDatabaseConnection *)sessionStoreDBConnection

@ -12,27 +12,27 @@ NS_ASSUME_NONNULL_BEGIN
- (void)receivedOffer:(SSKProtoCallMessageOffer *)offer fromCallerId:(NSString *)callerId
{
NSLog(@"%s", __PRETTY_FUNCTION__);
OWSLogInfo(@"");
}
- (void)receivedAnswer:(SSKProtoCallMessageAnswer *)answer fromCallerId:(NSString *)callerId
{
NSLog(@"%s", __PRETTY_FUNCTION__);
OWSLogInfo(@"");
}
- (void)receivedIceUpdate:(SSKProtoCallMessageIceUpdate *)iceUpdate fromCallerId:(NSString *)callerId
{
NSLog(@"%s", __PRETTY_FUNCTION__);
OWSLogInfo(@"");
}
- (void)receivedHangup:(SSKProtoCallMessageHangup *)hangup fromCallerId:(NSString *)callerId
{
NSLog(@"%s", __PRETTY_FUNCTION__);
OWSLogInfo(@"");
}
- (void)receivedBusy:(SSKProtoCallMessageBusy *)busy fromCallerId:(NSString *)callerId
{
NSLog(@"%s", __PRETTY_FUNCTION__);
OWSLogInfo(@"");
}
@end

@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
//- (nullable SignalRecipient *)synchronousLookup:(NSString *)identifier error:(NSError **)error
//{
// NSLog(@"[OWSFakeContactsUpdater] Faking contact lookup.");
// OWSLogInfo(@"[OWSFakeContactsUpdater] Faking contact lookup.");
// return [[SignalRecipient alloc] initWithTextSecureIdentifier:@"fake-recipient-id"
// relay:nil];
//}

@ -13,15 +13,24 @@ NS_ASSUME_NONNULL_BEGIN
- (void)notifyUserForIncomingMessage:(TSIncomingMessage *)incomingMessage
inThread:(TSThread *)thread
contactsManager:(id<ContactsManagerProtocol>)contactsManager
{
NSLog(@"%s", __PRETTY_FUNCTION__);
transaction:(YapDatabaseReadTransaction *)transaction {
OWSLogInfo(@"");
}
- (void)notifyUserForErrorMessage:(TSErrorMessage *)error inThread:(TSThread *)thread
{
NSLog(@"%s", __PRETTY_FUNCTION__);
- (void)notifyUserForErrorMessage:(TSErrorMessage *)error
thread:(TSThread *)thread
transaction:(YapDatabaseReadWriteTransaction *)transaction {
OWSLogInfo(@"");
}
- (void)notifyUserForThreadlessErrorMessage:(TSErrorMessage *)error
transaction:(YapDatabaseReadWriteTransaction *)transaction {
OWSLogInfo(@"");
}
- (void)clearAllNotifications {
OWSLogInfo(@"");
}
@end

@ -7,6 +7,7 @@
#import "OWSBackgroundTask.h"
#import "OWSPrimaryStorage.h"
#import "OWSQueues.h"
#import "SSKEnvironment.h"
#import "YapDatabaseConnection+OWS.h"
#import <CocoaLumberjack/CocoaLumberjack.h>
#import <Reachability/Reachability.h>
@ -66,15 +67,7 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
// errors that occur while initializing OWSPrimaryStorage.
+ (YapDatabaseConnection *)dbConnection
{
static YapDatabaseConnection *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
OWSPrimaryStorage *primaryStorage = [OWSPrimaryStorage sharedManager];
OWSAssertDebug(primaryStorage);
// Use a newDatabaseConnection so as not to block reads in the launch path.
instance = primaryStorage.newDatabaseConnection;
});
return instance;
return SSKEnvironment.shared.analyticsDBConnection;
}
- (instancetype)initDefault

@ -20,7 +20,7 @@
success:(void (^)())successCallback
failure:(void (^)(NSError *))failureCallback
{
NSLog(@"faking successful provisioning");
OWSLogInfo(@"faking successful provisioning");
successCallback();
}
@ -35,7 +35,7 @@
- (void)requestProvisioningCodeWithSuccess:(void (^)(NSString *))successCallback
failure:(void (^)(NSError *))failureCallback
{
NSLog(@"faking successful provisioning code fetching");
OWSLogInfo(@"faking successful provisioning code fetching");
successCallback(@"fake-provisioning-code");
}
@ -90,7 +90,7 @@
[self waitForExpectationsWithTimeout:5.0
handler:^(NSError *error) {
if (error) {
NSLog(@"Timeout Error: %@", error);
OWSLogInfo(@"Timeout Error: %@", error);
}
}];
}

@ -86,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN
[self waitForExpectationsWithTimeout:5
handler:^(NSError *error) {
NSLog(@"No message submitted.");
OWSLogInfo(@"No message submitted.");
}];
}

@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
forRecipient:(SignalRecipient *)recipient
inThread:(TSThread *)thread
{
NSLog(@"[OWSFakeMessagesManager] Faking deviceMessages.");
OWSLogInfo(@"[OWSFakeMessagesManager] Faking deviceMessages.");
return @[];
}
@ -298,7 +298,7 @@ NS_ASSUME_NONNULL_BEGIN
[self waitForExpectationsWithTimeout:5
handler:^(NSError *error) {
NSLog(@"Expiration timer not set in time.");
OWSLogInfo(@"Expiration timer not set in time.");
}];
}
@ -324,7 +324,7 @@ NS_ASSUME_NONNULL_BEGIN
[self waitForExpectationsWithTimeout:5
handler:^(NSError *error) {
NSLog(@"Expiration timer not set in time.");
OWSLogInfo(@"Expiration timer not set in time.");
}];
}

@ -7,6 +7,9 @@
#import "SSKEnvironment.h"
#import "TestAppContext.h"
@import CocoaLumberjack;
#import <CocoaLumberjack/DDTTYLogger.h>
NS_ASSUME_NONNULL_BEGIN
#ifdef DEBUG
@ -15,10 +18,12 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setUp
{
NSLog(@"%@ setUp", self.logTag);
OWSLogInfo(@"%@ setUp", self.logTag);
[super setUp];
[DDLog addLogger:DDTTYLogger.sharedInstance];
ClearCurrentAppContextForTests();
SetCurrentAppContext([TestAppContext new]);
@ -27,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)tearDown
{
NSLog(@"%@ tearDown", self.logTag);
OWSLogInfo(@"%@ tearDown", self.logTag);
[super tearDown];
}

@ -4,6 +4,7 @@
import XCTest
import SignalServiceKit
import CocoaLumberjack
@objc
public class SSKBaseTestSwift: XCTestCase {
@ -12,6 +13,8 @@ public class SSKBaseTestSwift: XCTestCase {
public override func setUp() {
super.setUp()
DDLog.add(DDTTYLogger.sharedInstance)
ClearCurrentAppContextForTests()
SetCurrentAppContext(TestAppContext())

Loading…
Cancel
Save