mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Create AppEnvironment.
This commit is contained in:
parent
dbaa49d2f9
commit
d7e52367ff
12 changed files with 246 additions and 151 deletions
|
@ -265,6 +265,7 @@
|
||||||
34D8C02B1ED3685800188D7C /* DebugUIContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C02A1ED3685800188D7C /* DebugUIContacts.m */; };
|
34D8C02B1ED3685800188D7C /* DebugUIContacts.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D8C02A1ED3685800188D7C /* DebugUIContacts.m */; };
|
||||||
34D920E720E179C200D51158 /* OWSMessageFooterView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D920E620E179C200D51158 /* OWSMessageFooterView.m */; };
|
34D920E720E179C200D51158 /* OWSMessageFooterView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34D920E620E179C200D51158 /* OWSMessageFooterView.m */; };
|
||||||
34D99C931F2937CC00D284D6 /* OWSAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D99C911F2937CC00D284D6 /* OWSAnalytics.swift */; };
|
34D99C931F2937CC00D284D6 /* OWSAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D99C911F2937CC00D284D6 /* OWSAnalytics.swift */; };
|
||||||
|
34D99CE4217509C2000AFB39 /* AppEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D99CE3217509C1000AFB39 /* AppEnvironment.swift */; };
|
||||||
34DB0BED2011548B007B313F /* OWSDatabaseConverterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34DB0BEC2011548B007B313F /* OWSDatabaseConverterTest.m */; };
|
34DB0BED2011548B007B313F /* OWSDatabaseConverterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34DB0BEC2011548B007B313F /* OWSDatabaseConverterTest.m */; };
|
||||||
34DBF003206BD5A500025978 /* OWSMessageTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34DBEFFF206BD5A400025978 /* OWSMessageTextView.m */; };
|
34DBF003206BD5A500025978 /* OWSMessageTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34DBEFFF206BD5A400025978 /* OWSMessageTextView.m */; };
|
||||||
34DBF004206BD5A500025978 /* OWSBubbleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34DBF001206BD5A500025978 /* OWSBubbleView.m */; };
|
34DBF004206BD5A500025978 /* OWSBubbleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34DBF001206BD5A500025978 /* OWSBubbleView.m */; };
|
||||||
|
@ -942,6 +943,7 @@
|
||||||
34D920E520E179C100D51158 /* OWSMessageFooterView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageFooterView.h; sourceTree = "<group>"; };
|
34D920E520E179C100D51158 /* OWSMessageFooterView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageFooterView.h; sourceTree = "<group>"; };
|
||||||
34D920E620E179C200D51158 /* OWSMessageFooterView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSMessageFooterView.m; sourceTree = "<group>"; };
|
34D920E620E179C200D51158 /* OWSMessageFooterView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSMessageFooterView.m; sourceTree = "<group>"; };
|
||||||
34D99C911F2937CC00D284D6 /* OWSAnalytics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSAnalytics.swift; sourceTree = "<group>"; };
|
34D99C911F2937CC00D284D6 /* OWSAnalytics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSAnalytics.swift; sourceTree = "<group>"; };
|
||||||
|
34D99CE3217509C1000AFB39 /* AppEnvironment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppEnvironment.swift; sourceTree = "<group>"; };
|
||||||
34DB0BEB2011548A007B313F /* OWSDatabaseConverterTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSDatabaseConverterTest.h; sourceTree = "<group>"; };
|
34DB0BEB2011548A007B313F /* OWSDatabaseConverterTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSDatabaseConverterTest.h; sourceTree = "<group>"; };
|
||||||
34DB0BEC2011548B007B313F /* OWSDatabaseConverterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSDatabaseConverterTest.m; sourceTree = "<group>"; };
|
34DB0BEC2011548B007B313F /* OWSDatabaseConverterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSDatabaseConverterTest.m; sourceTree = "<group>"; };
|
||||||
34DBEFFF206BD5A400025978 /* OWSMessageTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSMessageTextView.m; sourceTree = "<group>"; };
|
34DBEFFF206BD5A400025978 /* OWSMessageTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSMessageTextView.m; sourceTree = "<group>"; };
|
||||||
|
@ -2160,6 +2162,7 @@
|
||||||
76EB041118170B33006006FC /* environment */ = {
|
76EB041118170B33006006FC /* environment */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
34D99CE3217509C1000AFB39 /* AppEnvironment.swift */,
|
||||||
4505C2BD1E648E6E00CEBF41 /* ExperienceUpgrades */,
|
4505C2BD1E648E6E00CEBF41 /* ExperienceUpgrades */,
|
||||||
3461299A1FD1EA9E00532771 /* NotificationsManager.h */,
|
3461299A1FD1EA9E00532771 /* NotificationsManager.h */,
|
||||||
3461299B1FD1EA9E00532771 /* NotificationsManager.m */,
|
3461299B1FD1EA9E00532771 /* NotificationsManager.m */,
|
||||||
|
@ -3295,6 +3298,7 @@
|
||||||
340FC8B4204DAC8D007AEB0F /* OWSBackupSettingsViewController.m in Sources */,
|
340FC8B4204DAC8D007AEB0F /* OWSBackupSettingsViewController.m in Sources */,
|
||||||
34D1F0871F8678AA0066283D /* ConversationViewItem.m in Sources */,
|
34D1F0871F8678AA0066283D /* ConversationViewItem.m in Sources */,
|
||||||
451A13B11E13DED2000A50FD /* CallNotificationsAdapter.swift in Sources */,
|
451A13B11E13DED2000A50FD /* CallNotificationsAdapter.swift in Sources */,
|
||||||
|
34D99CE4217509C2000AFB39 /* AppEnvironment.swift in Sources */,
|
||||||
348570A820F67575004FF32B /* OWSMessageHeaderView.m in Sources */,
|
348570A820F67575004FF32B /* OWSMessageHeaderView.m in Sources */,
|
||||||
450DF2091E0DD2C6003D14BE /* UserNotificationsAdaptee.swift in Sources */,
|
450DF2091E0DD2C6003D14BE /* UserNotificationsAdaptee.swift in Sources */,
|
||||||
34D1F0AB1F867BFC0066283D /* OWSContactOffersCell.m in Sources */,
|
34D1F0AB1F867BFC0066283D /* OWSContactOffersCell.m in Sources */,
|
||||||
|
|
|
@ -158,7 +158,9 @@ static NSTimeInterval launchStartedAt;
|
||||||
|
|
||||||
[AppSetup
|
[AppSetup
|
||||||
setupEnvironmentWithAppSpecificSingletonBlock:^{
|
setupEnvironmentWithAppSpecificSingletonBlock:^{
|
||||||
[SignalApp.sharedApp createSingletons];
|
// Create AppEnvironment.
|
||||||
|
[AppEnvironment shared];
|
||||||
|
[SignalApp.sharedApp setup];
|
||||||
}
|
}
|
||||||
migrationCompletion:^{
|
migrationCompletion:^{
|
||||||
OWSAssertIsOnMainThread();
|
OWSAssertIsOnMainThread();
|
||||||
|
|
|
@ -9,15 +9,14 @@ import SignalServiceKit
|
||||||
@objc(OWSMessageFetcherJob)
|
@objc(OWSMessageFetcherJob)
|
||||||
public class MessageFetcherJob: NSObject {
|
public class MessageFetcherJob: NSObject {
|
||||||
|
|
||||||
private var timer: Timer?
|
private
|
||||||
|
var timer : Timer ?
|
||||||
|
|
||||||
// MARK: injected dependencies
|
@objc public override
|
||||||
private let signalService: OWSSignalService
|
init()
|
||||||
|
{
|
||||||
@objc public init(signalService: OWSSignalService) {
|
super
|
||||||
self.signalService = signalService
|
.init()
|
||||||
|
|
||||||
super.init()
|
|
||||||
|
|
||||||
SwiftSingletons.register(self)
|
SwiftSingletons.register(self)
|
||||||
}
|
}
|
||||||
|
@ -32,6 +31,12 @@ public class MessageFetcherJob: NSObject {
|
||||||
return SSKEnvironment.shared.messageReceiver
|
return SSKEnvironment.shared.messageReceiver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private
|
||||||
|
var signalService : OWSSignalService
|
||||||
|
{
|
||||||
|
return OWSSignalService.sharedInstance()
|
||||||
|
}
|
||||||
|
|
||||||
// MARK:
|
// MARK:
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
|
|
|
@ -18,8 +18,8 @@ public class AccountManager: NSObject {
|
||||||
return PushManager.shared()
|
return PushManager.shared()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc public override init()
|
||||||
public required override init() {
|
{
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
SwiftSingletons.register(self)
|
SwiftSingletons.register(self)
|
||||||
|
|
|
@ -14,7 +14,7 @@ class DebugUINotifications: DebugUIPage {
|
||||||
return SignalApp.shared().notificationsManager
|
return SignalApp.shared().notificationsManager
|
||||||
}
|
}
|
||||||
var notificationsAdapter: CallNotificationsAdapter {
|
var notificationsAdapter: CallNotificationsAdapter {
|
||||||
return SignalApp.shared().callService.notificationsAdapter
|
return AppEnvironment.shared.callNotificationsAdapter
|
||||||
}
|
}
|
||||||
var messageSender: MessageSender {
|
var messageSender: MessageSender {
|
||||||
return SSKEnvironment.shared.messageSender
|
return SSKEnvironment.shared.messageSender
|
||||||
|
@ -29,7 +29,8 @@ class DebugUINotifications: DebugUIPage {
|
||||||
return "Notifications"
|
return "Notifications"
|
||||||
}
|
}
|
||||||
|
|
||||||
override func section(thread aThread: TSThread?) -> OWSTableSection? {
|
override func section(thread aThread: TSThread?) -> OWSTableSection?
|
||||||
|
{
|
||||||
guard let thread = aThread else {
|
guard let thread = aThread else {
|
||||||
owsFailDebug("Notifications must specify thread.")
|
owsFailDebug("Notifications must specify thread.")
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -147,25 +147,28 @@ private class SignalCallData: NSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
required init(call: SignalCall) {
|
required init(call
|
||||||
self.call = call
|
: SignalCall) { self.call = call
|
||||||
|
|
||||||
let (callConnectedPromise, callConnectedResolver) = Promise<Void>.pending()
|
let(callConnectedPromise, callConnectedResolver)
|
||||||
self.callConnectedPromise = callConnectedPromise
|
= Promise<Void>.pending() self.callConnectedPromise = callConnectedPromise self.callConnectedResolver
|
||||||
self.callConnectedResolver = callConnectedResolver
|
= callConnectedResolver
|
||||||
|
|
||||||
let (peerConnectionClientPromise, peerConnectionClientResolver) = Promise<Void>.pending()
|
let(peerConnectionClientPromise, peerConnectionClientResolver)
|
||||||
self.peerConnectionClientPromise = peerConnectionClientPromise
|
= Promise<Void>.pending() self.peerConnectionClientPromise
|
||||||
self.peerConnectionClientResolver = peerConnectionClientResolver
|
= peerConnectionClientPromise self.peerConnectionClientResolver = peerConnectionClientResolver
|
||||||
|
|
||||||
let (readyToSendIceUpdatesPromise, readyToSendIceUpdatesResolver) = Promise<Void>.pending()
|
let(readyToSendIceUpdatesPromise, readyToSendIceUpdatesResolver)
|
||||||
self.readyToSendIceUpdatesPromise = readyToSendIceUpdatesPromise
|
= Promise<Void>.pending() self.readyToSendIceUpdatesPromise
|
||||||
self.readyToSendIceUpdatesResolver = readyToSendIceUpdatesResolver
|
= readyToSendIceUpdatesPromise self.readyToSendIceUpdatesResolver = readyToSendIceUpdatesResolver
|
||||||
|
|
||||||
super.init()
|
super
|
||||||
}
|
.init()
|
||||||
|
|
||||||
deinit {
|
SwiftSingletons.register(self) }
|
||||||
|
|
||||||
|
deinit
|
||||||
|
{
|
||||||
Logger.debug("[SignalCallData] deinit")
|
Logger.debug("[SignalCallData] deinit")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,22 +207,21 @@ private class SignalCallData: NSObject {
|
||||||
|
|
||||||
// MARK: Dependencies
|
// MARK: Dependencies
|
||||||
|
|
||||||
private let accountManager: AccountManager
|
|
||||||
private let messageSender: MessageSender
|
|
||||||
private let contactsManager: OWSContactsManager
|
|
||||||
private let primaryStorage: OWSPrimaryStorage
|
|
||||||
|
|
||||||
// Exposed by environment.m
|
// Exposed by environment.m
|
||||||
internal let notificationsAdapter: CallNotificationsAdapter
|
|
||||||
@objc public var callUIAdapter: CallUIAdapter!
|
@objc public var callUIAdapter : CallUIAdapter !
|
||||||
|
|
||||||
// MARK: Class
|
// MARK: Class
|
||||||
|
|
||||||
static let fallbackIceServer = RTCIceServer(urlStrings: ["stun:stun1.l.google.com:19302"])
|
static let fallbackIceServer
|
||||||
|
= RTCIceServer(urlStrings
|
||||||
|
: ["stun:stun1.l.google.com:19302"])
|
||||||
|
|
||||||
// MARK: Ivars
|
// MARK: Ivars
|
||||||
|
|
||||||
fileprivate var callData: SignalCallData? {
|
fileprivate var callData : SignalCallData
|
||||||
|
?
|
||||||
|
{
|
||||||
didSet {
|
didSet {
|
||||||
AssertIsOnMainThread()
|
AssertIsOnMainThread()
|
||||||
|
|
||||||
|
@ -291,33 +293,59 @@ private class SignalCallData: NSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc public required init(accountManager: AccountManager, contactsManager: OWSContactsManager, messageSender: MessageSender, notificationsAdapter: CallNotificationsAdapter) {
|
@objc public override init() { super
|
||||||
self.accountManager = accountManager
|
.init()
|
||||||
self.contactsManager = contactsManager
|
|
||||||
self.messageSender = messageSender
|
|
||||||
self.notificationsAdapter = notificationsAdapter
|
|
||||||
self.primaryStorage = OWSPrimaryStorage.shared()
|
|
||||||
|
|
||||||
super.init()
|
SwiftSingletons
|
||||||
|
.register(self)
|
||||||
|
|
||||||
SwiftSingletons.register(self)
|
self
|
||||||
|
.createCallUIAdapter()
|
||||||
|
|
||||||
self.createCallUIAdapter()
|
NotificationCenter.default
|
||||||
|
.addObserver(self, selector
|
||||||
|
: #selector(didEnterBackground), name
|
||||||
|
: NSNotification.Name.OWSApplicationDidEnterBackground, object
|
||||||
|
: nil)
|
||||||
|
NotificationCenter.default.addObserver(
|
||||||
|
self, selector
|
||||||
|
: #selector(didBecomeActive), name
|
||||||
|
: NSNotification.Name.OWSApplicationDidBecomeActive, object
|
||||||
|
: nil) }
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self,
|
deinit
|
||||||
selector: #selector(didEnterBackground),
|
{
|
||||||
name: NSNotification.Name.OWSApplicationDidEnterBackground,
|
|
||||||
object: nil)
|
|
||||||
NotificationCenter.default.addObserver(self,
|
|
||||||
selector: #selector(didBecomeActive),
|
|
||||||
name: NSNotification.Name.OWSApplicationDidBecomeActive,
|
|
||||||
object: nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
deinit {
|
|
||||||
NotificationCenter.default.removeObserver(self)
|
NotificationCenter.default.removeObserver(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Dependencies
|
||||||
|
|
||||||
|
private
|
||||||
|
var contactsManager : OWSContactsManager
|
||||||
|
{
|
||||||
|
return Environment.shared.contactsManager
|
||||||
|
}
|
||||||
|
|
||||||
|
private
|
||||||
|
var messageSender : MessageSender
|
||||||
|
{
|
||||||
|
return SSKEnvironment.shared.messageSender
|
||||||
|
}
|
||||||
|
|
||||||
|
private
|
||||||
|
var accountManager : AccountManager
|
||||||
|
{
|
||||||
|
return AppEnvironment.shared.accountManager
|
||||||
|
}
|
||||||
|
|
||||||
|
private
|
||||||
|
var notificationsAdapter : CallNotificationsAdapter
|
||||||
|
{
|
||||||
|
return AppEnvironment.shared.callNotificationsAdapter
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Notifications
|
||||||
|
|
||||||
@objc func didEnterBackground() {
|
@objc func didEnterBackground() {
|
||||||
AssertIsOnMainThread()
|
AssertIsOnMainThread()
|
||||||
self.updateIsVideoEnabled()
|
self.updateIsVideoEnabled()
|
||||||
|
@ -328,6 +356,8 @@ private class SignalCallData: NSObject {
|
||||||
self.updateIsVideoEnabled()
|
self.updateIsVideoEnabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: -
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Choose whether to use CallKit or a Notification backed interface for calling.
|
* Choose whether to use CallKit or a Notification backed interface for calling.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,18 +11,29 @@ import SignalMessaging
|
||||||
*/
|
*/
|
||||||
@objc public class OutboundCallInitiator: NSObject {
|
@objc public class OutboundCallInitiator: NSObject {
|
||||||
|
|
||||||
let contactsManager: OWSContactsManager
|
@objc public override init()
|
||||||
let contactsUpdater: ContactsUpdater
|
{
|
||||||
|
|
||||||
@objc public init(contactsManager: OWSContactsManager, contactsUpdater: ContactsUpdater) {
|
|
||||||
self.contactsManager = contactsManager
|
|
||||||
self.contactsUpdater = contactsUpdater
|
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
SwiftSingletons.register(self)
|
SwiftSingletons.register(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Dependencies
|
||||||
|
|
||||||
|
private
|
||||||
|
var contactsManager : OWSContactsManager
|
||||||
|
{
|
||||||
|
return Environment.shared.contactsManager
|
||||||
|
}
|
||||||
|
|
||||||
|
private
|
||||||
|
var contactsUpdater : ContactsUpdater
|
||||||
|
{
|
||||||
|
return SSKEnvironment.shared.contactsUpdater
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: -
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* |handle| is a user formatted phone number, e.g. from a system contacts entry
|
* |handle| is a user formatted phone number, e.g. from a system contacts entry
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -9,26 +9,36 @@ import SignalMessaging
|
||||||
@objc(OWSWebRTCCallMessageHandler)
|
@objc(OWSWebRTCCallMessageHandler)
|
||||||
public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
|
public class WebRTCCallMessageHandler: NSObject, OWSCallMessageHandler {
|
||||||
|
|
||||||
// MARK: - Properties
|
|
||||||
|
|
||||||
// MARK: Dependencies
|
|
||||||
|
|
||||||
let accountManager: AccountManager
|
|
||||||
let callService: CallService
|
|
||||||
let messageSender: MessageSender
|
|
||||||
|
|
||||||
// MARK: Initializers
|
// MARK: Initializers
|
||||||
|
|
||||||
@objc public required init(accountManager: AccountManager, callService: CallService, messageSender: MessageSender) {
|
@objc public override init()
|
||||||
self.accountManager = accountManager
|
{
|
||||||
self.callService = callService
|
super
|
||||||
self.messageSender = messageSender
|
.init()
|
||||||
|
|
||||||
super.init()
|
|
||||||
|
|
||||||
SwiftSingletons.register(self)
|
SwiftSingletons.register(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Dependencies
|
||||||
|
|
||||||
|
private
|
||||||
|
var messageSender : MessageSender
|
||||||
|
{
|
||||||
|
return SSKEnvironment.shared.messageSender
|
||||||
|
}
|
||||||
|
|
||||||
|
private
|
||||||
|
var accountManager : AccountManager
|
||||||
|
{
|
||||||
|
return AppEnvironment.shared.accountManager
|
||||||
|
}
|
||||||
|
|
||||||
|
private
|
||||||
|
var callService : CallService
|
||||||
|
{
|
||||||
|
return AppEnvironment.shared.callService
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Call Handlers
|
// MARK: - Call Handlers
|
||||||
|
|
||||||
public func receivedOffer(_ offer: SSKProtoCallMessageOffer, from callerId: String) {
|
public func receivedOffer(_ offer: SSKProtoCallMessageOffer, from callerId: String) {
|
||||||
|
|
89
Signal/src/environment/AppEnvironment.swift
Normal file
89
Signal/src/environment/AppEnvironment.swift
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
//
|
||||||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
//import PromiseKit
|
||||||
|
//import PushKit
|
||||||
|
import SignalServiceKit import SignalMessaging
|
||||||
|
|
||||||
|
@objc public class AppEnvironment : NSObject {
|
||||||
|
|
||||||
|
private
|
||||||
|
static var _shared : AppEnvironment = AppEnvironment()
|
||||||
|
|
||||||
|
@objc public class var shared : AppEnvironment {
|
||||||
|
get { return _shared } set
|
||||||
|
{
|
||||||
|
_shared = newValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public var callMessageHandler : WebRTCCallMessageHandler
|
||||||
|
|
||||||
|
@objc public var callService : CallService
|
||||||
|
|
||||||
|
@objc public var outboundCallInitiator
|
||||||
|
: OutboundCallInitiator
|
||||||
|
|
||||||
|
@objc public var messageFetcherJob : MessageFetcherJob
|
||||||
|
|
||||||
|
@objc public var notificationsManager : NotificationsManager
|
||||||
|
|
||||||
|
@objc public var accountManager
|
||||||
|
: AccountManager
|
||||||
|
|
||||||
|
@objc public var callNotificationsAdapter : CallNotificationsAdapter
|
||||||
|
|
||||||
|
@objc public init(callMessageHandler
|
||||||
|
: WebRTCCallMessageHandler, callService
|
||||||
|
: CallService, outboundCallInitiator
|
||||||
|
: OutboundCallInitiator, messageFetcherJob
|
||||||
|
: MessageFetcherJob, notificationsManager
|
||||||
|
: NotificationsManager, accountManager
|
||||||
|
: AccountManager, callNotificationsAdapter
|
||||||
|
: CallNotificationsAdapter)
|
||||||
|
{
|
||||||
|
self.callMessageHandler = callMessageHandler self.callService = callService self.outboundCallInitiator
|
||||||
|
= outboundCallInitiator self.messageFetcherJob = messageFetcherJob self.notificationsManager
|
||||||
|
= notificationsManager self.accountManager = accountManager self.callNotificationsAdapter
|
||||||
|
= callNotificationsAdapter
|
||||||
|
|
||||||
|
super
|
||||||
|
.init()
|
||||||
|
|
||||||
|
SwiftSingletons.register(self)
|
||||||
|
|
||||||
|
setup()
|
||||||
|
}
|
||||||
|
|
||||||
|
private
|
||||||
|
override init()
|
||||||
|
{
|
||||||
|
let accountManager = AccountManager() let notificationsManager
|
||||||
|
= NotificationsManager() let callNotificationsAdapter = CallNotificationsAdapter() let callService
|
||||||
|
= CallService() let callMessageHandler = WebRTCCallMessageHandler() let outboundCallInitiator
|
||||||
|
= OutboundCallInitiator() let messageFetcherJob = MessageFetcherJob()
|
||||||
|
|
||||||
|
self.callMessageHandler
|
||||||
|
= callMessageHandler self.callService = callService self.outboundCallInitiator
|
||||||
|
= outboundCallInitiator self.messageFetcherJob = messageFetcherJob self.notificationsManager
|
||||||
|
= notificationsManager self.accountManager = accountManager self.callNotificationsAdapter
|
||||||
|
= callNotificationsAdapter
|
||||||
|
|
||||||
|
super
|
||||||
|
.init()
|
||||||
|
|
||||||
|
SwiftSingletons.register(self)
|
||||||
|
|
||||||
|
setup()
|
||||||
|
}
|
||||||
|
|
||||||
|
private
|
||||||
|
func setup()
|
||||||
|
{
|
||||||
|
// Hang certain singletons on SSKEnvironment too.
|
||||||
|
SSKEnvironment.shared.notificationsManager = notificationsManager SSKEnvironment.shared.callMessageHandler
|
||||||
|
= callMessageHandler
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
+ (instancetype)sharedApp;
|
+ (instancetype)sharedApp;
|
||||||
|
|
||||||
- (void)createSingletons;
|
- (void)setup;
|
||||||
|
|
||||||
#pragma mark - Conversation Presentation
|
#pragma mark - Conversation Presentation
|
||||||
|
|
||||||
|
|
|
@ -15,19 +15,6 @@
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface SignalApp ()
|
|
||||||
|
|
||||||
@property (nonatomic) OWSWebRTCCallMessageHandler *callMessageHandler;
|
|
||||||
@property (nonatomic) CallService *callService;
|
|
||||||
@property (nonatomic) OutboundCallInitiator *outboundCallInitiator;
|
|
||||||
@property (nonatomic) OWSMessageFetcherJob *messageFetcherJob;
|
|
||||||
@property (nonatomic) NotificationsManager *notificationsManager;
|
|
||||||
@property (nonatomic) AccountManager *accountManager;
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
|
|
||||||
@implementation SignalApp
|
@implementation SignalApp
|
||||||
|
|
||||||
+ (instancetype)sharedApp
|
+ (instancetype)sharedApp
|
||||||
|
@ -55,88 +42,46 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
#pragma mark - Singletons
|
#pragma mark - Singletons
|
||||||
|
|
||||||
- (void)createSingletons
|
- (void)setup {
|
||||||
{
|
|
||||||
OWSAssertDebug(SSKEnvironment.shared.messageSender);
|
|
||||||
OWSAssertDebug(Environment.shared.contactsManager);
|
|
||||||
OWSAssertDebug(Environment.shared.preferences);
|
|
||||||
OWSAssertDebug(SSKEnvironment.shared.networkManager);
|
|
||||||
OWSAssertDebug(SSKEnvironment.shared.contactsUpdater);
|
|
||||||
|
|
||||||
_accountManager = [[AccountManager alloc] init];
|
|
||||||
|
|
||||||
_notificationsManager = [NotificationsManager new];
|
|
||||||
SSKEnvironment.shared.notificationsManager = self.notificationsManager;
|
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(didChangeCallLoggingPreference:)
|
selector:@selector(didChangeCallLoggingPreference:)
|
||||||
name:OWSPreferencesCallLoggingDidChangeNotification
|
name:OWSPreferencesCallLoggingDidChangeNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
_callService = [[CallService alloc] initWithAccountManager:self.accountManager
|
|
||||||
contactsManager:Environment.shared.contactsManager
|
|
||||||
messageSender:SSKEnvironment.shared.messageSender
|
|
||||||
notificationsAdapter:[OWSCallNotificationsAdapter new]];
|
|
||||||
|
|
||||||
_callMessageHandler =
|
|
||||||
[[OWSWebRTCCallMessageHandler alloc] initWithAccountManager:self.accountManager
|
|
||||||
callService:self.callService
|
|
||||||
messageSender:SSKEnvironment.shared.messageSender];
|
|
||||||
SSKEnvironment.shared.callMessageHandler = self.callMessageHandler;
|
|
||||||
|
|
||||||
_outboundCallInitiator =
|
|
||||||
[[OutboundCallInitiator alloc] initWithContactsManager:Environment.shared.contactsManager
|
|
||||||
contactsUpdater:SSKEnvironment.shared.contactsUpdater];
|
|
||||||
|
|
||||||
_messageFetcherJob = [[OWSMessageFetcherJob alloc] initWithSignalService:[OWSSignalService sharedInstance]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OWSWebRTCCallMessageHandler *)callMessageHandler
|
- (OWSWebRTCCallMessageHandler *)callMessageHandler
|
||||||
{
|
{
|
||||||
OWSAssertDebug(_callMessageHandler);
|
return AppEnvironment.shared.callMessageHandler;
|
||||||
|
|
||||||
return _callMessageHandler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CallService *)callService
|
- (CallService *)callService
|
||||||
{
|
{
|
||||||
OWSAssertDebug(_callService);
|
return AppEnvironment.shared.callService;
|
||||||
|
|
||||||
return _callService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CallUIAdapter *)callUIAdapter
|
- (CallUIAdapter *)callUIAdapter
|
||||||
{
|
{
|
||||||
OWSAssertDebug(self.callService.callUIAdapter);
|
return AppEnvironment.shared.callService.callUIAdapter;
|
||||||
|
|
||||||
return self.callService.callUIAdapter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OutboundCallInitiator *)outboundCallInitiator
|
- (OutboundCallInitiator *)outboundCallInitiator
|
||||||
{
|
{
|
||||||
OWSAssertDebug(_outboundCallInitiator);
|
return AppEnvironment.shared.outboundCallInitiator;
|
||||||
|
|
||||||
return _outboundCallInitiator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (OWSMessageFetcherJob *)messageFetcherJob
|
- (OWSMessageFetcherJob *)messageFetcherJob
|
||||||
{
|
{
|
||||||
OWSAssertDebug(_messageFetcherJob);
|
return AppEnvironment.shared.messageFetcherJob;
|
||||||
|
|
||||||
return _messageFetcherJob;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NotificationsManager *)notificationsManager
|
- (NotificationsManager *)notificationsManager
|
||||||
{
|
{
|
||||||
OWSAssertDebug(_notificationsManager);
|
return AppEnvironment.shared.notificationsManager;
|
||||||
|
|
||||||
return _notificationsManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (AccountManager *)accountManager
|
- (AccountManager *)accountManager
|
||||||
{
|
{
|
||||||
OWSAssertDebug(_accountManager);
|
return AppEnvironment.shared.accountManager;
|
||||||
|
|
||||||
return _accountManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - View Convenience Methods
|
#pragma mark - View Convenience Methods
|
||||||
|
|
|
@ -42,11 +42,10 @@ class FailingTSAccountManager: TSAccountManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
class VerifyingTSAccountManager: FailingTSAccountManager {
|
class VerifyingTSAccountManager: FailingTSAccountManager {
|
||||||
override func verifyAccount(withCode: String,
|
override func verifyAccount(withCode
|
||||||
pin: String?,
|
: String, pin
|
||||||
success: @escaping () -> Void, failure: @escaping (Error) -> Void) {
|
: String ?, success : @escaping()->Void, failure
|
||||||
success()
|
: @escaping(Error)->Void) { success() } s
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TokenObtainingTSAccountManager: VerifyingTSAccountManager {
|
class TokenObtainingTSAccountManager: VerifyingTSAccountManager {
|
||||||
|
@ -142,5 +141,4 @@ class AccountManagerTest: SignalBaseTest {
|
||||||
|
|
||||||
self.waitForExpectations(timeout: 1.0, handler: nil)
|
self.waitForExpectations(timeout: 1.0, handler: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue