mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
192 lines
6.4 KiB
Objective-C
192 lines
6.4 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;
|
|
@property (nonatomic) TSSocketManager *socketManager;
|
|
@property (nonatomic) TSAccountManager *tsAccountManager;
|
|
@property (nonatomic) OWS2FAManager *ows2FAManager;
|
|
@property (nonatomic) AppVersion *appVersion;
|
|
@property (nonatomic) AppReadiness *appReadiness;
|
|
@property (nonatomic) OWSDisappearingMessagesJob *disappearingMessagesJob;
|
|
@property (nonatomic) ContactDiscoveryService *contactDiscoveryService;
|
|
|
|
@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
|
|
socketManager:(TSSocketManager *)socketManager
|
|
tsAccountManager:(TSAccountManager *)tsAccountManager
|
|
ows2FAManager:(OWS2FAManager *)ows2FAManager
|
|
appVersion:(AppVersion *)appVersion
|
|
appReadiness:(AppReadiness *)appReadiness
|
|
disappearingMessagesJob:(OWSDisappearingMessagesJob *)disappearingMessagesJob
|
|
contactDiscoveryService:(ContactDiscoveryService *)contactDiscoveryService {
|
|
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);
|
|
OWSAssertDebug(socketManager);
|
|
OWSAssertDebug(tsAccountManager);
|
|
OWSAssertDebug(ows2FAManager);
|
|
OWSAssertDebug(appVersion);
|
|
OWSAssertDebug(appReadiness);
|
|
OWSAssertDebug(disappearingMessagesJob);
|
|
OWSAssertDebug(contactDiscoveryService);
|
|
|
|
_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;
|
|
_socketManager = socketManager;
|
|
_tsAccountManager = tsAccountManager;
|
|
_ows2FAManager = ows2FAManager;
|
|
_appVersion = appVersion;
|
|
_appReadiness = appReadiness;
|
|
_disappearingMessagesJob = disappearingMessagesJob;
|
|
_contactDiscoveryService = contactDiscoveryService;
|
|
|
|
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
|