fix duplicated incoming call

pull/560/head
Ryan Zhao 4 years ago
parent bf33030d9a
commit e9f19b9c62

@ -105,10 +105,10 @@ public final class SessionCallManager: NSObject {
guard let call = currentCall else { return } guard let call = currentCall else { return }
if let reason = reason { if let reason = reason {
self.provider.reportCall(with: call.callID, endedAt: nil, reason: reason) self.provider.reportCall(with: call.callID, endedAt: nil, reason: reason)
if reason == .answeredElsewhere { return }
switch (reason) { switch (reason) {
case .unanswered: call.updateCallMessage(mode: .unanswered) case .unanswered: call.updateCallMessage(mode: .unanswered)
case .declinedElsewhere: call.updateCallMessage(mode: .local) case .declinedElsewhere: call.updateCallMessage(mode: .local)
case .answeredElsewhere: break
default: call.updateCallMessage(mode: .remote) default: call.updateCallMessage(mode: .remote)
} }
} else { } else {

@ -19,18 +19,40 @@ 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() }
} }
private func showCallUIForCall(_ call: SessionCall) {
DispatchQueue.main.async {
if CurrentAppContext().isMainAppAndActive {
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() == call.sessionID {
let callVC = CallVC(for: call)
callVC.conversationVC = conversationVC
conversationVC.inputAccessoryView?.isHidden = true
conversationVC.inputAccessoryView?.alpha = 0
presentingVC.present(callVC, animated: true, completion: nil)
}
}
call.reportIncomingCallIfNeeded{ error in
if let error = error {
SNLog("[Calls] Failed to report incoming call to CallKit due to error: \(error)")
let incomingCallBanner = IncomingCallBanner(for: call)
incomingCallBanner.show()
}
}
}
}
@objc func setUpCallHandling() { @objc func setUpCallHandling() {
// Pre offer messages // Pre offer messages
MessageReceiver.handleNewCallOfferMessageIfNeeded = { (message, transaction) in MessageReceiver.handleNewCallOfferMessageIfNeeded = { (message, transaction) in
guard CurrentAppContext().isMainApp else { return } guard CurrentAppContext().isMainApp else { return }
let callManager = AppEnvironment.shared.callManager let callManager = AppEnvironment.shared.callManager
// Ignore pre offer message afte the same call instance has been generated // Ignore pre offer message after the same call instance has been generated
if let currentCall = callManager.currentCall, currentCall.uuid == message.uuid! { return } if let currentCall = callManager.currentCall, currentCall.uuid == message.uuid! { return }
guard callManager.currentCall == nil && SSKPreferences.areCallsEnabled else { guard callManager.currentCall == nil && SSKPreferences.areCallsEnabled else {
callManager.handleIncomingCallOfferInBusyOrUnenabledState(offerMessage: message, using: transaction) callManager.handleIncomingCallOfferInBusyOrUnenabledState(offerMessage: message, using: transaction)
@ -44,25 +66,7 @@ extension AppDelegate {
if let caller = message.sender, let uuid = message.uuid { if let caller = message.sender, let uuid = message.uuid {
let call = SessionCall(for: caller, uuid: uuid, mode: .answer) let call = SessionCall(for: caller, uuid: uuid, mode: .answer)
call.callMessageTimestamp = message.sentTimestamp call.callMessageTimestamp = message.sentTimestamp
DispatchQueue.main.async { self.showCallUIForCall(call)
if CurrentAppContext().isMainAppAndActive {
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 {
let callVC = CallVC(for: call)
callVC.conversationVC = conversationVC
conversationVC.inputAccessoryView?.isHidden = true
conversationVC.inputAccessoryView?.alpha = 0
presentingVC.present(callVC, animated: true, completion: nil)
}
}
call.reportIncomingCallIfNeeded{ error in
if let error = error {
SNLog("[Calls] Failed to report incoming call to CallKit due to error: \(error)")
let incomingCallBanner = IncomingCallBanner(for: call)
incomingCallBanner.show()
}
}
}
} }
} }
// Offer messages // Offer messages

@ -271,8 +271,6 @@ extension MessageReceiver {
handleNewCallOfferMessageIfNeeded?(message, transaction) handleNewCallOfferMessageIfNeeded?(message, transaction)
case .offer: case .offer:
print("[Calls] Received offer message.") print("[Calls] Received offer message.")
let transaction = transaction as! YapDatabaseReadWriteTransaction
handleNewCallOfferMessageIfNeeded?(message, transaction)
handleOfferCallMessage?(message) handleOfferCallMessage?(message)
case .answer: case .answer:
print("[Calls] Received answer message.") print("[Calls] Received answer message.")

Loading…
Cancel
Save