pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
author Xavier Algarra <xavier@pep-project.org>
Mon, 10 Jul 2017 16:38:16 +0200
changeset 2404 092e3013db61
parent 2369 6ab35cb4c20f
child 2425 dfdfba5c4f2a
permissions -rw-r--r--
IOS-340 code clean
dirk@30
     1
//
dirk@30
     2
//  EmailListViewController.swift
dirk@30
     3
//  pEpForiOS
dirk@30
     4
//
dirk@30
     5
//  Created by Dirk Zimmermann on 16/04/16.
dirk@30
     6
//  Copyright © 2016 p≡p Security S.A. All rights reserved.
dirk@30
     7
//
dirk@30
     8
dirk@30
     9
import Foundation
dirk@30
    10
import UIKit
dirk@31
    11
import CoreData
dirk@810
    12
import MessageModel
dirk@810
    13
igor@1260
    14
struct EmailListConfig {
igor@1338
    15
    var appConfig: AppConfig?
dirk@1333
    16
igor@1260
    17
    /** The folder to display, if it exists */
igor@1260
    18
    var folder: Folder?
dirk@1906
    19
dirk@1906
    20
    let imageProvider = IdentityImageProvider()
igor@1260
    21
}
dirk@30
    22
xavier@2369
    23
class EmailListViewController: UITableViewController {
dirk@583
    24
    struct UIState {
dirk@583
    25
        var isSynching: Bool = false
dirk@583
    26
    }
dirk@30
    27
dirk@1344
    28
    var config: EmailListConfig?
xavier@2362
    29
    var viewModel: EmailListViewModel?
dirk@275
    30
    var state = UIState()
igor@1301
    31
    let searchController = UISearchController(searchResultsController: nil)
xavier@2363
    32
    //let cellsInUse = NSCache<NSString, EmailListViewCell>()
dirk@719
    33
dirk@1724
    34
    /**
dirk@1724
    35
     After trustwords have been invoked, this will be the partner identity that
dirk@1724
    36
     was either confirmed or mistrusted.
dirk@1724
    37
     */
dirk@1724
    38
    var partnerIdentity: Identity?
dirk@1724
    39
dirk@2067
    40
    @IBOutlet weak var enableFilterButton: UIBarButtonItem!
dirk@2067
    41
    @IBOutlet weak var textFilterButton: UIBarButtonItem!
dirk@2067
    42
xavier@2363
    43
    //private var filterEnabled = false
dirk@2067
    44
dirk@275
    45
    override func viewDidLoad() {
ylandert@935
    46
        super.viewDidLoad()
xavier@1623
    47
dirk@2189
    48
        title = NSLocalizedString("Inbox", comment: "General name for (unified) inbox")
igor@1284
    49
        UIHelper.emailListTableHeight(self.tableView)
igor@1301
    50
        addSearchBar()
dirk@275
    51
    }
dirk@31
    52
dirk@784
    53
    override func viewWillAppear(_ animated: Bool) {
igor@1301
    54
        super.viewWillAppear(animated)
xavier@2325
    55
        self.navigationController?.setToolbarHidden(false, animated: true)
dirk@1344
    56
        if MiscUtil.isUnitTest() {
dirk@1344
    57
            return
dirk@1344
    58
        }
dirk@1344
    59
xavier@2363
    60
        if let vm = viewModel {
xavier@2363
    61
            self.textFilterButton.isEnabled = vm.filterEnabled
xavier@2363
    62
        } else {
xavier@2363
    63
            self.textFilterButton.isEnabled = false
xavier@2363
    64
        }
xavier@1832
    65
dirk@1826
    66
        setDefaultColors()
dirk@1344
    67
        initialConfig()
dirk@854
    68
        updateModel()
dirk@1348
    69
dirk@2191
    70
        // Mark this folder as having been looked at by the user
dirk@2191
    71
        if let fol = config?.folder {
dirk@2191
    72
            fol.updateLastLookAt()
dirk@2191
    73
        }
dirk@2191
    74
xavier@2369
    75
        viewModel = EmailListViewModel(config: config, delegate: self)
dirk@1348
    76
        MessageModelConfig.messageFolderDelegate = self
xavier@2325
    77
        
dirk@1348
    78
    }
dirk@1348
    79
xavier@1948
    80
dirk@1348
    81
    override func viewWillDisappear(_ animated: Bool) {
dirk@1348
    82
        super.viewWillDisappear(animated)
dirk@1348
    83
        MessageModelConfig.messageFolderDelegate = nil
igor@1301
    84
    }
xavier@1623
    85
igor@1338
    86
    func initialConfig() {
dirk@1344
    87
        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
igor@1338
    88
            return
igor@1338
    89
        }
xavier@2132
    90
        if config == nil {
dirk@2191
    91
            config = EmailListConfig(appConfig: appDelegate.appConfig,
dirk@2191
    92
                                     folder: Folder.unifiedInbox())
xavier@2132
    93
        }
xavier@2362
    94
dirk@2240
    95
        if Account.all().isEmpty {
dirk@2240
    96
            performSegue(withIdentifier:.segueAddNewAccount, sender: self)
dirk@2240
    97
        }
xavier@2132
    98
        self.title = config?.folder?.realName
igor@1338
    99
    }
