Explorar o código

Merge pull request #244 from deltachat/ask-start-chat

show alert before chat with contact in new chat context (#240)
björn petersen %!s(int64=5) %!d(string=hai) anos
pai
achega
aa34c1b7ad
Modificáronse 1 ficheiros con 18 adicións e 3 borrados
  1. 18 3
      deltachat-ios/Controller/NewChatViewController.swift

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

@@ -269,16 +269,31 @@ 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: .alert)
+        alert.addAction(UIAlertAction(title: String.localized("ok"), 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) {
         if searchController.isActive {
             // edge case: when searchController is active but searchBar is empty -> filteredContacts is empty, so we fallback to contactIds
             let contactId = isFiltering() ? filteredContacts[row].contact.id : contactIds[row]
             searchController.dismiss(animated: false, completion: {
-                self.coordinator?.showNewChat(contactId: contactId)
+                self.askToChatWith(contactId: contactId)
             })
         } else {
             let contactId = contactIds[row]
-            coordinator?.showNewChat(contactId: contactId)
+            self.askToChatWith(contactId: contactId)
         }
     }
 
@@ -342,7 +357,7 @@ extension NewChatViewController: QrCodeReaderDelegate {
             }
         } else {
             let alert = UIAlertController(title: String.localized("invalid_qr_code"), message: code, preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: String.localized("OK"), style: .cancel, handler: { _ in
+            alert.addAction(UIAlertAction(title: String.localized("OK"), style: .default, handler: { _ in
                 self.dismiss(animated: true, completion: nil)
             }))
             present(alert, animated: true, completion: nil)