|
|
@ -19,35 +19,17 @@ extension AppDelegate {
|
|
|
|
presentingVC.present(callVC, animated: true, completion: nil)
|
|
|
|
presentingVC.present(callVC, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc func dismissAllCallUI() {
|
|
|
|
private func dismissAllCallUI() {
|
|
|
|
if let currentBanner = IncomingCallBanner.current { currentBanner.dismiss() }
|
|
|
|
if let currentBanner = IncomingCallBanner.current { currentBanner.dismiss() }
|
|
|
|
if let callVC = CurrentAppContext().frontmostViewController() as? CallVC { callVC.handleEndCallMessage() }
|
|
|
|
if let callVC = CurrentAppContext().frontmostViewController() as? CallVC { callVC.handleEndCallMessage() }
|
|
|
|
if let miniCallView = MiniCallView.current { miniCallView.dismiss() }
|
|
|
|
if let miniCallView = MiniCallView.current { miniCallView.dismiss() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc func setUpCallHandling() {
|
|
|
|
private func showCallUIForCall(_ call: SessionCall) {
|
|
|
|
// Pre offer messages
|
|
|
|
|
|
|
|
MessageReceiver.handleNewCallOfferMessageIfNeeded = { (message, transaction) in
|
|
|
|
|
|
|
|
guard CurrentAppContext().isMainApp else { return }
|
|
|
|
|
|
|
|
let callManager = AppEnvironment.shared.callManager
|
|
|
|
|
|
|
|
// Ignore pre offer message afte the same call instance has been generated
|
|
|
|
|
|
|
|
if let currentCall = callManager.currentCall, currentCall.uuid == message.uuid! { return }
|
|
|
|
|
|
|
|
guard callManager.currentCall == nil && SSKPreferences.areCallsEnabled else {
|
|
|
|
|
|
|
|
callManager.handleIncomingCallOfferInBusyOrUnenabledState(offerMessage: message, using: transaction)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create incoming call message
|
|
|
|
|
|
|
|
let thread = TSContactThread.getOrCreateThread(withContactSessionID: message.sender!, transaction: transaction)
|
|
|
|
|
|
|
|
let tsMessage = TSIncomingMessage.from(message, associatedWith: thread)
|
|
|
|
|
|
|
|
tsMessage.save(with: transaction)
|
|
|
|
|
|
|
|
// Handle UI
|
|
|
|
|
|
|
|
if let caller = message.sender, let uuid = message.uuid {
|
|
|
|
|
|
|
|
let call = SessionCall(for: caller, uuid: uuid, mode: .answer)
|
|
|
|
|
|
|
|
call.callMessageTimestamp = message.sentTimestamp
|
|
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
if CurrentAppContext().isMainAppAndActive {
|
|
|
|
if CurrentAppContext().isMainAppAndActive {
|
|
|
|
guard let presentingVC = CurrentAppContext().frontmostViewController() else { preconditionFailure() } // TODO: Handle more gracefully
|
|
|
|
guard let presentingVC = CurrentAppContext().frontmostViewController() else { preconditionFailure() } // TODO: Handle more gracefully
|
|
|
|
if let conversationVC = presentingVC as? ConversationVC, let contactThread = conversationVC.thread as? TSContactThread, contactThread.contactSessionID() == caller {
|
|
|
|
if let conversationVC = presentingVC as? ConversationVC, let contactThread = conversationVC.thread as? TSContactThread, contactThread.contactSessionID() == call.sessionID {
|
|
|
|
let callVC = CallVC(for: call)
|
|
|
|
let callVC = CallVC(for: call)
|
|
|
|
callVC.conversationVC = conversationVC
|
|
|
|
callVC.conversationVC = conversationVC
|
|
|
|
conversationVC.inputAccessoryView?.isHidden = true
|
|
|
|
conversationVC.inputAccessoryView?.isHidden = true
|
|
|
@ -64,6 +46,28 @@ extension AppDelegate {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@objc func setUpCallHandling() {
|
|
|
|
|
|
|
|
// Pre offer messages
|
|
|
|
|
|
|
|
MessageReceiver.handleNewCallOfferMessageIfNeeded = { (message, transaction) in
|
|
|
|
|
|
|
|
guard CurrentAppContext().isMainApp else { return }
|
|
|
|
|
|
|
|
let callManager = AppEnvironment.shared.callManager
|
|
|
|
|
|
|
|
// Ignore pre offer message after the same call instance has been generated
|
|
|
|
|
|
|
|
if let currentCall = callManager.currentCall, currentCall.uuid == message.uuid! { return }
|
|
|
|
|
|
|
|
guard callManager.currentCall == nil && SSKPreferences.areCallsEnabled else {
|
|
|
|
|
|
|
|
callManager.handleIncomingCallOfferInBusyOrUnenabledState(offerMessage: message, using: transaction)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create incoming call message
|
|
|
|
|
|
|
|
let thread = TSContactThread.getOrCreateThread(withContactSessionID: message.sender!, transaction: transaction)
|
|
|
|
|
|
|
|
let tsMessage = TSIncomingMessage.from(message, associatedWith: thread)
|
|
|
|
|
|
|
|
tsMessage.save(with: transaction)
|
|
|
|
|
|
|
|
// Handle UI
|
|
|
|
|
|
|
|
if let caller = message.sender, let uuid = message.uuid {
|
|
|
|
|
|
|
|
let call = SessionCall(for: caller, uuid: uuid, mode: .answer)
|
|
|
|
|
|
|
|
call.callMessageTimestamp = message.sentTimestamp
|
|
|
|
|
|
|
|
self.showCallUIForCall(call)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Offer messages
|
|
|
|
// Offer messages
|
|
|
|
MessageReceiver.handleOfferCallMessage = { message in
|
|
|
|
MessageReceiver.handleOfferCallMessage = { message in
|
|
|
|