Преглед изворни кода

Merge pull request #370 from deltachat/streamline-qr

streamline qr-codes
cyBerta пре 5 година
родитељ
комит
ea29090630

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

@@ -367,36 +367,6 @@ class NewChatViewController: UITableViewController {
     }
 }
 
-extension NewChatViewController: QrCodeReaderDelegate {
-    func handleQrCode(_ code: String) {
-        logger.info("decoded: \(code)")
-
-        let check = dc_check_qr(mailboxPointer, code)!
-        logger.info("got ver: \(check)")
-
-        if dc_lot_get_state(check) == DC_QR_ASK_VERIFYGROUP {
-            hud = ProgressHud(String.localized("synchronizing_account"), in: view)
-            DispatchQueue.global(qos: .userInitiated).async {
-                let id = dc_join_securejoin(mailboxPointer, code)
-
-                DispatchQueue.main.async {
-                    self.dismiss(animated: true) {
-                        self.coordinator?.showChat(chatId: Int(id))
-                        // self.chatDisplayer?.displayChatForId(chatId: Int(id))
-                    }
-                }
-            }
-        } else {
-            let alert = UIAlertController(title: String.localized("invalid_qr_code"), message: code, preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: String.localized("OK"), style: .default, handler: { _ in
-                self.dismiss(animated: true, completion: nil)
-            }))
-            present(alert, animated: true, completion: nil)
-        }
-        dc_lot_unref(check)
-    }
-}
-
 extension NewChatViewController: ContactListDelegate {
     func deviceContactsImported() {
         contactIds = Utils.getContactIds()

+ 19 - 8
deltachat-ios/Controller/QrViewController.swift

@@ -140,17 +140,28 @@ class QrViewController: UITableViewController, QrCodeReaderDelegate {
         switch state {
         case DC_QR_ASK_VERIFYCONTACT:
             let nameAndAddress = DcContact(id: qrParsed.id).nameNAddr
-            joinSecureJoin(alertMessage: String.localizedStringWithFormat(String.localized("qrscan_ask_fingerprint_ask_oob"), nameAndAddress), code: code)
+            joinSecureJoin(alertMessage: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), nameAndAddress), code: code)
+
         case DC_QR_ASK_VERIFYGROUP:
-            if let group = qrParsed.text1?.replacingOccurrences(of: "+", with: " ") {
-                joinSecureJoin(alertMessage: String.localizedStringWithFormat(String.localized("qrscan_ask_join_group"), group), code: code)
-            }
+            let groupName = qrParsed.text1 ?? "ErrGroupName"
+            joinSecureJoin(alertMessage: String.localizedStringWithFormat(String.localized("qrscan_ask_join_group"), groupName), code: code)
+
+        case DC_QR_TEXT:
+            let msg = String.localizedStringWithFormat(String.localized("qrscan_contains_text"), qrParsed.text1 ?? "")
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
+
         default:
-            let alertMessage = "QR code scanning for type " + String(state) + " is not yet implemented."
-            let alert = UIAlertController(title: alertMessage,
-                                          message: nil,
-                                          preferredStyle: .alert)
+            var msg = String.localizedStringWithFormat(String.localized("qrscan_contains_text"), code)
+            if state == DC_QR_ERROR {
+                if let errorMsg = qrParsed.text1 {
+                    msg = errorMsg + "\n\n" + msg
+                }
+            }
+            let alert = UIAlertController(title: msg, message: nil, preferredStyle: .alert)
             alert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+            present(alert, animated: true, completion: nil)
         }
 
     }

+ 1 - 4
tools/untranslated.xml

@@ -2,14 +2,11 @@
 <resources>
 
     <!-- iOS specific untranslated strings -->
-    <string name="hide">Hide</string>
-    <string name="start_chat">Start Chat</string>
+    <string name="start_chat">Start chat</string>
     <string name="dismiss">Dismiss</string>
     <string name="photo">Photo</string>
     <string name="import_contacts">Import device contacts</string>
     <string name="import_contacts_message">To chat with contacts from your device open the settings menu and enable the Contacts option</string>
-    <string name="synchronizing_account">Synchronizing account</string>
-    <string name="invalid_qr_code">Invalid group QR code</string>
     <string name="no_account_setup">No account set up</string>
     <string name="delete_account">Delete account</string>
     <string name="delete_account_message">Are you sure you want to delete your account data?</string>