pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
author Xavier Algarra <xavier@pep-project.org>
Mon, 03 Jul 2017 17:53:59 +0200
changeset 2369 6ab35cb4c20f
parent 2363 e969a926d09b
child 2404 092e3013db61
permissions -rw-r--r--
IOS-97 handling search with filter unread enabled
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
dirk@1737
   166
        if let message = cell.configureCell(config: config, indexPath: indexPath) {
xavier@2362
   167
            viewModel?.associate(cell: cell, position: indexPath.row)
xavier@2362
   168
            //associate(message: message, toCell: cell)
dirk@1542
   169
        }
dirk@31
   170
        return cell
dirk@31
   171
    }
dirk@31
   172
dirk@719
   173
    // MARK: - UITableViewDelegate
dirk@719
   174
dirk@784
   175
    override func tableView(_ tableView: UITableView, editActionsForRowAt
dirk@784
   176
        indexPath: IndexPath)-> [UITableViewRowAction]? {
xavier@1623
   177
dirk@784
   178
        let cell = tableView.cellForRow(at: indexPath) as! EmailListViewCell
igor@1260
   179
        if let email = cell.messageAt(indexPath: indexPath, config: config) {
igor@1576
   180
            let flagAction = createFlagAction(message: email, cell: cell)
dirk@1507
   181
            let deleteAction = createDeleteAction(message: email, cell: cell)
igor@1242
   182
            let moreAction = createMoreAction(message: email, cell: cell)
igor@1576
   183
            return [deleteAction, flagAction, moreAction]
dirk@855
   184
        }
dirk@855
   185
        return nil
dirk@744
   186
    }
dirk@744
   187
dirk@719
   188
    // MARK: - Misc
dirk@719
   189
dirk@1507
   190
    func createRowAction(cell: EmailListViewCell,
xavier@1623
   191
                         image: UIImage?, action: @escaping (UITableViewRowAction, IndexPath) -> Void,
xavier@1623
   192
                         title: String) -> UITableViewRowAction {
dirk@1510
   193
        let rowAction = UITableViewRowAction(
dirk@1510
   194
            style: .normal, title: title, handler: action)
dirk@1507
   195
dirk@1507
   196
        if let theImage = image {
dirk@1507
   197
            let iconColor = UIColor(patternImage: theImage)
dirk@1507
   198
            rowAction.backgroundColor = iconColor
dirk@744
   199
        }
dirk@744
   200
dirk@1507
   201
        return rowAction
dirk@744
   202
    }
dirk@744
   203
dirk@1507
   204
    func createFlagAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
dirk@1507
   205
        func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
dirk@1522
   206
            if message.imapFlags == nil {
dirk@1522
   207
                Log.warn(component: #function, content: "message.imapFlags == nil")
dirk@1522
   208
            }
dirk@1605
   209
            if cell.isFlagged(message: message) {
dirk@1507
   210
                message.imapFlags?.flagged = false
dirk@1507
   211
            } else {
dirk@1507
   212
                message.imapFlags?.flagged = true
dirk@1507
   213
            }
dirk@1507
   214
            message.save()
dirk@1507
   215
            self.tableView.reloadRows(at: [indexPath], with: .none)
dirk@1507
   216
        }
dirk@1510
   217
dirk@2190
   218
        var title = "\n\n" + NSLocalizedString("Flag", comment: "Message action (on swipe)")
dirk@1605
   219
        if message.imapFlags?.flagged ?? true {
dirk@2190
   220
            title = "\n\n" + NSLocalizedString("Unflag", comment: "Message action (on swipe)")
dirk@744
   221
        }
dirk@744
   222
dirk@1510
   223
        return createRowAction(
dirk@1510
   224
            cell: cell, image: UIImage(named: "swipe-flag"), action: action, title: title)
dirk@744
   225
    }
dirk@744
   226
dirk@1507
   227
    func createDeleteAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
dirk@1507
   228
        func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
dirk@1507
   229
            guard let message = cell.messageAt(indexPath: indexPath, config: self.config) else {
dirk@1507
   230
                return
dirk@1507
   231
            }
xavier@1623
   232
dirk@1650
   233
            message.delete() // mark for deletion/trash
dirk@1507
   234
            message.save()
