Commit 4f4435bb authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

fix: place call from contact request

This patch adds the ability to call a persons from pending contact
requests list.

Change-Id: Ic18951e6b307305afa01960d9ef8538392a8bb12
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 01293d39
......@@ -113,6 +113,7 @@
0E4909751FEAC943005CAA50 /* CallViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E4909741FEAC943005CAA50 /* CallViewController.storyboard */; };
0E49097A1FEAC9E1005CAA50 /* CallViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E4909791FEAC9E1005CAA50 /* CallViewController.swift */; };
0E49097C1FEACA4B005CAA50 /* CallViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E49097B1FEACA4B005CAA50 /* CallViewModel.swift */; };
0E68571120238546008B0717 /* CallMakeable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E68571020238546008B0717 /* CallMakeable.swift */; };
0E6949791FA7E71C0029B60A /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6949781FA7E71C0029B60A /* BaseViewController.swift */; };
0E7CF4DB20164B6700CD967D /* ButtonsContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7CF4DA20164B6700CD967D /* ButtonsContainerView.swift */; };
0E7CF4DD20165BFB00CD967D /* ButtonsContainerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E7CF4DC20165BFB00CD967D /* ButtonsContainerViewModel.swift */; };
......@@ -379,6 +380,7 @@
0E4909741FEAC943005CAA50 /* CallViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CallViewController.storyboard; sourceTree = "<group>"; };
0E4909791FEAC9E1005CAA50 /* CallViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallViewController.swift; sourceTree = "<group>"; };
0E49097B1FEACA4B005CAA50 /* CallViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallViewModel.swift; sourceTree = "<group>"; };
0E68571020238546008B0717 /* CallMakeable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallMakeable.swift; sourceTree = "<group>"; };
0E6949781FA7E71C0029B60A /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = "<group>"; };
0E7CF4DA20164B6700CD967D /* ButtonsContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonsContainerView.swift; sourceTree = "<group>"; };
0E7CF4DC20165BFB00CD967D /* ButtonsContainerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonsContainerViewModel.swift; sourceTree = "<group>"; };
......@@ -1120,6 +1122,7 @@
1A2041791F1E547F00C08435 /* Stateable.swift */,
1A20418C1F1EABCC00C08435 /* StateableResponsive.swift */,
1A20418E1F1EAC0E00C08435 /* Coordinator.swift */,
0E68571020238546008B0717 /* CallMakeable.swift */,
);
path = Protocols;
sourceTree = "<group>";
......@@ -1642,6 +1645,7 @@
1A2D18C51F29180700B2C785 /* ContactModel.swift in Sources */,
1A2D18F71F292D7200B2C785 /* MessageCellSent.swift in Sources */,
04399AAC1D1C304300E99CD9 /* AccountAdapter.mm in Sources */,
0E68571120238546008B0717 /* CallMakeable.swift in Sources */,
0E49096C1FEAB225005CAA50 /* CallsAdapterDelegate.swift in Sources */,
1AABA7461F0FE9C000739605 /* UIColor+Ring.swift in Sources */,
1A5DC0201F355DCF0075E8EF /* ContactsService.swift in Sources */,
......
......@@ -22,7 +22,7 @@ import Foundation
import RxSwift
/// This Coordinator drives the Contact Requests navigation
class ContactRequestsCoordinator: Coordinator, StateableResponsive {
class ContactRequestsCoordinator: Coordinator, StateableResponsive, CallMakeable {
var rootViewController: UIViewController {
return self.navigationViewController
......@@ -31,7 +31,7 @@ class ContactRequestsCoordinator: Coordinator, StateableResponsive {
var childCoordinators = [Coordinator]()
private let navigationViewController = BaseViewController(with: TabBarItemType.contactRequest)
private let injectionBag: InjectionBag
let injectionBag: InjectionBag
let disposeBag = DisposeBag()
let stateSubject = PublishSubject<State>()
......@@ -46,10 +46,9 @@ class ContactRequestsCoordinator: Coordinator, StateableResponsive {
switch state {
case .conversationDetail (let conversationViewModel):
self.showConversation(withConversationViewModel: conversationViewModel)
default:
break
}
}).disposed(by: self.disposeBag)
self.callbackPlaceCall()
}
func start () {
......@@ -60,6 +59,6 @@ class ContactRequestsCoordinator: Coordinator, StateableResponsive {
private func showConversation (withConversationViewModel conversationViewModel: ConversationViewModel) {
let conversationViewController = ConversationViewController.instantiate(with: self.injectionBag)
conversationViewController.viewModel = conversationViewModel
self.present(viewController: conversationViewController, withStyle: .show, withAnimation: true)
self.present(viewController: conversationViewController, withStyle: .show, withAnimation: true, withStateable: conversationViewController.viewModel)
}
}
......@@ -372,13 +372,13 @@ class ConversationViewModel: Stateable, ViewModel {
if self.conversation.value.messages.isEmpty {
self.sendContactRequest()
}
self.stateSubject.onNext(ConversationsState.startCall(contactRingId: self.conversation.value.recipientRingId, userName: self.userName.value))
self.stateSubject.onNext(PlaceCallState.startCall(contactRingId: self.conversation.value.recipientRingId, userName: self.userName.value))
}
func startAudioCall() {
if self.conversation.value.messages.isEmpty {
self.sendContactRequest()
}
self.stateSubject.onNext(ConversationsState.startAudioCall(contactRingId: self.conversation.value.recipientRingId, userName: self.userName.value))
self.stateSubject.onNext(PlaceCallState.startAudioCall(contactRingId: self.conversation.value.recipientRingId, userName: self.userName.value))
}
}
......@@ -26,12 +26,10 @@ import RxSwift
/// - conversationDetail: user want to see a conversation detail
enum ConversationsState: State {
case conversationDetail(conversationViewModel: ConversationViewModel)
case startCall(contactRingId: String, userName: String)
case startAudioCall(contactRingId: String, userName: String)
}
/// This Coordinator drives the conversation navigation (Smartlist / Conversation detail)
class ConversationsCoordinator: Coordinator, StateableResponsive {
class ConversationsCoordinator: Coordinator, StateableResponsive, CallMakeable {
var rootViewController: UIViewController {
return self.navigationViewController
......@@ -40,7 +38,7 @@ class ConversationsCoordinator: Coordinator, StateableResponsive {
var childCoordinators = [Coordinator]()
private let navigationViewController = BaseViewController(with: TabBarItemType.chat)
private let injectionBag: InjectionBag
let injectionBag: InjectionBag
let disposeBag = DisposeBag()
let stateSubject = PublishSubject<State>()
......@@ -63,14 +61,10 @@ class ConversationsCoordinator: Coordinator, StateableResponsive {
switch state {
case .conversationDetail (let conversationViewModel):
self.showConversation(withConversationViewModel: conversationViewModel)
case .startCall(let contactRingId, let name):
self.startOutgoingCall(contactRingId: contactRingId, userName: name)
case .startAudioCall(let contactRingId, let name):
self.startOutgoingCall(contactRingId: contactRingId, userName: name, isAudioOnly: true)
}
}).disposed(by: self.disposeBag)
self.navigationViewController.viewModel = ChatTabBarItemViewModel(with: self.injectionBag)
self.callbackPlaceCall()
}
func start () {
......@@ -84,12 +78,6 @@ class ConversationsCoordinator: Coordinator, StateableResponsive {
self.present(viewController: conversationViewController, withStyle: .show, withAnimation: true, withStateable: conversationViewController.viewModel)
}
private func startOutgoingCall(contactRingId: String, userName: String, isAudioOnly: Bool = false) {
let callViewController = CallViewController.instantiate(with: self.injectionBag)
callViewController.viewModel.placeCall(with: contactRingId, userName: userName, isAudioOnly: isAudioOnly)
self.present(viewController: callViewController, withStyle: .present, withAnimation: false)
}
private func answerIncomingCall(call: CallModel) {
let callViewController = CallViewController.instantiate(with: self.injectionBag)
callViewController.viewModel.call = call
......
/*
* Copyright (C) 2018 Savoir-faire Linux Inc.
*
* Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import RxSwift
enum PlaceCallState: State {
case startCall(contactRingId: String, userName: String)
case startAudioCall(contactRingId: String, userName: String)
}
protocol CallMakeable: class {
var injectionBag: InjectionBag { get }
}
extension CallMakeable where Self: Coordinator, Self: StateableResponsive {
func callbackPlaceCall() {
self.stateSubject.subscribe(onNext: { [unowned self] (state) in
guard let state = state as? PlaceCallState else { return }
switch state {
case .startCall(let contactRingId, let name):
self.startOutgoingCall(contactRingId: contactRingId, userName: name)
case .startAudioCall(let contactRingId, let name):
self.startOutgoingCall(contactRingId: contactRingId, userName: name, isAudioOnly: true)
}
}).disposed(by: self.disposeBag)
}
func startOutgoingCall(contactRingId: String, userName: String, isAudioOnly: Bool = false) {
let callViewController = CallViewController.instantiate(with: self.injectionBag)
callViewController.viewModel.placeCall(with: contactRingId, userName: userName, isAudioOnly: isAudioOnly)
self.present(viewController: callViewController, withStyle: .present, withAnimation: false)
}
}
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