IOS-1559 Update all message properties when receiving a new thread message. New thread messages move top message to top.
authorMiguel Berrocal Go?mez <miguel@helm.cat>
Thu, 16 Aug 2018 13:03:38 +0200
changeset 58493cee57dd8029
parent 5846 996278780e43
child 5850 11fdaba12c1d
child 5851 03765f4b2d23
IOS-1559 Update all message properties when receiving a new thread message. New thread messages move top message to top.
pEpForiOS/UI/EmailDisplayList/EmailListViewController.swift
pEpForiOS/UI/EmailDisplayList/EmailListViewModel+MessageFolderDelegate.swift
pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift
     1.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewController.swift	Thu Aug 16 11:31:04 2018 +0200
     1.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewController.swift	Thu Aug 16 13:03:38 2018 +0200
     1.3 @@ -422,6 +422,13 @@
     1.4          self.navigationItem.rightBarButtonItem = editRightButton
     1.5      }
     1.6  
     1.7 +    private func moveSelectionIfNeeded(fromIndexPath: IndexPath, toIndexPath: IndexPath) {
     1.8 +        if lastSelectedIndexPath == fromIndexPath {
     1.9 +            lastSelectedIndexPath = toIndexPath
    1.10 +            resetSelection()
    1.11 +        }
    1.12 +    }
    1.13 +
    1.14      private func resetSelectionIfNeeded(for indexPath: IndexPath) {
    1.15          if lastSelectedIndexPath == indexPath {
    1.16              resetSelection()
    1.17 @@ -824,6 +831,16 @@
    1.18          // ignore
    1.19      }
    1.20  
    1.21 +    func emailListViewModel(viewModel: EmailListViewModel, didMoveData atIndexPath: IndexPath, toIndexPath: IndexPath) {
    1.22 +        lastSelectedIndexPath = tableView.indexPathForSelectedRow
    1.23 +
    1.24 +        tableView.beginUpdates()
    1.25 +        tableView.moveRow(at: atIndexPath, to: toIndexPath)
    1.26 +        tableView.endUpdates()
    1.27 +
    1.28 +        moveSelectionIfNeeded(fromIndexPath: atIndexPath, toIndexPath: toIndexPath)
    1.29 +    }
    1.30 +
    1.31      func updateView() {
    1.32          loadingBlocked = false
    1.33          tableView.dataSource = self
     2.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewModel+MessageFolderDelegate.swift	Thu Aug 16 11:31:04 2018 +0200
     2.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewModel+MessageFolderDelegate.swift	Thu Aug 16 13:03:38 2018 +0200
     2.3 @@ -83,13 +83,20 @@
     2.4                          messages: referencedTopMessages) {
     2.5  
     2.6                          // The thread count might need to be updated
     2.7 -                        if let messageModel = theSelf.messages.object(at: index),
     2.8 -                            let messageCount = messageModel.internalMessageCount  {
     2.9 -                            messageModel.internalMessageCount = messageCount + 1
    2.10 +
    2.11 +                        theSelf.messages.removeObject(at: index)
    2.12 +                        let newIndex = theSelf.messages.insert(object: previewMessage)
    2.13 +
    2.14 +                        if newIndex != index {
    2.15 +                            theSelf.emailListViewModelDelegate?.emailListViewModel(
    2.16 +                                viewModel: theSelf,
    2.17 +                                didMoveData: IndexPath(row: index, section: 0),
    2.18 +                                toIndexPath: IndexPath(row: newIndex, section: 0))
    2.19                          }
    2.20 +
    2.21                          theSelf.emailListViewModelDelegate?.emailListViewModel(
    2.22                              viewModel: theSelf,
    2.23 -                            didUpdateDataAt: [IndexPath(row: index, section: 0)])
    2.24 +                            didUpdateDataAt: [IndexPath(row: newIndex, section: 0)])
    2.25  
    2.26                          if let topMessage = theSelf.currentlyDisplayedMessage(
    2.27                              of: referencedTopMessages) {
     3.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift	Thu Aug 16 11:31:04 2018 +0200
     3.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift	Thu Aug 16 13:03:38 2018 +0200
     3.3 @@ -14,6 +14,7 @@
     3.4      func emailListViewModel(viewModel: EmailListViewModel, didInsertDataAt indexPaths: [IndexPath])
     3.5      func emailListViewModel(viewModel: EmailListViewModel, didUpdateDataAt indexPaths: [IndexPath])
     3.6      func emailListViewModel(viewModel: EmailListViewModel, didRemoveDataAt indexPaths: [IndexPath])
     3.7 +    func emailListViewModel(viewModel: EmailListViewModel, didMoveData atIndexPath: IndexPath, toIndexPath: IndexPath)
     3.8      func emailListViewModel(viewModel: EmailListViewModel,
     3.9                              didUpdateUndisplayedMessage message: Message)
    3.10      func toolbarIs(enabled: Bool)