Просмотр исходного кода

use DCContext in NewProfileViewController for secure join

cyberta 6 лет назад
Родитель
Сommit
1d73faa2c7

+ 2 - 2
deltachat-ios/AppDelegate.swift

@@ -17,12 +17,12 @@ enum ApplicationState {
 
 @UIApplicationMain
 class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
+    private let dcContext = DCContext()
     var appCoordinator: AppCoordinator!
     // static let appCoordinatorDeprecated = AppCoordinatorDeprecated()
     static var progress: Float = 0 // TODO: delete
     static var lastErrorDuringConfig: String?
     private var backgroundTask: UIBackgroundTaskIdentifier = .invalid
-    private let dcContext = DCContext()
 
     var reachability = Reachability()!
     var window: UIWindow?
@@ -68,7 +68,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         //       - second param remains nil (user data for more than one mailbox)
         open()
         let isConfigured = dc_is_configured(mailboxPointer) != 0
-        appCoordinator = AppCoordinator(window: window)
+        appCoordinator = AppCoordinator(window: window, dcContext: dcContext)
         appCoordinator.start()
         UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
         start()

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

@@ -1,12 +1,20 @@
 import Foundation
 import UIKit
 
-
 class NewProfileViewController: UIViewController, QrCodeReaderDelegate {
 
 	weak var coordinator: ProfileCoordinator?
 	let qrCodeReaderController = QrCodeReaderController()
+	var dcContext: DCContext 
+
+	init(dcContext: DCContext) {
+		self.dcContext = dcContext
+		super.init(nibName: nil, bundle: nil)
+	}
 
+	required init?(coder _: NSCoder) {
+		fatalError("init(coder:) has not been implemented")
+	}
 
 	var contact: DCContact? {
 		// This is nil if we do not have an account setup yet
@@ -20,12 +28,7 @@ class NewProfileViewController: UIViewController, QrCodeReaderDelegate {
 		if !DCConfig.configured {
 			return nil
 		}
-		
-		if let cString = dc_get_securejoin_qr(mailboxPointer, 0) {
-			return String(cString: cString)
-		}
-		
-		return nil
+		return dcContext.getSecurejoinQr(chatId: 0)
 	}
 
 	override func loadView() {
@@ -68,6 +71,9 @@ class NewProfileViewController: UIViewController, QrCodeReaderDelegate {
 		if let ctrl = navigationController {
 			ctrl.viewControllers.removeLast()
 		}
+		DispatchQueue.main.async {
+			self.dcContext.joinSecurejoin(qrCode: code)
+		}
 	}
 
 	private func createInfoLabel() -> UIView {

+ 4 - 2
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -5,6 +5,7 @@ import MobileCoreServices
 
 class AppCoordinator: NSObject, Coordinator {
     private let window: UIWindow
+    private let dcContext: DCContext
 
     var rootViewController: UIViewController {
         return tabBarController
@@ -48,7 +49,7 @@ class AppCoordinator: NSObject, Coordinator {
     }()
 
     private lazy var profileController: UIViewController = {
-        let controller = NewProfileViewController()
+        let controller = NewProfileViewController(dcContext: dcContext)
         let nav = DCNavigationController(rootViewController: controller)
         let settingsImage = UIImage(named: "report_card")
         nav.tabBarItem = UITabBarItem(title: String.localized("my_profile"), image: settingsImage, tag: 2)
@@ -80,8 +81,9 @@ class AppCoordinator: NSObject, Coordinator {
         return nav
     }()
 
-    init(window: UIWindow) {
+    init(window: UIWindow, dcContext: DCContext) {
         self.window = window
+        self.dcContext = dcContext
         super.init()
         window.rootViewController = rootViewController
         window.makeKeyAndVisible()