Commit 5e1c5c68 authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Kateryna Kostiuk

contact requests: present conversation view for contact request

- Makes the contact request items selectable and links them to
  their associated conversation.

Change-Id: I91f1ac47fa513453a3091297f56e4493082dee4b
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent 41dc9734
......@@ -41,10 +41,23 @@ class ContactRequestsCoordinator: Coordinator, StateableResponsive {
self.injectionBag = injectionBag
self.contactService = injectionBag.contactsService
self.navigationViewController.viewModel = ContactRequestTabBarItem(with: self.injectionBag)
self.stateSubject.subscribe(onNext: { [unowned self] (state) in
guard let state = state as? ConversationsState else { return }
switch state {
case .conversationDetail (let conversationViewModel):
self.showConversation(withConversationViewModel: conversationViewModel)
}
}).disposed(by: self.disposeBag)
}
func start () {
let contactRequestsViewController = ContactRequestsViewController.instantiate(with: self.injectionBag)
self.present(viewController: contactRequestsViewController, withStyle: .show, withAnimation: true)
self.present(viewController: contactRequestsViewController, withStyle: .show, withAnimation: true, withStateable: contactRequestsViewController.viewModel)
}
private func showConversation (withConversationViewModel conversationViewModel: ConversationViewModel) {
let conversationViewController = ConversationViewController.instantiate(with: self.injectionBag)
conversationViewController.viewModel = conversationViewModel
self.present(viewController: conversationViewController, withStyle: .show, withAnimation: true)
}
}
......@@ -39,7 +39,12 @@ class ContactRequestsViewController: UIViewController, StoryboardBased, ViewMode
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.rx.modelSelected(ContactRequestItem.self)
.subscribe({ [unowned self] item in
if let ringId = item.element?.contactRequest.ringId {
self.viewModel.showConversation(forRingId: ringId)
}
}).disposed(by: disposeBag)
self.navigationItem.title = L10n.Global.contactRequestsTabBarTitle
}
......@@ -52,7 +57,7 @@ class ContactRequestsViewController: UIViewController, StoryboardBased, ViewMode
func setupTableView() {
self.tableView.estimatedRowHeight = 100.0
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.allowsSelection = false
self.tableView.allowsSelection = true
//Register cell
self.tableView.register(cellType: ContactRequestCell.self)
......
......@@ -22,7 +22,13 @@ import RxSwift
import Contacts
import SwiftyBeaver
class ContactRequestsViewModel: ViewModel {
class ContactRequestsViewModel: Stateable, ViewModel {
// MARK: - Rx Stateable
private let stateSubject = PublishSubject<State>()
lazy var state: Observable<State> = {
return self.stateSubject.asObservable()
}()
let contactsService: ContactsService
let accountsService: AccountsService
......@@ -32,12 +38,16 @@ class ContactRequestsViewModel: ViewModel {
fileprivate let disposeBag = DisposeBag()
fileprivate let log = SwiftyBeaver.self
fileprivate let injectionBag: InjectionBag
required init(with injectionBag: InjectionBag) {
self.contactsService = injectionBag.contactsService
self.accountsService = injectionBag.accountService
self.conversationService = injectionBag.conversationsService
self.nameService = injectionBag.nameService
self.injectionBag = injectionBag
self.contactsService.contactRequests
.asObservable()
.subscribe(onNext: {[unowned self] contactRequests in
......@@ -134,4 +144,12 @@ class ContactRequestsViewModel: ViewModel {
nameserver: "",
address: item.contactRequest.ringId)
}
func showConversation (forRingId ringId: String) {
let conversationViewModel = ConversationViewModel(with: self.injectionBag)
let conversation = self.conversationService.findConversation(withRingId: ringId,
withAccountId: (accountsService.currentAccount?.id)!)
conversationViewModel.conversation = conversation
self.stateSubject.onNext(ConversationsState.conversationDetail(conversationViewModel: conversationViewModel))
}
}
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