浏览代码

do not ask 'start chat with ...?' when a chat with the contact acutally exists

B. Petersen 5 年之前
父节点
当前提交
b3435d5d8a

+ 13 - 7
deltachat-ios/Controller/ChatViewController.swift

@@ -596,13 +596,19 @@ class ChatViewController: MessagesViewController {
     }
 
     private func askToChatWith(email: String) {
-        confirmationAlert(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), email),
-                          actionTitle: String.localized("start_chat"),
-                          actionHandler: { _ in
-                            self.dismiss(animated: true, completion: nil)
-                            let contactId = self.dcContext.createContact(name: "", email: email)
-                            let chatId = self.dcContext.createChatByContactId(contactId: contactId)
-                            self.coordinator?.showChat(chatId: chatId)})
+        let contactId = self.dcContext.createContact(name: "", email: email)
+        if dcContext.getChatIdByContactId(contactId: contactId) != 0 {
+            self.dismiss(animated: true, completion: nil)
+            let chatId = self.dcContext.createChatByContactId(contactId: contactId)
+            self.coordinator?.showChat(chatId: chatId)
+        } else {
+            confirmationAlert(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), email),
+                              actionTitle: String.localized("start_chat"),
+                              actionHandler: { _ in
+                                self.dismiss(animated: true, completion: nil)
+                                let chatId = self.dcContext.createChatByContactId(contactId: contactId)
+                                self.coordinator?.showChat(chatId: chatId)})
+        }
     }
 
     private func askToDeleteMessage(id: Int) {

+ 4 - 16
deltachat-ios/Controller/ContactDetailViewController.swift

@@ -146,7 +146,7 @@ class ContactDetailViewController: UITableViewController {
             handleCellAction(for: indexPath.row)
         case .startChat:
             let contactId = viewModel.contactId
-            askToChatWith(contactId: contactId)
+            chatWith(contactId: contactId)
         case .sharedChats:
             let chatId = viewModel.getSharedChatIdAt(indexPath: indexPath)
             coordinator?.showChat(chatId: chatId)
@@ -260,21 +260,9 @@ extension ContactDetailViewController {
         }
     }
 
-    private func askToChatWith(contactId: Int) {
-        let dcContact = DcContact(id: contactId)
-        let alert = UIAlertController(title: String.localizedStringWithFormat(
-            String.localized("ask_start_chat_with"), dcContact.nameNAddr),
-                                      message: nil,
-                                      preferredStyle: .safeActionSheet)
-        alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
-            self.dismiss(animated: true, completion: nil)
-            let chatId = self.viewModel.context.createChatByContactId(contactId: contactId)
-            self.coordinator?.showChat(chatId: chatId)
-        }))
-        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
-            self.dismiss(animated: true, completion: nil)
-        }))
-        present(alert, animated: true, completion: nil)
+    private func chatWith(contactId: Int) {
+        let chatId = self.viewModel.context.createChatByContactId(contactId: contactId)
+        self.coordinator?.showChat(chatId: chatId)
     }
 
 }

+ 15 - 10
deltachat-ios/Controller/NewChatViewController.swift

@@ -291,18 +291,23 @@ class NewChatViewController: UITableViewController {
     }
 
     private func askToChatWith(contactId: Int) {
-        let dcContact = DcContact(id: contactId)
-        let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr),
-                                      message: nil,
-                                      preferredStyle: .safeActionSheet)
-        alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
+        if dcContext.getChatIdByContactId(contactId: contactId) != 0 {
             self.dismiss(animated: true, completion: nil)
             self.coordinator?.showNewChat(contactId: contactId)
-        }))
-        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
-            self.dismiss(animated: true, completion: nil)
-        }))
-        present(alert, animated: true, completion: nil)
+        } else {
+            let dcContact = DcContact(id: contactId)
+            let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr),
+                                          message: nil,
+                                          preferredStyle: .safeActionSheet)
+            alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { _ in
+                self.dismiss(animated: true, completion: nil)
+                self.coordinator?.showNewChat(contactId: contactId)
+            }))
+            alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
+                self.dismiss(animated: true, completion: nil)
+            }))
+            present(alert, animated: true, completion: nil)
+        }
     }
 
     private func showChatAt(row: Int) {