166 lines
4.9 KiB
Objective-C
166 lines
4.9 KiB
Objective-C
//
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
#import "SSKEnvironment.h"
|
|
#import "AppContext.h"
|
|
#import "OWSPrimaryStorage.h"
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
static SSKEnvironment *sharedSSKEnvironment;
|
|
|
|
@interface SSKEnvironment ()
|
|
|
|
@property (nonatomic) id<ContactsManagerProtocol> contactsManager;
|
|
@property (nonatomic) OWSMessageSender *messageSender;
|
|
@property (nonatomic) id<ProfileManagerProtocol> profileManager;
|
|
@property (nonatomic) OWSPrimaryStorage *primaryStorage;
|
|
@property (nonatomic) ContactsUpdater *contactsUpdater;
|
|
@property (nonatomic) TSNetworkManager *networkManager;
|
|
@property (nonatomic) OWSMessageManager *messageManager;
|
|
@property (nonatomic) OWSBlockingManager *blockingManager;
|
|
@property (nonatomic) OWSIdentityManager *identityManager;
|
|
@property (nonatomic) id<OWSUDManager> udManager;
|
|
@property (nonatomic) OWSMessageDecrypter *messageDecrypter;
|
|
@property (nonatomic) OWSBatchMessageProcessor *batchMessageProcessor;
|
|
@property (nonatomic) OWSMessageReceiver *messageReceiver;
|
|
|
|
@end
|
|
|
|
#pragma mark -
|
|
|
|
@implementation SSKEnvironment
|
|
|
|
@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
|
|
messageManager:(OWSMessageManager *)messageManager
|
|
blockingManager:(OWSBlockingManager *)blockingManager
|
|
identityManager:(OWSIdentityManager *)identityManager
|
|
udManager:(id<OWSUDManager>)udManager
|
|
messageDecrypter:(OWSMessageDecrypter *)messageDecrypter
|
|
batchMessageProcessor:(OWSBatchMessageProcessor *)batchMessageProcessor
|
|
messageReceiver:(OWSMessageReceiver *)messageReceiver
|
|
{
|
|
self = [super init];
|
|
if (!self) {
|
|
return self;
|
|
}
|
|
|
|
OWSAssertDebug(contactsManager);
|
|
OWSAssertDebug(messageSender);
|
|
OWSAssertDebug(profileManager);
|
|
OWSAssertDebug(primaryStorage);
|
|
OWSAssertDebug(contactsUpdater);
|
|
OWSAssertDebug(networkManager);
|
|
OWSAssertDebug(messageManager);
|
|
OWSAssertDebug(blockingManager);
|
|
OWSAssertDebug(identityManager);
|
|
OWSAssertDebug(udManager);
|
|
OWSAssertDebug(messageDecrypter);
|
|
OWSAssertDebug(batchMessageProcessor);
|
|
OWSAssertDebug(messageReceiver);
|
|
|
|
_contactsManager = contactsManager;
|
|
_messageSender = messageSender;
|
|
_profileManager = profileManager;
|
|
_primaryStorage = primaryStorage;
|
|
_contactsUpdater = contactsUpdater;
|
|
_networkManager = networkManager;
|
|
_messageManager = messageManager;
|
|
_blockingManager = blockingManager;
|
|
_identityManager = identityManager;
|
|
_udManager = udManager;
|
|
_messageDecrypter = messageDecrypter;
|
|
_batchMessageProcessor = batchMessageProcessor;
|
|
_messageReceiver = messageReceiver;
|
|
|
|
return self;
|
|
}
|
|
|
|
+ (instancetype)shared
|
|
{
|
|
OWSAssertDebug(sharedSSKEnvironment);
|
|
|
|
return sharedSSKEnvironment;
|
|
}
|
|
|
|
+ (void)setShared:(SSKEnvironment *)env
|
|
{
|
|
OWSAssertDebug(env);
|
|
OWSAssertDebug(!sharedSSKEnvironment || CurrentAppContext().isRunningTests);
|
|
|
|
sharedSSKEnvironment = env;
|
|
}
|
|
|
|
+ (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;
|
|
}
|
|
}
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|