xavier@1623
   100
igor@1301
   101
    func addSearchBar() {
igor@1301
   102
        searchController.searchResultsUpdater = self
igor@1301
   103
        searchController.dimsBackgroundDuringPresentation = false
igor@1301
   104
        searchController.delegate = self
igor@1301
   105
        definesPresentationContext = true
igor@1301
   106
        tableView.tableHeaderView = searchController.searchBar
igor@1301
   107
        tableView.setContentOffset(CGPoint(x: 0.0, y: 40.0), animated: false)
igor@1301
   108
    }
dirk@705
   109
dirk@854
   110
    func updateModel() {
igor@1318
   111
        tableView.reloadData()
dirk@31
   112
    }
dirk@31
   113
xavier@1832
   114
xavier@1832
   115
    @IBAction func showUnreadButtonTapped(_ sender: UIBarButtonItem) {
xavier@2363
   116
        if let vm = viewModel {
xavier@2363
   117
            if vm.filterEnabled {
xavier@2363
   118
                vm.filterEnabled = false
xavier@2363
   119
                textFilterButton.title = ""
xavier@2363
   120
                enableFilterButton.image = UIImage(named: "unread-icon")
xavier@2369
   121
                vm.updateFilter(filter: Filter.unified())
xavier@2363
   122
            } else {
xavier@2363
   123
                vm.filterEnabled = true
xavier@2363
   124
                textFilterButton.title = "Filter by: unread"
xavier@2363
   125
                enableFilterButton.image = UIImage(named: "unread-icon-active")
xavier@2363
   126
                if config != nil {
xavier@2369
   127
                    vm.updateFilter(filter: Filter.unread())
xavier@2363
   128
                }
xavier@1832
   129
            }
xavier@2363
   130
            self.textFilterButton.isEnabled = vm.filterEnabled
xavier@1832
   131
        }
xavier@2363
   132
xavier@1832
   133
xavier@1832
   134
    }
xavier@1832
   135
dirk@58
   136
    // MARK: - UI State
dirk@58
   137
dirk@58
   138
    func updateUI() {
dirk@784
   139
        UIApplication.shared.isNetworkActivityIndicatorVisible = state.isSynching
dirk@748
   140
        if !state.isSynching {
igor@1260
   141
            refreshControl?.endRefreshing()
dirk@58
   142
        }
dirk@58
   143
    }
dirk@58
   144
dirk@31
   145
    // MARK: - UITableViewDataSource
dirk@31
   146
dirk@784
   147
    override func numberOfSections(in tableView: UITableView) -> Int {
xavier@2362
   148
        if let _ = viewModel?.folderToShow {
dirk@854
   149
            return 1
dirk@209
   150
        }
dirk@854
   151
        return 0
dirk@31
   152
    }
dirk@31
   153
dirk@784
   154
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
xavier@2362
   155
        if let vm = viewModel {
xavier@2362
   156
            return vm.count
dirk@31
   157
        }
dirk@31
   158
        return 0
dirk@31
   159
    }
dirk@31
   160
dirk@784
   161
    override func tableView(_ tableView: UITableView,
dirk@784
   162
                            cellForRowAt indexPath: IndexPath) -> UITableViewCell {
dirk@784
   163
        let cell = tableView.dequeueReusableCell(
dirk@784
   164
            withIdentifier: "EmailListViewCell", for: indexPath) as! EmailListViewCell
xavier@2344
   165
        //mantener el configure cell para tal de no generar un vm para celdas
xavier@2404
   166
        let _ = cell.configureCell(config: config, indexPath: indexPath)
xavier@2404
   167
        viewModel?.associate(cell: cell, position: indexPath.row)
dirk@31
   168
        return cell
dirk@31
   169
    }