igor@1576
   235
            self.tableView.reloadData()
dirk@1507
   236
        }
dirk@744
   237
dirk@1510
   238
        return createRowAction(
dirk@1510
   239
            cell: cell, image: UIImage(named: "swipe-trash"), action: action,
dirk@2190
   240
            title: "\n\n" + NSLocalizedString("Delete", comment: "Message action (on swipe)"))
dirk@1507
   241
    }
dirk@1507
   242
dirk@1507
   243
    func createMarkAsReadAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
dirk@1507
   244
        func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
dirk@1605
   245
            if cell.haveSeen(message: message) {
dirk@1507
   246
                message.imapFlags?.seen = false
dirk@1507
   247
            } else {
dirk@1507
   248
                message.imapFlags?.seen = true
dirk@1507
   249
            }
dirk@1507
   250
            self.tableView.reloadRows(at: [indexPath], with: .none)
dirk@744
   251
        }
dirk@1510
   252
dirk@1510
   253
        var title = NSLocalizedString(
dirk@2190
   254
            "Unread", comment: "Message action (on swipe)")
dirk@1605
   255
        if !cell.haveSeen(message: message) {
dirk@1510
   256
            title = NSLocalizedString(
dirk@2190
   257
                "Read", comment: "Message action (on swipe)")
dirk@1507
   258
        }
dirk@1507
   259
dirk@1507
   260
        let isReadAction = createRowAction(cell: cell, image: nil, action: action,
dirk@1510
   261
                                           title: title)
dirk@784
   262
        isReadAction.backgroundColor = UIColor.blue
dirk@744
   263
dirk@744
   264
        return isReadAction
dirk@744
   265
    }
xavier@1623
   266
igor@1242
   267
    func createMoreAction(message: Message, cell: EmailListViewCell) -> UITableViewRowAction {
dirk@1510
   268
        func action(action: UITableViewRowAction, indexPath: IndexPath) -> Void {
igor@1242
   269
            self.showMoreActionSheet(cell: cell)
igor@1242
   270
        }
dirk@1510
   271
dirk@1510
   272
        return createRowAction(
dirk@1510
   273
            cell: cell, image: UIImage(named: "swipe-more"), action: action,
dirk@2190
   274
            title: "\n\n" + NSLocalizedString("More", comment: "Message action (on swipe)"))
igor@1242
   275
    }
xavier@1623
   276
igor@1242
   277
    // MARK: - Action Sheet
xavier@1623
   278
igor@1242
   279
    func showMoreActionSheet(cell: EmailListViewCell) {
igor@1242
   280
        let alertControler = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
igor@1438
   281
        alertControler.view.tintColor = .pEpGreen
igor@1242
   282
        let cancelAction = createCancelAction()
igor@1242
   283
        let replyAction = createReplyAction(cell: cell)
xavier@1623
   284
        let replyAllAction = createReplyAllAction(cell: cell)
igor@1242
   285
        let forwardAction = createForwardAction(cell: cell)
igor@1242
   286
        let markAction = createMarkAction()
igor@1242
   287
        alertControler.addAction(cancelAction)
igor@1242
   288
        alertControler.addAction(replyAction)
xavier@1620
   289
        alertControler.addAction(replyAllAction)
igor@1242
   290
        alertControler.addAction(forwardAction)
igor@1242
   291
        alertControler.addAction(markAction)
igor@1414
   292
        if let popoverPresentationController = alertControler.popoverPresentationController {
igor@1414
   293
            popoverPresentationController.sourceView = cell
igor@1414
   294
        }
igor@1242
   295
        present(alertControler, animated: true, completion: nil)
igor@1242
   296
    }
xavier@1623
   297
igor@1242
   298
    // MARK: - Action Sheet Actions
igor@1242
   299
igor@1242
   300
    func createCancelAction() -> UIAlertAction {
xavier@1623
   301
        return  UIAlertAction(title: "Cancel", style: .cancel) { (action) in}
igor@1242
   302
    }
xavier@1623
   303
igor@1242
   304
    func createReplyAction(cell: EmailListViewCell) ->  UIAlertAction {
igor@1242
   305
        return UIAlertAction(title: "Reply", style: .default) { (action) in
xavier@1623
   306
            // self.performSegue(withIdentifier: self.segueCompose, sender: cell)
igor@1338
   307
            self.performSegue(withIdentifier: .segueCompose, sender: cell)
igor@1242
   308
        }
igor@1242
   309
    }
