|
@@ -2,7 +2,6 @@ import UIKit
|
|
|
import DcCore
|
|
|
|
|
|
class ChatListController: UITableViewController {
|
|
|
- weak var coordinator: ChatListCoordinator?
|
|
|
let viewModel: ChatListViewModelProtocol
|
|
|
let dcContext: DcContext
|
|
|
|
|
@@ -99,7 +98,7 @@ class ChatListController: UITableViewController {
|
|
|
object: nil,
|
|
|
queue: nil) { notification in
|
|
|
if let chatId = notification.userInfo?["chat_id"] as? Int {
|
|
|
- self.coordinator?.showChat(chatId: chatId)
|
|
|
+ self.showChat(chatId: chatId)
|
|
|
}
|
|
|
}
|
|
|
deleteChatObserver = nc.addObserver(
|
|
@@ -141,7 +140,7 @@ class ChatListController: UITableViewController {
|
|
|
|
|
|
// MARK: - actions
|
|
|
@objc func didPressNewChat() {
|
|
|
- coordinator?.showNewChatController()
|
|
|
+ showNewChatController()
|
|
|
}
|
|
|
|
|
|
@objc func cancelButtonPressed() {
|
|
@@ -214,14 +213,14 @@ class ChatListController: UITableViewController {
|
|
|
case .chat(let chatData):
|
|
|
let chatId = chatData.chatId
|
|
|
if chatId == DC_CHAT_ID_ARCHIVED_LINK {
|
|
|
- coordinator?.showArchive()
|
|
|
+ showArchive()
|
|
|
} else {
|
|
|
- coordinator?.showChat(chatId: chatId)
|
|
|
+ showChat(chatId: chatId)
|
|
|
}
|
|
|
case .contact(let contactData):
|
|
|
let contactId = contactData.contactId
|
|
|
if let chatId = contactData.chatId {
|
|
|
- coordinator?.showChat(chatId: chatId)
|
|
|
+ showChat(chatId: chatId)
|
|
|
} else {
|
|
|
self.askToChatWith(contactId: contactId)
|
|
|
}
|
|
@@ -318,7 +317,7 @@ class ChatListController: UITableViewController {
|
|
|
let alert = UIAlertController(title: title, message: nil, preferredStyle: .safeActionSheet)
|
|
|
alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
|
|
|
let chat = self.dcContext.createChatByMessageId(msgId)
|
|
|
- self.coordinator?.showChat(chatId: chat.id)
|
|
|
+ self.showChat(chatId: chat.id)
|
|
|
}))
|
|
|
alert.addAction(UIAlertAction(title: String.localized("not_now"), style: .default, handler: { _ in
|
|
|
dcContact.marknoticed()
|
|
@@ -340,7 +339,7 @@ class ChatListController: UITableViewController {
|
|
|
title: String.localized("start_chat"),
|
|
|
style: .default,
|
|
|
handler: { _ in
|
|
|
- self.coordinator?.showNewChat(contactId: contactId)
|
|
|
+ self.showNewChat(contactId: contactId)
|
|
|
}))
|
|
|
alert.addAction(UIAlertAction(
|
|
|
title: String.localized("cancel"),
|
|
@@ -360,6 +359,36 @@ class ChatListController: UITableViewController {
|
|
|
let row = viewModel.deleteChat(chatId: chatId)
|
|
|
tableView.deleteRows(at: [IndexPath(row: row, section: 0)], with: .fade)
|
|
|
}
|
|
|
+
|
|
|
+ // MARK: - coordinator
|
|
|
+ func showNewChatController() {
|
|
|
+ if let navigationController = self.parent as? UINavigationController {
|
|
|
+ let newChatVC = NewChatViewController(dcContext: dcContext)
|
|
|
+ navigationController.pushViewController(newChatVC, animated: true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func showChat(chatId: Int) {
|
|
|
+ if let navigationController = self.parent as? UINavigationController {
|
|
|
+ let chatVC = ChatViewController(dcContext: dcContext, chatId: chatId)
|
|
|
+ let coordinator = ChatViewCoordinator(dcContext: dcContext, navigationController: navigationController, chatId: chatId)
|
|
|
+ chatVC.coordinator = coordinator
|
|
|
+ navigationController.pushViewController(chatVC, animated: true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func showArchive() {
|
|
|
+ if let navigationController = self.parent as? UINavigationController {
|
|
|
+ let viewModel = ChatListViewModel(dcContext: dcContext, isArchive: true)
|
|
|
+ let controller = ChatListController(dcContext: dcContext, viewModel: viewModel)
|
|
|
+ navigationController.pushViewController(controller, animated: true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func showNewChat(contactId: Int) {
|
|
|
+ let chatId = dcContext.createChatByContactId(contactId: contactId)
|
|
|
+ showChat(chatId: Int(chatId))
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// MARK: - uisearchbardelegate
|