dirk@31
   170
dirk@719
   171
    // MARK: - UITableViewDelegate
dirk@719
   172
dirk@784
   173
    override func tableView(_ tableView: UITableView, editActionsForRowAt
dirk@784
   174
        indexPath: IndexPath)-> [UITableViewRowAction]? {
xavier@1623
   175
dirk@784
   176
        let cell = tableView.cellForRow(at: indexPath) as! EmailListViewCell
igor@1260
   177
        if let email = cell.messageAt(indexPath: indexPath, config: config) {
igor@1576
   178
            let flagAction = createFlagAction(message: email, cell: cell)
dirk@1507
   179
            let deleteAction = createDeleteAction(message: email, cell: cell)
igor@1242
   180
            let moreAction = createMoreAction(message: email, cell: cell)
igor@1576
   181
            return [deleteAction, flagAction, moreAction]
dirk@855
   182
        }
dirk@855
   183
        return nil
dirk@744
   184
    }
dirk@744
   185
dirk@719
   186
    // MARK: - Misc
dirk@719
   187
dirk@1507
   188
    func createRowAction(cell: EmailListViewCell,
xavier@1623
   189
                         image: UIImage?, action: @escaping (UITableViewRowAction, IndexPath) -> Void,
xavier@1623
   190
                         title: String) -> UITableViewRowAction {
dirk@1510
   191
        let rowAction = UITableViewRowAction(
dirk@1510
   192
            style: .normal, title: title, handler: action)
dirk@1507
   193
dirk@1507
   194
        if let theImage = image {
dirk@1507
   195
            let iconColor = UIColor(patternImage: theImage)
dirk@1507
   196
            rowAction.backgroundColor = iconColor
dirk@744
   197
        }
dirk@744
   198
dirk@1507
   199
        return rowAction
dirk@744
   200
    }
dirk@744
   201
dirk@1507
   202
    func createFlagAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
dirk@1507
   203
        func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
dirk@1522
   204
            if message.imapFlags == nil {
dirk@1522
   205
                Log.warn(component: #function, content: "message.imapFlags == nil")
dirk@1522
   206
            }
dirk@1605
   207
            if cell.isFlagged(message: message) {
dirk@1507
   208
                message.imapFlags?.flagged = false
dirk@1507
   209
            } else {
dirk@1507
   210
                message.imapFlags?.flagged = true
dirk@1507
   211
            }
dirk@1507
   212
            message.save()
dirk@1507
   213
            self.tableView.reloadRows(at: [indexPath], with: .none)
dirk@1507
   214
        }
dirk@1510
   215
dirk@2190
   216
        var title = "\n\n" + NSLocalizedString("Flag", comment: "Message action (on swipe)")
dirk@1605
   217
        if message.imapFlags?.flagged ?? true {
dirk@2190
   218
            title = "\n\n" + NSLocalizedString("Unflag", comment: "Message action (on swipe)")
dirk@744
   219
        }
dirk@744
   220
dirk@1510
   221
        return createRowAction(
dirk@1510
   222
            cell: cell, image: UIImage(named: "swipe-flag"), action: action, title: title)
dirk@744
   223
    }
dirk@744
   224
dirk@1507
   225
    func createDeleteAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
dirk@1507
   226
        func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
dirk@1507
   227
            guard let message = cell.messageAt(indexPath: indexPath, config: self.config) else {
dirk@1507
   228
                return
dirk@1507
   229
            }
xavier@1623
   230
dirk@1650
   231
            message.delete() // mark for deletion/trash
dirk@1507
   232
            message.save()
igor@1576
   233
            self.tableView.reloadData()
dirk@1507
   234
        }
dirk@744
   235
dirk@1510
   236
        return createRowAction(
dirk@1510
   237
            cell: cell, image: UIImage(named: "swipe-trash"), action: action,
dirk@2190
   238
            title: "\n\n" + NSLocalizedString("Delete", comment: "Message action (on swipe)"))
dirk@1507
   239
    }
dirk@1507
   240
dirk@1507
   241
    func createMarkAsReadAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
dirk@1507
   242
        func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
