IOS-1190 fixes: UI not informed about deleted messages.
authorbuff <andreas@pep-project.org>
Thu, 26 Jul 2018 16:38:08 +0200
changeset 56307d9696d72650
parent 5628 54976f907da8
child 5631 e910b70faf62
child 5632 1ebed3e498dd
IOS-1190 fixes: UI not informed about deleted messages.
pEpForiOS/Background/PersistentImapFolder.swift
     1.1 --- a/pEpForiOS/Background/PersistentImapFolder.swift	Thu Jul 26 11:41:26 2018 +0200
     1.2 +++ b/pEpForiOS/Background/PersistentImapFolder.swift	Thu Jul 26 16:38:08 2018 +0200
     1.3 @@ -275,23 +275,27 @@
     1.4      }
     1.5  
     1.6      override func setUIDValidity(_ theUIDValidity: UInt) {
     1.7 -        privateMOC.performAndWait() {
     1.8 +        guard let context = self.folder.managedObjectContext else {
     1.9 +            Log.shared.errorAndCrash(component: #function, errorString: "Dangling folder")
    1.10 +            return
    1.11 +        }
    1.12 +        context.performAndWait() {
    1.13              if self.folder.uidValidity != Int32(theUIDValidity) {
    1.14 -                Log.warn(
    1.15 -                    component: self.functionName(#function),
    1.16 -                    content: "UIValidity changed, deleting all messages. Folder \(String(describing: self.folder.name))")
    1.17 +                Log.warn(component: self.functionName(#function),
    1.18 +                         content: "UIValidity changed, deleting all messages. " +
    1.19 +                    "Folder \(String(describing: self.folder.name))")
    1.20                  // For some reason messages are not deleted when removing it from folder
    1.21                  // (even cascade is the delete rule). This causes crashes saving the context,
    1.22                  // as it holds invalid messages that have no parent folder.
    1.23                  // That is why we are deleting the messages manually.
    1.24                  if let messages =  self.folder.messages?.allObjects as? [CdMessage] {
    1.25                      for cdMessage in messages  {
    1.26 -                        self.privateMOC.delete(cdMessage)
    1.27 +                        cdMessage.deleteAndInformDelegate(context: context)
    1.28                      }
    1.29                  }
    1.30 +                self.folder.uidValidity = Int32(theUIDValidity)
    1.31 +                context.saveAndLogErrors()
    1.32              }
    1.33 -            self.folder.uidValidity = Int32(theUIDValidity)
    1.34 -            self.privateMOC.saveAndLogErrors()
    1.35          }
    1.36      }
    1.37