Commit 339376a5 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

call: prevent multiple calls

Since we don't support multiple calls yet, refuse a new incoming call
if one call is already started

Change-Id: I8be7a0be4f45dd4168477ac7fc650ef61912664d
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 03025bd0
......@@ -96,8 +96,11 @@ class CallViewModel: Stateable, ViewModel {
}()
lazy var dismisVC: Observable<Bool> = {
return callService.currentCall.map({[weak self] call in
return call.state == .over || call.state == .failure && call.callId == self?.call?.callId
return callService.currentCall.filter({ [weak self] call in
return call.callId == self?.call?.callId
})
.map({[weak self] call in
return call.state == .over || call.state == .failure
}).map({ hide in
return hide
})
......@@ -138,10 +141,12 @@ class CallViewModel: Stateable, ViewModel {
}()
lazy var bottomInfo: Observable<String> = {
return callService.currentCall.map({ [weak self] call in
return callService.currentCall
.filter({ [weak self] call in
return call.callId == self?.call?.callId
}).map({ [weak self] call in
if call.state == .connecting || call.state == .ringing &&
call.callType == .outgoing &&
call.callId == self?.call?.callId {
call.callType == .outgoing {
return L10n.Calls.calling
} else if call.state == .over {
return L10n.Calls.callFinished
......@@ -164,7 +169,10 @@ class CallViewModel: Stateable, ViewModel {
}()
lazy var showCancelOption: Observable<Bool> = {
return self.callService.currentCall.map({ call in
return self.callService.currentCall
.filter({ [weak self] call in
return call.callId == self?.call?.callId
}).map({ call in
return call.state == .connecting || call.state == .ringing
})
}()
......@@ -265,10 +273,6 @@ class CallViewModel: Stateable, ViewModel {
var containerViewModel: ButtonsContainerViewModel?
// lazy var containerViewModel: ButtonsContainerViewModel = {
// return ButtonsContainerViewModel(with: self.callService, audioService: self.audioService, callID: (self.call?.callId)!)
// }()
required init(with injectionBag: InjectionBag) {
self.callService = injectionBag.callService
self.contactsService = injectionBag.contactsService
......
......@@ -111,10 +111,6 @@ class ConversationsCoordinator: Coordinator, StateableResponsive {
alert.dismiss(animated: true, completion: nil)
}))
if let controller = self.rootViewController.presentedViewController {
controller.present(alert, animated: false, completion: nil)
} else {
self.present(viewController: alert, withStyle: .present, withAnimation: true)
}
}
}
......@@ -321,16 +321,27 @@ class CallsService: CallsAdapterDelegate {
func receivingCall(withAccountId accountId: String, callId: String, fromURI uri: String) {
if let callDictionary = self.callsAdapter.callDetails(withCallId: callId) {
//Add or update new call
var call = self.calls[callId]
if call == nil {
call = CallModel(withCallId: callId, callDetails: callDictionary)
if !isCurrentCall() {
let call = CallModel(withCallId: callId, callDetails: callDictionary)
self.newCall.value = call
} else {
call?.update(withDictionary: callDictionary)
self.refuse(callId: callId).subscribe(onCompleted: { [weak self] in
self?.log.debug("call refused")
}, onError: { [weak self] _ in
self?.log.debug("Could not to refuse a call")
}).disposed(by: self.disposeBag)
}
}
}
func isCurrentCall() -> Bool {
for call in self.calls.values {
if call.state == .current || call.state == .hold ||
call.state == .unhold || call.state == .ringing {
return true
}
//Emit the call to the observers
self.newCall.value = call!
}
return false
}
func newCallStarted(withAccountId accountId: String, callId: String, toURI uri: String) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment