|
@@ -14,16 +14,12 @@ class ChatListController: UIViewController {
|
|
|
|
|
|
lazy var chatTable: UITableView = {
|
|
lazy var chatTable: UITableView = {
|
|
let chatTable = UITableView()
|
|
let chatTable = UITableView()
|
|
- chatTable.dataSource = chatTableDataSource
|
|
|
|
- chatTableDelegate.chatPresenter = self
|
|
|
|
- chatTable.delegate = chatTableDelegate
|
|
|
|
|
|
+ chatTable.dataSource = self
|
|
|
|
+ chatTable.delegate = self
|
|
chatTable.rowHeight = 80
|
|
chatTable.rowHeight = 80
|
|
return chatTable
|
|
return chatTable
|
|
}()
|
|
}()
|
|
|
|
|
|
- let chatTableDataSource = ChatTableDataSource()
|
|
|
|
- let chatTableDelegate = ChatTableDelegate()
|
|
|
|
-
|
|
|
|
var msgChangedObserver: Any?
|
|
var msgChangedObserver: Any?
|
|
var incomingMsgObserver: Any?
|
|
var incomingMsgObserver: Any?
|
|
var viewChatObserver: Any?
|
|
var viewChatObserver: Any?
|
|
@@ -66,8 +62,8 @@ class ChatListController: UIViewController {
|
|
viewChatObserver = nc.addObserver(forName: dcNotificationViewChat, object: nil, queue: nil) {
|
|
viewChatObserver = nc.addObserver(forName: dcNotificationViewChat, object: nil, queue: nil) {
|
|
notification in
|
|
notification in
|
|
if let chatId = notification.userInfo?["chat_id"] as? Int {
|
|
if let chatId = notification.userInfo?["chat_id"] as? Int {
|
|
- self.displayChatForId(chatId: chatId)
|
|
|
|
- }
|
|
|
|
|
|
+ self.coordinator?.showChat(chatId: chatId)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -109,12 +105,6 @@ class ChatListController: UIViewController {
|
|
|
|
|
|
@objc func didPressNewChat() {
|
|
@objc func didPressNewChat() {
|
|
coordinator?.showNewChatController()
|
|
coordinator?.showNewChatController()
|
|
- /*
|
|
|
|
- let ncv = NewChatViewController()
|
|
|
|
- ncv.chatDisplayer = self
|
|
|
|
- let nav = UINavigationController(rootViewController: ncv)
|
|
|
|
- present(nav, animated: true, completion: nil)
|
|
|
|
- */
|
|
|
|
}
|
|
}
|
|
|
|
|
|
func getChatList() {
|
|
func getChatList() {
|
|
@@ -123,42 +113,11 @@ class ChatListController: UIViewController {
|
|
}
|
|
}
|
|
// ownership of chatlistPointer transferred here to ChatList object
|
|
// ownership of chatlistPointer transferred here to ChatList object
|
|
chatList = MRChatList(chatListPointer: chatlistPointer)
|
|
chatList = MRChatList(chatListPointer: chatlistPointer)
|
|
-
|
|
|
|
- chatTableDataSource.chatList = chatList
|
|
|
|
chatTable.reloadData()
|
|
chatTable.reloadData()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-extension ChatListController: ChatPresenter {
|
|
|
|
- func displayChat(index: Int) {
|
|
|
|
- guard let chatList = self.chatList else {
|
|
|
|
- fatalError("chatList was nil in ChatPresenter extension")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let chatId = chatList.getChatId(index: index)
|
|
|
|
- let chatVC = ChatViewController(chatId: chatId)
|
|
|
|
-
|
|
|
|
- chatVC.hidesBottomBarWhenPushed = true
|
|
|
|
- navigationController?.pushViewController(chatVC, animated: true)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-extension ChatListController: ChatDisplayer {
|
|
|
|
- func displayNewChat(contactId: Int) {
|
|
|
|
- let chatId = dc_create_chat_by_contact_id(mailboxPointer, UInt32(contactId))
|
|
|
|
- displayChatForId(chatId: Int(chatId))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func displayChatForId(chatId: Int) {
|
|
|
|
- let chatVC = ChatViewController(chatId: chatId)
|
|
|
|
-
|
|
|
|
- chatVC.hidesBottomBarWhenPushed = true
|
|
|
|
- navigationController?.pushViewController(chatVC, animated: true)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-class ChatTableDataSource: NSObject, UITableViewDataSource {
|
|
|
|
- weak var chatList: MRChatList?
|
|
|
|
|
|
+extension ChatListController: UITableViewDataSource, UITableViewDelegate {
|
|
|
|
|
|
func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
|
|
func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
|
|
guard let chatList = self.chatList else {
|
|
guard let chatList = self.chatList else {
|
|
@@ -205,17 +164,11 @@ class ChatTableDataSource: NSObject, UITableViewDataSource {
|
|
cell.emailLabel.text = result
|
|
cell.emailLabel.text = result
|
|
return cell
|
|
return cell
|
|
}
|
|
}
|
|
-}
|
|
|
|
-
|
|
|
|
-protocol ChatPresenter: class {
|
|
|
|
- func displayChat(index: Int)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-class ChatTableDelegate: NSObject, UITableViewDelegate {
|
|
|
|
- weak var chatPresenter: ChatPresenter?
|
|
|
|
|
|
|
|
- func tableView(_: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
|
|
+ func tableView(_: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
let row = indexPath.row
|
|
let row = indexPath.row
|
|
- chatPresenter?.displayChat(index: row)
|
|
|
|
|
|
+ if let chatId = chatList?.getChatId(index: row) {
|
|
|
|
+ coordinator?.showChat(chatId: chatId)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|