IOS-1190 fixes: sync local messages fails due to outdated UID cache.
authorbuff <andreas@pep-project.org>
Wed, 01 Aug 2018 17:56:52 +0200
changeset 56640d4f8fba5414
parent 5663 689787cf11db
child 5665 5911fc5985ad
IOS-1190 fixes: sync local messages fails due to outdated UID cache.
pEpForiOS/Background/SyncMessagesOperation.swift
     1.1 --- a/pEpForiOS/Background/SyncMessagesOperation.swift	Wed Aug 01 14:51:42 2018 +0200
     1.2 +++ b/pEpForiOS/Background/SyncMessagesOperation.swift	Wed Aug 01 17:56:52 2018 +0200
     1.3 @@ -67,7 +67,7 @@
     1.4          }
     1.5      }
     1.6  
     1.7 -    func process(context: NSManagedObjectContext) {
     1.8 +    private func process(context: NSManagedObjectContext) {
     1.9          guard
    1.10              let cdAccount = context.object(
    1.11                  with: imapSyncData.connectInfo.accountObjectID) as? CdAccount
    1.12 @@ -91,16 +91,27 @@
    1.13          self.imapSyncData.sync?.folderBuilder = folderBuilder
    1.14  
    1.15          guard let sync = self.imapSyncData.sync else {
    1.16 +            Log.shared.errorAndCrash(component: #function, errorString: "No sync")
    1.17              handle(error: BackgroundError.GeneralError.illegalState(info: "No sync"))
    1.18              return
    1.19          }
    1.20 -        if !sync.openMailBox(name: self.folderToOpen) {
    1.21 -            sync.imapState.currentFolder?.resetMatchedUIDs()
    1.22 +
    1.23 +        resetUidCache()
    1.24 +        if !sync.openMailBox(name: self.folderToOpen, updateExistsCount: true) {
    1.25              self.syncMessages(sync)
    1.26          }
    1.27      }
    1.28  
    1.29 -    func syncMessages(_ sync: ImapSync) {
    1.30 +    private func resetUidCache() {
    1.31 +        guard let sync = self.imapSyncData.sync else {
    1.32 +            Log.shared.errorAndCrash(component: #function, errorString: "No sync")
    1.33 +            handle(error: BackgroundError.GeneralError.illegalState(info: "No sync"))
    1.34 +            return
    1.35 +        }
    1.36 +        sync.imapState.currentFolder?.resetMatchedUIDs()
    1.37 +    }
    1.38 +
    1.39 +    private func syncMessages(_ sync: ImapSync) {
    1.40          do {
    1.41              try sync.syncMessages(firstUID: firstUID, lastUID: lastUID, updateExistsCount: true)
    1.42          } catch {
    1.43 @@ -109,7 +120,7 @@
    1.44          }
    1.45      }
    1.46  
    1.47 -    func deleteDeletedMails(context: NSManagedObjectContext, existingUIDs: Set<AnyHashable>) {
    1.48 +    private func deleteDeletedMails(context: NSManagedObjectContext, existingUIDs: Set<AnyHashable>) {
    1.49          guard
    1.50              let theFolderID = folderID,
    1.51              let folder = context.object(with: theFolderID) as? CdFolder else {
    1.52 @@ -132,7 +143,7 @@
    1.53  
    1.54      // MARK: - ImapSyncDelegate (internal)
    1.55  
    1.56 -    func folderSyncCompleted(_ sync: ImapSync, notification: Notification?) {
    1.57 +    fileprivate func folderSyncCompleted(_ sync: ImapSync, notification: Notification?) {
    1.58          // delete locally whatever was not mentioned in our big sync
    1.59          if let folder = sync.imapState.currentFolder {
    1.60              let existingUIDs = folder.existingUIDs()
    1.61 @@ -144,7 +155,7 @@
    1.62          markAsFinished()
    1.63      }
    1.64  
    1.65 -    func folderOpenCompleted(_ sync: ImapSync, notification: Notification?) {
    1.66 +    fileprivate func folderOpenCompleted(_ sync: ImapSync, notification: Notification?) {
    1.67          syncMessages(sync)
    1.68      }
    1.69