2017-02-02 21:13:41 +01:00
|
|
|
//
|
2018-07-18 03:32:44 +02:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2017-02-02 21:13:41 +01:00
|
|
|
//
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2018-08-31 19:12:40 +02:00
|
|
|
#import "SSKEnvironment.h"
|
2017-12-06 21:53:19 +01:00
|
|
|
#import "AppContext.h"
|
2018-09-17 15:27:58 +02:00
|
|
|
#import "OWSPrimaryStorage.h"
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2016-12-18 22:08:26 +01:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2018-08-31 19:12:40 +02:00
|
|
|
static SSKEnvironment *sharedSSKEnvironment;
|
2016-12-18 22:08:26 +01:00
|
|
|
|
2018-08-31 19:12:40 +02:00
|
|
|
@implementation SSKEnvironment
|
2016-12-18 22:08:26 +01:00
|
|
|
|
2018-09-17 15:27:58 +02:00
|
|
|
@synthesize callMessageHandler = _callMessageHandler;
|
|
|
|
@synthesize notificationsManager = _notificationsManager;
|
|
|
|
@synthesize objectReadWriteConnection = _objectReadWriteConnection;
|
|
|
|
|
|
|
|
- (instancetype)initWithContactsManager:(id<ContactsManagerProtocol>)contactsManager
|
|
|
|
messageSender:(OWSMessageSender *)messageSender
|
|
|
|
profileManager:(id<ProfileManagerProtocol>)profileManager
|
|
|
|
primaryStorage:(OWSPrimaryStorage *)primaryStorage
|
|
|
|
contactsUpdater:(ContactsUpdater *)contactsUpdater
|
|
|
|
networkManager:(TSNetworkManager *)networkManager
|
2016-12-18 22:08:26 +01:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(contactsManager);
|
|
|
|
OWSAssertDebug(messageSender);
|
|
|
|
OWSAssertDebug(profileManager);
|
2018-09-17 15:27:58 +02:00
|
|
|
OWSAssertDebug(primaryStorage);
|
|
|
|
OWSAssertDebug(contactsUpdater);
|
|
|
|
OWSAssertDebug(networkManager);
|
2017-12-06 21:53:19 +01:00
|
|
|
|
2016-12-18 22:08:26 +01:00
|
|
|
_contactsManager = contactsManager;
|
2017-03-30 18:37:22 +02:00
|
|
|
_messageSender = messageSender;
|
2017-08-02 19:12:26 +02:00
|
|
|
_profileManager = profileManager;
|
2018-09-17 15:27:58 +02:00
|
|
|
_primaryStorage = primaryStorage;
|
|
|
|
_contactsUpdater = contactsUpdater;
|
|
|
|
_networkManager = networkManager;
|
2016-12-18 22:08:26 +01:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2018-08-31 19:16:31 +02:00
|
|
|
+ (instancetype)shared
|
2016-12-18 22:08:26 +01:00
|
|
|
{
|
2018-08-31 19:12:40 +02:00
|
|
|
OWSAssertDebug(sharedSSKEnvironment);
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2018-08-31 19:12:40 +02:00
|
|
|
return sharedSSKEnvironment;
|
2017-03-30 18:37:22 +02:00
|
|
|
}
|
2017-02-02 21:13:41 +01:00
|
|
|
|
2018-08-31 19:16:31 +02:00
|
|
|
+ (void)setShared:(SSKEnvironment *)env
|
2017-02-02 21:13:41 +01:00
|
|
|
{
|
2018-09-06 19:01:24 +02:00
|
|
|
OWSAssertDebug(env);
|
2018-08-31 19:12:40 +02:00
|
|
|
OWSAssertDebug(!sharedSSKEnvironment || CurrentAppContext().isRunningTests);
|
2017-02-02 21:13:41 +01:00
|
|
|
|
2018-08-31 19:12:40 +02:00
|
|
|
sharedSSKEnvironment = env;
|
2017-08-02 19:12:26 +02:00
|
|
|
}
|
|
|
|
|
2018-09-17 15:27:58 +02:00
|
|
|
+ (void)clearSharedForTests
|
|
|
|
{
|
|
|
|
sharedSSKEnvironment = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Mutable Accessors
|
|
|
|
|
|
|
|
- (nullable id<OWSCallMessageHandler>)callMessageHandler
|
|
|
|
{
|
|
|
|
@synchronized(self) {
|
|
|
|
OWSAssertDebug(_callMessageHandler);
|
|
|
|
|
|
|
|
return _callMessageHandler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setCallMessageHandler:(nullable id<OWSCallMessageHandler>)callMessageHandler
|
|
|
|
{
|
|
|
|
@synchronized(self) {
|
|
|
|
OWSAssertDebug(callMessageHandler);
|
|
|
|
OWSAssertDebug(!_callMessageHandler);
|
|
|
|
|
|
|
|
_callMessageHandler = callMessageHandler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (nullable id<NotificationsProtocol>)notificationsManager
|
|
|
|
{
|
|
|
|
@synchronized(self) {
|
|
|
|
OWSAssertDebug(_notificationsManager);
|
|
|
|
|
|
|
|
return _notificationsManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setNotificationsManager:(nullable id<NotificationsProtocol>)notificationsManager
|
|
|
|
{
|
|
|
|
@synchronized(self) {
|
|
|
|
OWSAssertDebug(notificationsManager);
|
|
|
|
OWSAssertDebug(!_notificationsManager);
|
|
|
|
|
|
|
|
_notificationsManager = notificationsManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isComplete
|
|
|
|
{
|
|
|
|
return (self.callMessageHandler != nil && self.notificationsManager != nil);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (YapDatabaseConnection *)objectReadWriteConnection
|
|
|
|
{
|
|
|
|
@synchronized(self) {
|
|
|
|
if (!_objectReadWriteConnection) {
|
|
|
|
_objectReadWriteConnection = self.primaryStorage.newDatabaseConnection;
|
|
|
|
}
|
|
|
|
return _objectReadWriteConnection;
|
|
|
|
}
|
|
|
|
}
|
2015-12-07 03:31:43 +01:00
|
|
|
@end
|
2016-12-18 22:08:26 +01:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|