pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
branchIOSAD-23-crash-or-merge-issues-deleting-mails
changeset 2850 3c5024ebf882
parent 2845 1db827abc7c8
child 2854 9c21ca9432a6
     1.1 --- a/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Thu Aug 24 11:35:14 2017 +0200
     1.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Thu Aug 24 12:08:08 2017 +0200
     1.3 @@ -385,68 +385,89 @@
     1.4      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     1.5          switch segueIdentifier(for: segue) {
     1.6          case .segueReply:
     1.7 -            if let nav = segue.destination as? UINavigationController,
     1.8 +            guard let nav = segue.destination as? UINavigationController,
     1.9                  let destination = nav.topViewController as? ComposeTableViewController,
    1.10                  let cell = sender as? EmailListViewCell,
    1.11                  let indexPath = self.tableView.indexPath(for: cell),
    1.12 -                let email = cell.messageAt(indexPath: indexPath, config: config) {
    1.13 -                destination.composeMode = .replyFrom
    1.14 -                destination.appConfig = config?.appConfig
    1.15 -                destination.originalMessage = email
    1.16 +                let email = cell.messageAt(indexPath: indexPath, config: config) else {
    1.17 +                    Log.shared.errorAndCrash(component: #function, errorString: "Segue issue")
    1.18 +                    return
    1.19              }
    1.20 +            destination.appConfig = appConfig
    1.21 +            destination.composeMode = .replyFrom
    1.22 +            destination.originalMessage = email
    1.23          case .segueReplyAll:
    1.24 -            if let nav = segue.destination as? UINavigationController,
    1.25 +            guard let nav = segue.destination as? UINavigationController,
    1.26                  let destination = nav.topViewController as? ComposeTableViewController,
    1.27                  let cell = sender as? EmailListViewCell,
    1.28                  let indexPath = self.tableView.indexPath(for: cell),
    1.29 -                let email = cell.messageAt(indexPath: indexPath, config: config) {
    1.30 -                destination.composeMode = .replyAll
    1.31 -                destination.appConfig = config?.appConfig
    1.32 -                destination.originalMessage = email
    1.33 +                let email = cell.messageAt(indexPath: indexPath, config: config)  else {
    1.34 +                    Log.shared.errorAndCrash(component: #function, errorString: "Segue issue")
    1.35 +                    return
    1.36              }
    1.37 -            break
    1.38 +            destination.appConfig = appConfig
    1.39 +            destination.composeMode = .replyAll
    1.40 +            destination.originalMessage = email
    1.41          case .segueShowEmail:
    1.42 -            if let vc = segue.destination as? EmailViewController,
    1.43 +            guard let vc = segue.destination as? EmailViewController,
    1.44                  let cell = sender as? EmailListViewCell,
    1.45                  let indexPath = self.tableView.indexPath(for: cell),
    1.46 -                let email = cell.messageAt(indexPath: indexPath, config: config) {
    1.47 -                vc.appConfig = config?.appConfig
    1.48 -                vc.message = email
    1.49 -                vc.folderShow = viewModel?.folderToShow
    1.50 -                vc.messageId = indexPath.row
    1.51 +                let email = cell.messageAt(indexPath: indexPath, config: config) else {
    1.52 +                    Log.shared.errorAndCrash(component: #function, errorString: "Segue issue")
    1.53 +                    return
    1.54              }
    1.55 -            break
    1.56 +            vc.appConfig = appConfig
    1.57 +            vc.message = email
    1.58 +            vc.folderShow = viewModel?.folderToShow
    1.59 +            vc.messageId = indexPath.row
    1.60          case .segueForward:
    1.61 -            if let nav = segue.destination as? UINavigationController,
    1.62 +            guard let nav = segue.destination as? UINavigationController,
    1.63                  let destination = nav.topViewController as? ComposeTableViewController,
    1.64                  let cell = sender as? EmailListViewCell,
    1.65                  let indexPath = self.tableView.indexPath(for: cell),
    1.66 -                let email = cell.messageAt(indexPath: indexPath, config: config) {
    1.67 -                destination.composeMode = .forward
    1.68 -                destination.appConfig = config?.appConfig
    1.69 -                destination.originalMessage = email
    1.70 +                let email = cell.messageAt(indexPath: indexPath, config: config) else {
    1.71 +                    Log.shared.errorAndCrash(component: #function, errorString: "Segue issue")
    1.72 +                    return
    1.73              }
    1.74 +            destination.composeMode = .forward
    1.75 +            destination.appConfig = appConfig
    1.76 +            destination.originalMessage = email
    1.77 +        case .segueFilter:
    1.78 +            guard let destiny = segue.destination as? FilterTableViewController  else {
    1.79 +                Log.shared.errorAndCrash(component: #function, errorString: "Segue issue")
    1.80 +                return
    1.81 +            }
    1.82 +            destiny.appConfig = appConfig
    1.83 +            destiny.filterDelegate = viewModel
    1.84 +            destiny.inFolder = false
    1.85 +            destiny.filterEnabled = viewModel?.folderToShow?.filter
    1.86 +            destiny.hidesBottomBarWhenPushed = true
    1.87 +        case .segueAddNewAccount:
    1.88 +            guard let vc = segue.destination as? LoginTableViewController  else {
    1.89 +                Log.shared.errorAndCrash(component: #function, errorString: "Segue issue")
    1.90 +                return
    1.91 +            }
    1.92 +            vc.appConfig = appConfig
    1.93 +            vc.hidesBottomBarWhenPushed = true
    1.94              break
    1.95 -        case .segueFilter:
    1.96 -            if let destiny = segue.destination as? FilterTableViewController {
    1.97 -                destiny.appConfig = self.appConfig
    1.98 -                destiny.filterDelegate = self.viewModel
    1.99 -                destiny.inFolder = false
   1.100 -                destiny.filterEnabled = self.viewModel?.folderToShow?.filter
   1.101 -                destiny.hidesBottomBarWhenPushed = true
   1.102 +        case .segueFolderViews:
   1.103 +            guard let vC = segue.destination as? FolderTableViewController  else {
   1.104 +                Log.shared.errorAndCrash(component: #function, errorString: "Segue issue")
   1.105 +                return
   1.106              }
   1.107 +            vC.appConfig = appConfig
   1.108 +            vC.hidesBottomBarWhenPushed = true
   1.109              break
   1.110 -        case .segueAddNewAccount:
   1.111 -            if let vc = segue.destination as? LoginTableViewController {
   1.112 -                vc.appConfig = config?.appConfig
   1.113 -                vc.hidesBottomBarWhenPushed = true
   1.114 +        case .segueCompose:
   1.115 +            guard let nav = segue.destination as? UINavigationController,
   1.116 +                let destination = nav.rootViewController as? ComposeTableViewController else {
   1.117 +                    Log.shared.errorAndCrash(component: #function, errorString: "Segue issue")
   1.118 +                    return
   1.119              }
   1.120 -        case .segueFolderViews:
   1.121 -            if let vC = segue.destination as? FolderTableViewController {
   1.122 -                vC.appConfig = config?.appConfig
   1.123 -                vC.hidesBottomBarWhenPushed = true
   1.124 -            }
   1.125 -        case .segueEditAccounts, .segueCompose, .noSegue:
   1.126 +            destination.appConfig = appConfig
   1.127 +            destination.composeMode = .normal
   1.128 +        default:
   1.129 +            Log.shared.errorAndCrash(component: #function, errorString: "Unhandled segue")
   1.130              break
   1.131          }
   1.132      }