Explorar el Código

adding a new chat works now (including adding a new contact, if necessary).

Jonas Reinsch hace 7 años
padre
commit
919df9a659

+ 16 - 0
deltachat-ios/ChatListController.swift

@@ -8,6 +8,7 @@
 
 import UIKit
 
+
 class ChatListController: UIViewController {
     var chatList:MRChatList?
 
@@ -81,6 +82,7 @@ class ChatListController: UIViewController {
     
     @objc func addChat() {
         let ncv = NewChatViewController()
+        ncv.chatDisplayer = self
         let nav = UINavigationController(rootViewController: ncv)
         present(nav, animated: true, completion: nil)
     }
@@ -92,6 +94,7 @@ class ChatListController: UIViewController {
 }
 
 extension ChatListController: ChatPresenter {
+
     func displayChat(index: Int) {
         guard let chatList = self.chatList else {
             fatalError("chatList was nil in ChatPresenter extension")
@@ -99,12 +102,25 @@ extension ChatListController: ChatPresenter {
         
         let chatId = chatList.getChatId(index: index)
         let chatVC = ChatViewController(chatId: chatId)
+        
 
         chatVC.hidesBottomBarWhenPushed = true 
         self.navigationController?.pushViewController(chatVC, animated: true)
     }
 }
 
+extension ChatListController: ChatDisplayer {
+    func displayNewChat(contactId: Int) {
+        let chatId = mrmailbox_create_chat_by_contact_id(mailboxPointer, UInt32(contactId))
+        let chatVC = ChatViewController(chatId: Int(chatId))
+        
+        chatVC.hidesBottomBarWhenPushed = true
+        self.navigationController?.pushViewController(chatVC, animated: true)
+    }
+    
+}
+
+
 class ChatTableDataSource: NSObject, UITableViewDataSource  {
     weak var chatList:MRChatList?
     

+ 32 - 0
deltachat-ios/NewChatViewController.swift

@@ -8,8 +8,13 @@
 
 import UIKit
 
+protocol ChatDisplayer: class {
+    func displayNewChat(contactId: Int)
+}
+
 class NewChatViewController: UITableViewController {
     var contactIds: [Int] = Utils.getContactIds()
+    weak var chatDisplayer: ChatDisplayer?
 
     override func viewDidLoad() {
         super.viewDidLoad()
@@ -22,6 +27,11 @@ class NewChatViewController: UITableViewController {
         navigationItem.rightBarButtonItem = cancelButton
     }
     
+    override func viewDidAppear(_ animated: Bool) {
+        contactIds = Utils.getContactIds()
+        tableView.reloadData()
+    }
+    
     @objc func cancelButtonPressed() {
         dismiss(animated: true, completion: nil)
     }
@@ -86,6 +96,28 @@ class NewChatViewController: UITableViewController {
 
         return cell
     }
+    
+    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+        let row = indexPath.row
+        if row == 0 {
+            let newContactController = NewContactController()
+            navigationController?.pushViewController(newContactController, animated: true)
+        }
+        if row == 1 {
+            let alertController = UIAlertController(title: "Not implemented", message: "Adding groups is not yet implemented.", preferredStyle: .alert)
+            let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
+            alertController.addAction(okAction)
+            present(alertController, animated: false, completion: nil)
+            tableView.deselectRow(at: indexPath, animated: true)
+        }
+        if row > 1 {
+            let contactIndex = row - 2
+            let contactId = contactIds[contactIndex]
+            dismiss(animated: false) {
+                self.chatDisplayer?.displayNewChat(contactId: contactId)
+            }
+        }
+    }
 
 
     /*

+ 5 - 5
deltachat-ios/NewContactController.swift

@@ -54,14 +54,14 @@ class NewContactController: UITableViewController {
     }
     
     @objc func saveContactButtonPressed() {
-        dismiss(animated: true) {
-            let contactId = mrmailbox_create_contact(mailboxPointer, self.model.name, self.model.email)
-            let _ = mrmailbox_create_chat_by_contact_id(mailboxPointer, contactId)
-        }
+        let contactId = mrmailbox_create_contact(mailboxPointer, self.model.name, self.model.email)
+        navigationController?.popViewController(animated: true)
+        
+        
     }
     
     @objc func cancelButtonPressed() {
-        dismiss(animated: true, completion: nil)
+        navigationController?.popViewController(animated: true)
     }
     
     required init?(coder aDecoder: NSCoder) {