Commit 798690eb authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Kateryna Kostiuk

fix: handle accepting an invalid call

Change-Id: Id1b786060b716f72bf9ed44eb453a47c582f736e
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent 315ffb97
......@@ -80,7 +80,7 @@ class CallViewModel: Stateable, ViewModel {
}
}
// data for ViewCintroller binding
// data for ViewController binding
var contactImageData = Variable<Data?>(nil)
......@@ -120,8 +120,6 @@ class CallViewModel: Stateable, ViewModel {
}).asDriver(onErrorJustReturn: "")
}()
//let timer: Observable<String>
lazy var callDuration: Driver<String> = {
let timer = Observable<Int>.interval(1, scheduler: MainScheduler.instance)
.takeUntil(self.callService.currentCall
......@@ -300,16 +298,8 @@ class CallViewModel: Stateable, ViewModel {
}).disposed(by: self.disposeBag)
}
func answerCall() {
guard let call = self.call else {
return
}
self.callService.accept(callId: call.callId)
.subscribe(onCompleted: { [weak self] in
self?.log.info("Call answered")
}, onError: { [weak self] error in
self?.log.error("Failed to answer the call")
}).disposed(by: self.disposeBag)
func answerCall() -> Completable {
return self.callService.accept(call: call)
}
func placeCall(with uri: String, userName: String, isAudioOnly: Bool = false) {
......
......@@ -94,7 +94,9 @@ class ConversationsCoordinator: Coordinator, StateableResponsive {
let callViewController = CallViewController.instantiate(with: self.injectionBag)
callViewController.viewModel.call = call
callViewController.viewModel.answerCall()
self.present(viewController: callViewController, withStyle: .present, withAnimation: false)
.subscribe(onCompleted: { [weak self] in
self?.present(viewController: callViewController, withStyle: .present, withAnimation: false)
}).disposed(by: self.disposeBag)
}
private func showCallAlert(call: CallModel) {
......
......@@ -71,8 +71,12 @@ class CallsService: CallsAdapterDelegate {
CallsAdapter.delegate = self
}
func accept(callId: String) -> Completable {
func accept(call: CallModel?) -> Completable {
return Completable.create(subscribe: { completable in
guard let callId = call?.callId else {
completable(.error(CallServiceError.acceptCallFailed))
return Disposables.create { }
}
let success = self.callsAdapter.acceptCall(withId: callId)
if success {
completable(.completed)
......
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