IOS-1618 remove MySelfOperation and KickOffMySelfProtocol IOS-1618
authorAlejandro Gelos <agp@pep.security>
Wed, 29 May 2019 13:57:03 +0200
branchIOS-1618
changeset 88422e388c2461a5
parent 8841 e6ae600d4a3f
child 8869 f874582427f4
IOS-1618 remove MySelfOperation and KickOffMySelfProtocol
pEpForiOS/AppDelegate.swift
pEpForiOS/UI/Login/LoginViewController.swift
pEpForiOS/UI/Login/ViewModel/LoginViewModel.swift
pEpForiOS/UI/Util/BaseTableViewController.swift
pEpForiOS/Util/AppConfig.swift
     1.1 --- a/pEpForiOS/AppDelegate.swift	Tue May 28 10:43:19 2019 +0200
     1.2 +++ b/pEpForiOS/AppDelegate.swift	Wed May 29 13:57:03 2019 +0200
     1.3 @@ -104,28 +104,6 @@
     1.4          }
     1.5      }
     1.6  
     1.7 -    func kickOffMySelf() {
     1.8 -        mySelfTaskId = application.beginBackgroundTask(expirationHandler: { [unowned self] in
     1.9 -            Log.shared.log("mySelfTaskId with ID expired.")
    1.10 -            // We migh want to call some (yet unexisting) emergency shutdown on
    1.11 -            // ReplicationService here here that brutally shuts down everything.
    1.12 -            self.application.endBackgroundTask(
    1.13 -                UIBackgroundTaskIdentifier(rawValue:self.mySelfTaskId.rawValue))
    1.14 -        })
    1.15 -        let op = MySelfOperation()
    1.16 -        op.completionBlock = { [unowned self] in
    1.17 -            // We might be the last service that finishes, so we have to cleanup.
    1.18 -            self.cleanupPEPSessionIfNeeded()
    1.19 -            if self.mySelfTaskId == UIBackgroundTaskIdentifier.invalid {
    1.20 -                return
    1.21 -            }
    1.22 -            self.application.endBackgroundTask(
    1.23 -                UIBackgroundTaskIdentifier(rawValue: self.mySelfTaskId.rawValue))
    1.24 -            self.mySelfTaskId = UIBackgroundTaskIdentifier.invalid
    1.25 -        }
    1.26 -        mySelfQueue.addOperation(op)
    1.27 -    }
    1.28 -
    1.29      func loadCoreDataStack() {
    1.30          let objectModel = MessageModelData.MessageModelData()
    1.31          let options = [NSMigratePersistentStoresAutomaticallyOption: true,
    1.32 @@ -177,10 +155,8 @@
    1.33      }
    1.34  
    1.35      private func setupServices() {
    1.36 -        let theAppConfig = AppConfig(
    1.37 -            mySelfer: self,
    1.38 -            errorPropagator: errorPropagator,
    1.39 -            oauth2AuthorizationFactory: oauth2Provider)
    1.40 +        let theAppConfig = AppConfig( errorPropagator: errorPropagator,
    1.41 +                                      oauth2AuthorizationFactory: oauth2Provider)
    1.42          appConfig = theAppConfig
    1.43          // This is a very dirty hack!! See SecureWebViewController docs for details.
    1.44          SecureWebViewController.appConfigDirtyHack = theAppConfig
    1.45 @@ -190,10 +166,8 @@
    1.46          // TODO: IOS-1276 set MessageModelConfig.logger
    1.47  
    1.48          loadCoreDataStack()
    1.49 -        messageModelService = MessageModelService(
    1.50 -            mySelfer: self,
    1.51 -            errorPropagator: errorPropagator,
    1.52 -            notifyHandShakeDelegate: notifyHandshakeDelegate)
    1.53 +        messageModelService = MessageModelService(errorPropagator: errorPropagator,
    1.54 +                                                  notifyHandShakeDelegate: notifyHandshakeDelegate)
    1.55          messageModelService?.delegate = self
    1.56      }
    1.57  
    1.58 @@ -272,8 +246,6 @@
    1.59  
    1.60      func applicationDidEnterBackground(_ application: UIApplication) {
    1.61          shouldDestroySession = true
    1.62 -        // generate keys in the background
    1.63 -        kickOffMySelf()
    1.64          stopUsingPepSession()
    1.65      }
    1.66  
    1.67 @@ -294,7 +266,6 @@
    1.68          shouldDestroySession = false
    1.69  
    1.70          shutdownAndPrepareServicesForRestart()
    1.71 -        kickOffMySelf()
    1.72          UserNotificationTool.resetApplicationIconBadgeNumber()
    1.73          // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    1.74      }
    1.75 @@ -357,14 +328,6 @@
    1.76      }
    1.77  }
    1.78  
    1.79 -// MARK: - KickOffMySelfProtocol
    1.80 -
    1.81 -extension AppDelegate: KickOffMySelfProtocol {
    1.82 -    func startMySelf() {
    1.83 -        kickOffMySelf()
    1.84 -    }
    1.85 -}
    1.86 -
    1.87  // MARK: - ReplicationServiceDelegate
    1.88  
    1.89  extension AppDelegate: MessageModelServiceDelegate {
     2.1 --- a/pEpForiOS/UI/Login/LoginViewController.swift	Tue May 28 10:43:19 2019 +0200
     2.2 +++ b/pEpForiOS/UI/Login/LoginViewController.swift	Wed May 29 13:57:03 2019 +0200
     2.3 @@ -222,7 +222,7 @@
     2.4              let oauth = appConfig.oauth2AuthorizationFactory.createOAuth2Authorizer()
     2.5              loginViewModel.loginWithOAuth2(
     2.6                  viewController: self, emailAddress: email, userName: username,
     2.7 -                mySelfer: appConfig.mySelfer, oauth2Authorizer: oauth)
     2.8 +                oauth2Authorizer: oauth)
     2.9          } else {
    2.10              guard let pass = password.text, pass != "" else {
    2.11                  handleLoginError(error: LoginViewController.LoginError.missingPassword,
    2.12 @@ -231,8 +231,7 @@
    2.13              }
    2.14  
    2.15              loginViewModel.login(
    2.16 -                accountName: email, userName: username, password: pass,
    2.17 -                mySelfer: appConfig.mySelfer)
    2.18 +                accountName: email, userName: username, password: pass)
    2.19          }
    2.20      }
    2.21  
     3.1 --- a/pEpForiOS/UI/Login/ViewModel/LoginViewModel.swift	Tue May 28 10:43:19 2019 +0200
     3.2 +++ b/pEpForiOS/UI/Login/ViewModel/LoginViewModel.swift	Wed May 29 13:57:03 2019 +0200
     3.3 @@ -20,7 +20,6 @@
     3.4      struct OAuth2Parameters {
     3.5          let emailAddress: String
     3.6          let userName: String
     3.7 -        let mySelfer: KickOffMySelfProtocol
     3.8      }
     3.9  
    3.10      /// Holding both the data of the current account in verification,
    3.11 @@ -35,12 +34,6 @@
    3.12      weak var loginViewModelOAuth2ErrorDelegate: LoginViewModelOAuth2ErrorDelegate?
    3.13  
    3.14      /**
    3.15 -     The last mySelfer, as indicated by login(), so after account verification,
    3.16 -     a key can be generated.
    3.17 -     */
    3.18 -    var mySelfer: KickOffMySelfProtocol?
    3.19 -
    3.20 -    /**
    3.21       An OAuth2 process lives longer than the method call, so this object needs to survive.
    3.22       */
    3.23      var currentOauth2Authorizer: OAuth2AuthorizationProtocol?
    3.24 @@ -68,10 +61,9 @@
    3.25          viewController: UIViewController,
    3.26          emailAddress: String,
    3.27          userName: String,
    3.28 -        mySelfer: KickOffMySelfProtocol,
    3.29          oauth2Authorizer: OAuth2AuthorizationProtocol) {
    3.30          lastOAuth2Parameters = OAuth2Parameters(
    3.31 -            emailAddress: emailAddress, userName: userName, mySelfer: mySelfer)
    3.32 +            emailAddress: emailAddress, userName: userName)
    3.33  
    3.34          oauth2Model.delegate = self
    3.35          oauth2Model.authorize(authorizer: oauth2Authorizer, emailAddress: emailAddress,
    3.36 @@ -88,9 +80,7 @@
    3.37       after account setup
    3.38       */
    3.39      func login(accountName: String, userName: String, loginName: String? = nil,
    3.40 -               password: String? = nil, accessToken: OAuth2AccessTokenProtocol? = nil,
    3.41 -               mySelfer: KickOffMySelfProtocol) {
    3.42 -        self.mySelfer = mySelfer
    3.43 +               password: String? = nil, accessToken: OAuth2AccessTokenProtocol? = nil) {
    3.44          let acSettings = AccountSettings(accountName: accountName, provider: nil,
    3.45                                           flags: AS_FLAG_USE_ANY, credentials: nil)
    3.46          acSettings.lookupCompletion() { [weak self] settings in
    3.47 @@ -194,7 +184,7 @@
    3.48                      return
    3.49                  }
    3.50                  login(accountName: oauth2Params.emailAddress, userName: oauth2Params.userName,
    3.51 -                      accessToken: token, mySelfer: oauth2Params.mySelfer)
    3.52 +                      accessToken: token)
    3.53              } else {
    3.54                  loginViewModelOAuth2ErrorDelegate?.handle(
    3.55                      oauth2Error: OAuth2AuthViewModelError.noToken)
    3.56 @@ -243,7 +233,6 @@
    3.57              do {
    3.58                  try verifiableAccount?.save()
    3.59                  informAccountVerificationResultDelegate(error: nil)
    3.60 -                mySelfer?.startMySelf()
    3.61              } catch {
    3.62                  Log.shared.errorAndCrash("%@", error.localizedDescription)
    3.63              }
     4.1 --- a/pEpForiOS/UI/Util/BaseTableViewController.swift	Tue May 28 10:43:19 2019 +0200
     4.2 +++ b/pEpForiOS/UI/Util/BaseTableViewController.swift	Wed May 29 13:57:03 2019 +0200
     4.3 @@ -21,7 +21,6 @@
     4.4  
     4.5                  // We have no config. Return nonsense.
     4.6                  return AppConfig(
     4.7 -                    mySelfer: self,
     4.8                      errorPropagator: ErrorPropagator(),
     4.9                      oauth2AuthorizationFactory: OAuth2ProviderFactory().oauth2Provider())
    4.10              }
    4.11 @@ -124,11 +123,4 @@
    4.12              }
    4.13          }
    4.14      }
    4.15 -
    4.16  }
    4.17 -
    4.18 -extension BaseTableViewController: KickOffMySelfProtocol {
    4.19 -    func startMySelf() {
    4.20 -        Log.shared.errorAndCrash("No appConfig?")
    4.21 -    }
    4.22 -}
     5.1 --- a/pEpForiOS/Util/AppConfig.swift	Tue May 28 10:43:19 2019 +0200
     5.2 +++ b/pEpForiOS/Util/AppConfig.swift	Wed May 29 13:57:03 2019 +0200
     5.3 @@ -16,20 +16,14 @@
     5.4  
     5.5      let errorPropagator : ErrorPropagator
     5.6  
     5.7 -    /**
     5.8 -     The UI can request key generation.
     5.9 -     */
    5.10 -    let mySelfer: KickOffMySelfProtocol
    5.11  
    5.12      /**
    5.13       For the views to kick off oauth2 requests.
    5.14       */
    5.15      let oauth2AuthorizationFactory: OAuth2AuthorizationFactoryProtocol
    5.16  
    5.17 -    init(mySelfer: KickOffMySelfProtocol,
    5.18 -         errorPropagator: ErrorPropagator,
    5.19 +    init(errorPropagator: ErrorPropagator,
    5.20           oauth2AuthorizationFactory: OAuth2AuthorizationFactoryProtocol) {
    5.21 -        self.mySelfer = mySelfer
    5.22          self.errorPropagator = errorPropagator
    5.23          self.oauth2AuthorizationFactory = oauth2AuthorizationFactory
    5.24          self.showedAccountsError = [:]