dirk@1605
   243
            if cell.haveSeen(message: message) {
dirk@1507
   244
                message.imapFlags?.seen = false
dirk@1507
   245
            } else {
dirk@1507
   246
                message.imapFlags?.seen = true
dirk@1507
   247
            }
dirk@1507
   248
            self.tableView.reloadRows(at: [indexPath], with: .none)
dirk@744
   249
        }
dirk@1510
   250
dirk@1510
   251
        var title = NSLocalizedString(
dirk@2190
   252
            "Unread", comment: "Message action (on swipe)")
dirk@1605
   253
        if !cell.haveSeen(message: message) {
dirk@1510
   254
            title = NSLocalizedString(
dirk@2190
   255
                "Read", comment: "Message action (on swipe)")
dirk@1507
   256
        }
dirk@1507
   257
dirk@1507
   258
        let isReadAction = createRowAction(cell: cell, image: nil, action: action,
dirk@1510
   259
                                           title: title)
dirk@784
   260
        isReadAction.backgroundColor = UIColor.blue
dirk@744
   261
dirk@744
   262
        return isReadAction
dirk@744
   263
    }
xavier@1623
   264
igor@1242
   265
    func createMoreAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
dirk@1510
   266
        func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
igor@1242
   267
            self.showMoreActionSheet(cell: cell)
igor@1242
   268
        }
dirk@1510
   269
dirk@1510
   270
        return createRowAction(
dirk@1510
   271
            cell: cell, image: UIImage(named: "swipe-more"), action: action,
dirk@2190
   272
            title: "\n\n" + NSLocalizedString("More", comment: "Message action (on swipe)"))
igor@1242
   273
    }
xavier@1623
   274
igor@1242
   275
    // MARK: - Action Sheet
xavier@1623
   276
igor@1242
   277
    func showMoreActionSheet(cell: EmailListViewCell) {
igor@1242
   278
        let alertControler = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
igor@1438
   279
        alertControler.view.tintColor = .pEpGreen
igor@1242
   280
        let cancelAction = createCancelAction()
igor@1242
   281
        let replyAction = createReplyAction(cell: cell)
xavier@1623
   282
        let replyAllAction = createReplyAllAction(cell: cell)
igor@1242
   283
        let forwardAction = createForwardAction(cell: cell)
igor@1242
   284
        let markAction = createMarkAction()
igor@1242
   285
        alertControler.addAction(cancelAction)
igor@1242
   286
        alertControler.addAction(replyAction)
xavier@1620
   287
        alertControler.addAction(replyAllAction)
igor@1242
   288
        alertControler.addAction(forwardAction)
igor@1242
   289
        alertControler.addAction(markAction)
igor@1414
   290
        if let popoverPresentationController = alertControler.popoverPresentationController {
igor@1414
   291
            popoverPresentationController.sourceView = cell
igor@1414
   292
        }
igor@1242
   293
        present(alertControler, animated: true, completion: nil)
igor@1242
   294
    }
xavier@1623
   295
igor@1242
   296
    // MARK: - Action Sheet Actions
igor@1242
   297
igor@1242
   298
    func createCancelAction() -> UIAlertAction {
xavier@1623
   299
        return  UIAlertAction(title: "Cancel", style: .cancel) { (action) in}
igor@1242
   300
    }
xavier@1623
   301
igor@1242
   302
    func createReplyAction(cell: EmailListViewCell) ->  UIAlertAction {
igor@1242
   303
        return UIAlertAction(title: "Reply", style: .default) { (action) in
xavier@1623
   304
            // self.performSegue(withIdentifier: self.segueCompose, sender: cell)
igor@1338
   305
            self.performSegue(withIdentifier: .segueCompose, sender: cell)
igor@1242
   306
        }
igor@1242
   307
    }
xavier@1620
   308
xavier@1620
   309
    func createReplyAllAction(cell: EmailListViewCell) ->  UIAlertAction {
xavier@1623
   310
        return UIAlertAction(title: "Reply All", style: .default) { (action) in
xavier@1623
   311
            self.performSegue(withIdentifier: .segueReplyAll, sender: cell)
xavier@1620
   312
        }
xavier@1620
   313
    }
xavier@1620
   314
igor@1242
   315
    func createForwardAction(cell: EmailListViewCell) -> UIAlertAction {
igor@1242
   316
        return UIAlertAction(title: "Forward", style: .default) { (action) in
xavier@1664
   317
            self.performSegue(withIdentifier: .segueForward, sender: cell)
igor@1242
   318
        }
igor@1242
   319
    }
