Sfoglia il codice sorgente

diverge from android: don't show the contact list, but the chat list as root view, in case of mailto urls without an address the user can easier choose an ongoing chat

cyberta 4 anni fa
parent
commit
2bb370e274

+ 31 - 15
deltachat-ios/Controller/ChatListController.swift

@@ -394,22 +394,23 @@ class ChatListController: UITableViewController {
     }
     }
 
 
     public func handleMailto() {
     public func handleMailto() {
-        let mailtoAddress = RelayHelper.sharedInstance.mailtoAddress
-        // FIXME: the line below should work
-        // var contactId = dcContext.lookupContactIdByAddress(mailtoAddress)
-
-        // workaround:
-        let contacts: [Int] = dcContext.getContacts(flags: DC_GCL_ADD_SELF, queryString: mailtoAddress)
-        let index = contacts.firstIndex(where: { dcContext.getContact(id: $0).email == mailtoAddress }) ?? -1
-        var contactId = 0
-        if index >= 0 {
-            contactId = contacts[index]
-        }
+        if let mailtoAddress = RelayHelper.sharedInstance.mailtoAddress {
+            // FIXME: the line below should work
+            // var contactId = dcContext.lookupContactIdByAddress(mailtoAddress)
+
+            // workaround:
+            let contacts: [Int] = dcContext.getContacts(flags: DC_GCL_ADD_SELF, queryString: mailtoAddress)
+            let index = contacts.firstIndex(where: { dcContext.getContact(id: $0).email == mailtoAddress }) ?? -1
+            var contactId = 0
+            if index >= 0 {
+                contactId = contacts[index]
+            }
 
 
-        if contactId != 0 && dcContext.getChatIdByContactId(contactId: contactId) != 0 {
-            showChat(chatId: dcContext.getChatIdByContactId(contactId: contactId), animated: false)
-        } else {
-            showNewChatController(animated: false)
+            if contactId != 0 && dcContext.getChatIdByContactId(contactId: contactId) != 0 {
+                showChat(chatId: dcContext.getChatIdByContactId(contactId: contactId), animated: false)
+            } else {
+                askToChatWith(address: mailtoAddress)
+            }
         }
         }
     }
     }
 
 
@@ -449,6 +450,21 @@ class ChatListController: UITableViewController {
         present(alert, animated: true, completion: nil)
         present(alert, animated: true, completion: nil)
     }
     }
 
 
+    private func askToChatWith(address: String) {
+        let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), address),
+                                      message: nil,
+                                      preferredStyle: .safeActionSheet)
+        alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { [weak self] _ in
+            guard let self = self else { return }
+            let contactId = self.dcContext.createContact(name: nil, email: address)
+            self.showNewChat(contactId: contactId)
+        }))
+        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
+            RelayHelper.sharedInstance.finishMailto()
+        }))
+        present(alert, animated: true, completion: nil)
+    }
+
     private func askToChatWith(contactId: Int) {
     private func askToChatWith(contactId: Int) {
         let dcContact = dcContext.getContact(id: contactId)
         let dcContact = dcContext.getContact(id: contactId)
         let alert = UIAlertController(
         let alert = UIAlertController(

+ 0 - 21
deltachat-ios/Controller/NewChatViewController.swift

@@ -94,11 +94,6 @@ class NewChatViewController: UITableViewController {
     override func viewWillAppear(_ animated: Bool) {
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
         super.viewWillAppear(animated)
         deviceContactAccessGranted = CNContactStore.authorizationStatus(for: .contacts) == .authorized
         deviceContactAccessGranted = CNContactStore.authorizationStatus(for: .contacts) == .authorized
-        if RelayHelper.sharedInstance.isMailtoHandling() {
-            if let mailtoAddress = RelayHelper.sharedInstance.mailtoAddress {
-                askToChatWith(address: mailtoAddress)
-            }
-        }
     }
     }
 
 
     // MARK: - actions
     // MARK: - actions
@@ -389,22 +384,6 @@ extension NewChatViewController {
         present(alert, animated: true, completion: nil)
         present(alert, animated: true, completion: nil)
     }
     }
 
 
-    private func askToChatWith(address: String) {
-        let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), address),
-                                      message: nil,
-                                      preferredStyle: .safeActionSheet)
-        alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { [weak self] _ in
-            guard let self = self else { return }
-            let contactId = self.dcContext.createContact(name: nil, email: address)
-            self.showNewChat(contactId: contactId)
-        }))
-        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { [weak self] _ in
-            RelayHelper.sharedInstance.finishMailto()
-            self?.navigationController?.popToRootViewController(animated: true)
-        }))
-        present(alert, animated: true, completion: nil)
-    }
-
     private func askToChatWith(contactId: Int) {
     private func askToChatWith(contactId: Int) {
         if dcContext.getChatIdByContactId(contactId: contactId) != 0 {
         if dcContext.getChatIdByContactId(contactId: contactId) != 0 {
             self.dismiss(animated: true, completion: nil)
             self.dismiss(animated: true, completion: nil)