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