Selaa lähdekoodia

basic support for urls like mailto:abc@example.org, implement workaround for dc_lookup_contact_id_by_addr

cyberta 4 vuotta sitten
vanhempi
commit
86264b5875

+ 2 - 2
deltachat-ios/Controller/ChatListController.swift

@@ -467,9 +467,9 @@ class ChatListController: UITableViewController {
     }
     }
 
 
     // MARK: - coordinator
     // MARK: - coordinator
-    func showNewChatController() {
+    func showNewChatController(animated: Bool = true) {
         let newChatVC = NewChatViewController(dcContext: dcContext)
         let newChatVC = NewChatViewController(dcContext: dcContext)
-        navigationController?.pushViewController(newChatVC, animated: true)
+        navigationController?.pushViewController(newChatVC, animated: animated)
     }
     }
 
 
     func showChat(chatId: Int, highlightedMsg: Int? = nil, animated: Bool = true) {
     func showChat(chatId: Int, highlightedMsg: Int? = nil, animated: Bool = true) {

+ 18 - 8
deltachat-ios/Controller/NewChatViewController.swift

@@ -325,15 +325,15 @@ class NewChatViewController: UITableViewController {
         navigationController?.pushViewController(newContactController, animated: true)
         navigationController?.pushViewController(newContactController, animated: true)
     }
     }
 
 
-    private func showNewChat(contactId: Int) {
+    private func showNewChat(contactId: Int, animated: Bool = true) {
         let chatId = dcContext.createChatByContactId(contactId: contactId)
         let chatId = dcContext.createChatByContactId(contactId: contactId)
-        showChat(chatId: Int(chatId))
+        showChat(chatId: Int(chatId), animated: animated)
     }
     }
 
 
-    private func showChat(chatId: Int) {
+    private func showChat(chatId: Int, animated: Bool = true) {
         let chatViewController = ChatViewController(dcContext: dcContext, chatId: chatId)
         let chatViewController = ChatViewController(dcContext: dcContext, chatId: chatId)
-        navigationController?.pushViewController(chatViewController, animated: true)
-        navigationController?.viewControllers.remove(at: 1)
+        navigationController?.popToRootViewController(animated: false)
+        navigationController?.pushViewController(chatViewController, animated: animated)
     }
     }
 
 
     private func showContactDetail(contactId: Int) {
     private func showContactDetail(contactId: Int) {
@@ -391,9 +391,19 @@ extension NewChatViewController {
     }
     }
 
 
     private func askToChatWith(address: String) {
     private func askToChatWith(address: String) {
-        var contactId = dcContext.lookupContactIdByAddress(address)
+        // FIXME: the line below should work
+        // var contactId = dcContext.lookupContactIdByAddress(address)
+
+        // workaround:
+        let contacts: [Int] = dcContext.getContacts(flags: DC_GCL_ADD_SELF, queryString: address)
+        let index = contacts.firstIndex(where: { self.dcContext.getContact(id: $0).email == address }) ?? -1
+        var contactId = 0
+        if index >= 0 {
+            contactId = contacts[index]
+        }
+
         if contactId != 0 && dcContext.getChatIdByContactId(contactId: contactId) != 0 {
         if contactId != 0 && dcContext.getChatIdByContactId(contactId: contactId) != 0 {
-            self.showNewChat(contactId: contactId)
+            self.showNewChat(contactId: contactId, animated: false)
         } else {
         } else {
             let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), address),
             let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), address),
                                           message: nil,
                                           message: nil,
@@ -407,7 +417,7 @@ extension NewChatViewController {
                 self.showNewChat(contactId: contactId)
                 self.showNewChat(contactId: contactId)
             }))
             }))
             alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
             alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
-                self.reactivateSearchBarIfNeeded()
+                self.dismiss(animated: true, completion: nil)
             }))
             }))
             present(alert, animated: true, completion: nil)
             present(alert, animated: true, completion: nil)
         }
         }

+ 1 - 1
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -103,7 +103,7 @@ class AppCoordinator {
             if let rootController = self.tabBarController.selectedViewController as? UINavigationController {
             if let rootController = self.tabBarController.selectedViewController as? UINavigationController {
                 rootController.popToRootViewController(animated: false)
                 rootController.popToRootViewController(animated: false)
                 if let controller = rootController.viewControllers.first as? ChatListController {
                 if let controller = rootController.viewControllers.first as? ChatListController {
-                    controller.showNewChatController()
+                    controller.showNewChatController(animated: true)
                 }
                 }
             }
             }
         } else {
         } else {

+ 1 - 1
deltachat-ios/Helper/RelayHelper.swift

@@ -86,7 +86,7 @@ class RelayHelper {
                 if !body.isEmpty {
                 if !body.isEmpty {
                     mailtoDraft += "\n\n \(body)"
                     mailtoDraft += "\n\n \(body)"
                 }
                 }
-            } else if (!body.isEmpty) {
+            } else if !body.isEmpty {
                 mailtoDraft = body
                 mailtoDraft = body
             }
             }