xavier@1620
   310
xavier@1620
   311
    func createReplyAllAction(cell: EmailListViewCell) ->  UIAlertAction {
xavier@1623
   312
        return UIAlertAction(title: "Reply All", style: .default) { (action) in
xavier@1623
   313
            self.performSegue(withIdentifier: .segueReplyAll, sender: cell)
xavier@1620
   314
        }
xavier@1620
   315
    }
xavier@1620
   316
igor@1242
   317
    func createForwardAction(cell: EmailListViewCell) -> UIAlertAction {
igor@1242
   318
        return UIAlertAction(title: "Forward", style: .default) { (action) in
xavier@1664
   319
            self.performSegue(withIdentifier: .segueForward, sender: cell)
igor@1242
   320
        }
igor@1242
   321
    }
xavier@1623
   322
igor@1242
   323
    func createMarkAction() -> UIAlertAction {
igor@1242
   324
        return UIAlertAction(title: "Mark", style: .default) { (action) in
igor@1242
   325
        }
igor@1242
   326
    }
xavier@1623
   327
dirk@784
   328
}
igor@1301
   329
igor@1301
   330
extension EmailListViewController: UISearchResultsUpdating, UISearchControllerDelegate {
igor@1301
   331
    public func updateSearchResults(for searchController: UISearchController) {
xavier@2369
   332
        if let vm = viewModel {
xavier@2369
   333
            vm.filterContentForSearchText(searchText: searchController.searchBar.text!, clear: false)
xavier@2369
   334
        }
igor@1301
   335
    }
xavier@1623
   336
igor@1301
   337
    func didDismissSearchController(_ searchController: UISearchController) {
xavier@2369
   338
        if let vm = viewModel {
xavier@2369
   339
            vm.filterContentForSearchText(clear: true)
xavier@2369
   340
        }
igor@1301
   341
    }
igor@1301
   342
}
igor@1338
   343
igor@1338
   344
// MARK: - Navigation
igor@1338
   345
igor@1338
   346
extension EmailListViewController: SegueHandlerType {
xavier@1623
   347
igor@1338
   348
    // MARK: - SegueHandlerType
xavier@1623
   349
igor@1338
   350
    enum SegueIdentifier: String {
igor@1338
   351
        case segueAddNewAccount
igor@1338
   352
        case segueEditAccounts
igor@1338
   353
        case segueShowEmail
igor@1338
   354
        case segueCompose
xavier@1623
   355
        case segueReplyAll
xavier@1664
   356
        case segueForward
xavier@1865
   357
        case segueFilter
xavier@2248
   358
        case segueFolderViews
igor@1338
   359
        case noSegue
igor@1338
   360
    }
xavier@1623
   361
igor@1338
   362
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
igor@1338
   363
        switch segueIdentifier(for: segue) {
xavier@1623
   364
        case .segueReplyAll:
xavier@1623
   365
            if let nav = segue.destination as? UINavigationController,
xavier@1623
   366
                let destination = nav.topViewController as? ComposeTableViewController,
xavier@1623
   367
                let cell = sender as? EmailListViewCell,
xavier@1623
   368
                let indexPath = self.tableView.indexPath(for: cell),
xavier@1623
   369
                let email = cell.messageAt(indexPath: indexPath, config: config) {
xavier@1623
   370
                destination.composeMode = .replyAll
xavier@1623
   371
                destination.appConfig = config?.appConfig
xavier@1623
   372
                destination.originalMessage = email
xavier@1623
   373
            }
igor@1338
   374
            break
igor@1338
   375
        case .segueShowEmail:
dirk@1594
   376
            if let vc = segue.destination as? EmailViewController,
igor@1338
   377
                let cell = sender as? EmailListViewCell,
igor@1338
   378
                let indexPath = self.tableView.indexPath(for: cell),
dirk@1594
   379
                let email = cell.messageAt(indexPath: indexPath, config: config) {
xavier@1623
   380
                vc.appConfig = config?.appConfig
xavier@1623
   381
                vc.message = email
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
}