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