Parcourir la source

send autocrypt setup message and show the setup code

B. Petersen il y a 5 ans
Parent
commit
852bfb4040
1 fichiers modifiés avec 27 ajouts et 6 suppressions
  1. 27 6
      deltachat-ios/Controller/SettingsController.swift

+ 27 - 6
deltachat-ios/Controller/SettingsController.swift

@@ -220,13 +220,34 @@ internal final class SettingsViewController: QuickTableViewController {
     }
 
     private func sendAsm(_: Row) {
-        let alert = UIAlertController(title: String.localized("autocrypt_send_asm_explain_before"), message: nil, preferredStyle: .actionSheet)
-        alert.addAction(UIAlertAction(title: String.localized("autocrypt_send_asm_title"), style: .default, handler: { _ in
-            //dcContext.intiateKeyTransfer()
-            self.dismiss(animated: true, completion: nil)
+        let askAlert = UIAlertController(title: String.localized("autocrypt_send_asm_explain_before"), message: nil, preferredStyle: .actionSheet)
+        askAlert.addAction(UIAlertAction(title: String.localized("autocrypt_send_asm_title"), style: .default, handler: { _ in
+            let waitAlert = UIAlertController(title: String.localized("one_moment"), message: nil, preferredStyle: .alert)
+            waitAlert.addAction(UIAlertAction(title: String.localized("cancel"), style: .default, handler: { _ in self.dcContext.stopOngoingProcess() }))
+            self.present(waitAlert, animated: true, completion: nil)
+            DispatchQueue.global(qos: .background).async {
+                let sc = self.dcContext.intiateKeyTransfer()
+                DispatchQueue.main.async {
+                    waitAlert.dismiss(animated: true, completion: nil)
+                    guard var sc = sc else {
+                        return
+                    }
+                    if sc.count == 44 {
+                        // format setup code to the typical 3 x 3 numbers
+                        sc = sc.substring(0, 4) + "  -  " + sc.substring(5, 9) + "  -  " + sc.substring(10, 14) + "  -\n\n" +
+                            sc.substring(15, 19) + "  -  " + sc.substring(20, 24) + "  -  " + sc.substring(25, 29) + "  -\n\n" +
+                            sc.substring(30, 34) + "  -  " + sc.substring(35, 39) + "  -  " + sc.substring(40, 44)
+                    }
+
+                    let text = String.localizedStringWithFormat(String.localized("autocrypt_send_asm_explain_after"), sc)
+                    let showAlert = UIAlertController(title: text, message: nil, preferredStyle: .alert)
+                    showAlert.addAction(UIAlertAction(title: String.localized("ok"), style: .default, handler: nil))
+                    self.present(showAlert, animated: true, completion: nil)
+                }
+            }
         }))
-        alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
-        present(alert, animated: true, completion: nil)
+        askAlert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
+        present(askAlert, animated: true, completion: nil)
     }
 
     private func configure(_: Row) {