xavier@1623
   320
igor@1242
   321
    func createMarkAction() -> UIAlertAction {
igor@1242
   322
        return UIAlertAction(title: "Mark", style: .default) { (action) in
igor@1242
   323
        }
igor@1242
   324
    }
xavier@1623
   325
dirk@784
   326
}
igor@1301
   327
igor@1301
   328
extension EmailListViewController: UISearchResultsUpdating, UISearchControllerDelegate {
igor@1301
   329
    public func updateSearchResults(for searchController: UISearchController) {
xavier@2369
   330
        if let vm = viewModel {
xavier@2369
   331
            vm.filterContentForSearchText(searchText: searchController.searchBar.text!, clear: false)
xavier@2369
   332
        }
igor@1301
   333
    }
xavier@1623
   334
igor@1301
   335
    func didDismissSearchController(_ searchController: UISearchController) {
xavier@2369
   336
        if let vm = viewModel {
xavier@2369
   337
            vm.filterContentForSearchText(clear: true)
xavier@2369
   338
        }
igor@1301
   339
    }
igor@1301
   340
}
igor@1338
   341
igor@1338
   342
// MARK: - Navigation
igor@1338
   343
igor@1338
   344
extension EmailListViewController: SegueHandlerType {
xavier@1623
   345
igor@1338
   346
    // MARK: - SegueHandlerType
xavier@1623
   347
igor@1338
   348
    enum SegueIdentifier: String {
igor@1338
   349
        case segueAddNewAccount
igor@1338
   350
        case segueEditAccounts
igor@1338
   351
        case segueShowEmail
igor@1338
   352
        case segueCompose
xavier@1623
   353
        case segueReplyAll
xavier@1664
   354
        case segueForward
xavier@1865
   355
        case segueFilter
xavier@2248
   356
        case segueFolderViews
igor@1338
   357
        case noSegue
igor@1338
   358
    }
xavier@1623
   359
igor@1338
   360
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
igor@1338
   361
        switch segueIdentifier(for: segue) {
xavier@1623
   362
        case .segueReplyAll:
xavier@1623
   363
            if let nav = segue.destination as? UINavigationController,
xavier@1623
   364
                let destination = nav.topViewController as? ComposeTableViewController,
xavier@1623
   365
                let cell = sender as? EmailListViewCell,
xavier@1623
   366
                let indexPath = self.tableView.indexPath(for: cell),
xavier@1623
   367
                let email = cell.messageAt(indexPath: indexPath, config: config) {
xavier@1623
   368
                destination.composeMode = .replyAll
xavier@1623
   369
                destination.appConfig = config?.appConfig
xavier@1623
   370
                destination.originalMessage = email
xavier@1623
   371
            }
igor@1338
   372
            break
igor@1338
   373
        case .segueShowEmail:
dirk@1594
   374
            if let vc = segue.destination as? EmailViewController,
igor@1338
   375
                let cell = sender as? EmailListViewCell,
igor@1338
   376
                let indexPath = self.tableView.indexPath(for: cell),
dirk@1594
   377
                let email = cell.messageAt(indexPath: indexPath, config: config) {
xavier@1623
   378
                vc.appConfig = config?.appConfig
xavier@1623
   379
                vc.message = email
xavier@2404
   380
                vc.folderShow = viewModel?.folderToShow
xavier@2404
   381
                vc.messageId = indexPath.row
igor@1338
   382
            }
igor@1338
   383
            break
xavier@1664
   384
        case .segueForward:
xavier@1664
   385
            if let nav = segue.destination as? UINavigationController,
xavier@1664
   386
                let destination = nav.topViewController as? ComposeTableViewController,
xavier@1664
   387
                let cell = sender as? EmailListViewCell,
xavier@1664
   388
                let indexPath = self.tableView.indexPath(for: cell),
xavier@1664
   389
                let email = cell.messageAt(indexPath: indexPath, config: config) {
xavier@1664
   390
                destination.composeMode = .forward
xavier@1664
   391
                destination.appConfig = config?.appConfig
xavier@1664
   392
                destination.originalMessage = email
xavier@1664
   393
            }
xavier@1664
   394
            break
xavier@1865
   395
        case .segueFilter:
xavier@1865
   396
            if let destiny = segue.destination as? FilterTableViewController {
xavier@2369
   397
                destiny.filterDelegate = self.viewModel
xavier@1865
   398
                destiny.inFolder = false
xavier@1876
   399
                destiny.filterEnabled = self.config?.folder?.filter as! Filter?
xavier@2325
   400
                destiny.hidesBottomBarWhenPushed = true
xavier@1865
   401
            }
xavier@1865
   402
            break
dirk@2240
   403
        case .segueAddNewAccount:
xavier@2254
   404
            if let vc = segue.destination as? LoginTableViewController {
dirk@2240
   405
                vc.appConfig = config?.appConfig
xavier@2254
   406
                vc.hidesBottomBarWhenPushed = true
dirk@2240
   407
            }
xavier@2248
   408
        case .segueFolderViews:
xavier@2248
   409
            if let vC = segue.destination as? FolderTableViewController {
xavier@2248
   410
                vC.appConfig = config?.appConfig
xavier@2254
   411
                vC.hidesBottomBarWhenPushed = true
xavier@2248
   412
            }
dirk@2240
   413
        case .segueEditAccounts, .segueCompose, .noSegue:
dirk@1694
   414
            break
igor@1338
   415
        }
xavier@1865
   416
igor@1338
   417
    }
