pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
changeset 1678 8eb2c23637d6
parent 1675 21f792356f97
child 1680 a958aa6e5982
equal deleted inserted replaced
1677:f5e20b03c815 1678:8eb2c23637d6
    17     /** The folder to display, if it exists */
    17     /** The folder to display, if it exists */
    18     var folder: Folder?
    18     var folder: Folder?
    19 }
    19 }
    20 
    20 
    21 class EmailListViewController: UITableViewController {
    21 class EmailListViewController: UITableViewController {
       
    22     /** For debug output */
       
    23     let compMessageCount = "messageCount"
       
    24 
    22     struct UIState {
    25     struct UIState {
    23         var isSynching: Bool = false
    26         var isSynching: Bool = false
    24     }
    27     }
    25 
    28 
    26     var config: EmailListConfig?
    29     var config: EmailListConfig?
   101         return 0
   104         return 0
   102     }
   105     }
   103 
   106 
   104     override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
   107     override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
   105         if let fol = config?.folder  {
   108         if let fol = config?.folder  {
       
   109             Log.info(component: #function, content: "\(compMessageCount) \(fol.messageCount())")
   106             return fol.messageCount()
   110             return fol.messageCount()
   107         }
   111         }
   108         return 0
   112         return 0
   109     }
   113     }
   110 
   114 
   378             if let msg = messageFolder as? Message {
   382             if let msg = messageFolder as? Message {
   379                 if msg.isOriginal {
   383                 if msg.isOriginal {
   380                     // new message has arrived
   384                     // new message has arrived
   381                     if let index = folder.indexOf(message: msg) {
   385                     if let index = folder.indexOf(message: msg) {
   382                         let ip = IndexPath(row: index, section: 0)
   386                         let ip = IndexPath(row: index, section: 0)
       
   387                         Log.info(
       
   388                             component: #function,
       
   389                             content: "\(compMessageCount) inserting at \(ip), current \(tableView.numberOfRows(inSection: 0))")
   383                         tableView.insertRows(at: [ip], with: .automatic)
   390                         tableView.insertRows(at: [ip], with: .automatic)
       
   391                         Log.info(
       
   392                             component: #function,
       
   393                             content: "\(compMessageCount) now \(tableView.numberOfRows(inSection: 0))")
   384                     } else {
   394                     } else {
   385                         tableView.reloadData()
   395                         tableView.reloadData()
   386                     }
   396                     }
   387                 } else if msg.isGhost {
   397                 } else if msg.isGhost {
   388                     if let cell = cellsByMessageID.object(forKey: msg.uuid as NSString) {
   398                     if let cell = cellsByMessageID.object(forKey: msg.uuid as NSString) {
   405 
   415 
   406 // MARK: - MessageFolderDelegate
   416 // MARK: - MessageFolderDelegate
   407 
   417 
   408 extension EmailListViewController: MessageFolderDelegate {
   418 extension EmailListViewController: MessageFolderDelegate {
   409     func didChange(messageFolder: MessageFolder) {
   419     func didChange(messageFolder: MessageFolder) {
   410         if let msg = messageFolder as? Message {
       
   411             if msg.isOriginal {
       
   412                 Log.info(component: #function, content: "new message")
       
   413             } else {
       
   414                 Log.info(component: #function, content: "flag changes?")
       
   415             }
       
   416         }
       
   417         GCD.onMainWait {
   420         GCD.onMainWait {
       
   421             Log.info(component: #function,
       
   422                      content: "\(self.compMessageCount) \(self.config?.folder?.messageCount())")
   418             self.didChangeInternal(messageFolder: messageFolder)
   423             self.didChangeInternal(messageFolder: messageFolder)
   419         }
   424         }
   420     }
   425     }
   421 }
   426 }