xavier@2254
   418
    
xavier@2254
   419
    @IBAction func segueUnwindAccountAdded(segue: UIStoryboardSegue) {
xavier@2254
   420
    }
xavier@2254
   421
dirk@1350
   422
    func didChangeInternal(messageFolder: MessageFolder) {
dirk@1350
   423
        if let folder = config?.folder,
dirk@1350
   424
            let message = messageFolder as? Message,
dirk@1558
   425
            folder.contains(message: message, deletedMessagesAreContained: true) {
dirk@2181
   426
            if message.isOriginal {
dirk@2181
   427
                // new message has arrived
dirk@2181
   428
                if let index = folder.indexOf(message: message) {
dirk@2181
   429
                    let ip = IndexPath(row: index, section: 0)
dirk@2181
   430
                    Log.info(
dirk@2181
   431
                        component: #function,
dirk@2181
   432
                        content: "insert message at \(index), \(folder.messageCount()) messages")
dirk@2181
   433
                    tableView.insertRows(at: [ip], with: .automatic)
dirk@1535
   434
                } else {
dirk@2181
   435
                    tableView.reloadData()
dirk@2181
   436
                }
dirk@2181
   437
            } else if message.isGhost {
xavier@2363
   438
                if let vm = viewModel, let cell = vm.cellFor(message: message), let ip = tableView.indexPath(for: cell) {
dirk@2181
   439
                    Log.info(
dirk@2181
   440
                        component: #function,
dirk@2181
   441
                        content: "delete message at \(index), \(folder.messageCount()) messages")
dirk@2181
   442
                    tableView.deleteRows(at: [ip], with: .automatic)
dirk@2181
   443
                } else {
dirk@2181
   444
                    tableView.reloadData()
dirk@2181
   445
                }
dirk@2181
   446
            } else {
dirk@2181
   447
                // other flags than delete must have been changed
xavier@2363
   448
                if let vm = viewModel, let cell = vm.cellFor(message: message) {
dirk@2181
   449
                    cell.updateFlags(message: message)
dirk@2181
   450
                } else {
dirk@2181
   451
                    tableView.reloadData()
dirk@1350
   452
                }
dirk@1350
   453
            }
dirk@1350
   454
        }
dirk@1350
   455
    }
dirk@1737
   456
igor@1338
   457
}
dirk@1348
   458
dirk@1348
   459
// MARK: - MessageFolderDelegate
dirk@1348
   460
dirk@1348
   461
extension EmailListViewController: MessageFolderDelegate {
dirk@1348
   462
    func didChange(messageFolder: MessageFolder) {
dirk@1675
   463
        GCD.onMainWait {
dirk@1350
   464
            self.didChangeInternal(messageFolder: messageFolder)
dirk@1348
   465
        }
dirk@1348
   466
    }
dirk@1348
   467
}
xavier@2369
   468
xavier@2369
   469
extension EmailListViewController: tableViewUpdate {
xavier@2369
   470
    func updateView() {
xavier@2369
   471
        self.tableView.reloadData()
xavier@2369
   472
    }
xavier@2369
   473
}