merge default IOS-1754
authorDirk Zimmermann <dz@pep.security>
Thu, 08 Aug 2019 07:25:12 +0200
branchIOS-1754
changeset 3951dd4ec3369111
parent 3947 5775c42aaaf4
parent 3950 e044c3b267d3
merge default
     1.1 --- a/MessageModel/MessageModel/CdObjectExtensions/CdIdentity/CdIdentity+UserID.swift	Wed Aug 07 15:26:46 2019 +0200
     1.2 +++ b/MessageModel/MessageModel/CdObjectExtensions/CdIdentity/CdIdentity+UserID.swift	Thu Aug 08 07:25:12 2019 +0200
     1.3 @@ -14,7 +14,7 @@
     1.4  
     1.5      // MARK: - MySelf
     1.6  
     1.7 -    public var isMySelf: Bool { //BUFF: For now, TRIPPLE CHECK!
     1.8 +    public var isMySelf: Bool {
     1.9          return userID == CdIdentity.pEpOwnUserID
    1.10      }
    1.11  }
     2.1 --- a/MessageModel/MessageModel/CdObjectExtensions/CdMessage+Extensions.swift	Wed Aug 07 15:26:46 2019 +0200
     2.2 +++ b/MessageModel/MessageModel/CdObjectExtensions/CdMessage+Extensions.swift	Thu Aug 08 07:25:12 2019 +0200
     2.3 @@ -201,7 +201,7 @@
     2.4      public func imapFields(context: NSManagedObjectContext? = nil) -> CdImapFields {
     2.5          guard let moc = context ?? managedObjectContext else {
     2.6              Log.shared.errorAndCrash("No Context!")
     2.7 -            let mainContext: NSManagedObjectContext = Stack.shared.mainContext //!!!: Mega wrong! Everyone MUST pass a context!
     2.8 +            let mainContext: NSManagedObjectContext = Stack.shared.mainContext //!!!: Mega wrong! Everyone MUST pass a context! Or we default.
     2.9              return imapFields(context: mainContext)
    2.10          }
    2.11          if let theImap = imap {
     3.1 --- a/MessageModel/MessageModel/Interface/PEPUtils/PEPUtils.swift	Wed Aug 07 15:26:46 2019 +0200
     3.2 +++ b/MessageModel/MessageModel/Interface/PEPUtils/PEPUtils.swift	Thu Aug 08 07:25:12 2019 +0200
     3.3 @@ -401,9 +401,4 @@
     3.4          try pEpSession.update(pEpID)
     3.5          try pEpSession.keyResetTrust(pEpID)
     3.6      }
     3.7 -
     3.8 -    //BUFF: rm if proven unused
     3.9 -    //    public static func ownIdentity(message: Message) -> Identity? {
    3.10 -    //        return message.parent.account.user
    3.11 -    //    }
    3.12  }
     4.1 --- a/MessageModel/MessageModel/Submodule/CoreData/Stack/Stack.swift	Wed Aug 07 15:26:46 2019 +0200
     4.2 +++ b/MessageModel/MessageModel/Submodule/CoreData/Stack/Stack.swift	Thu Aug 08 07:25:12 2019 +0200
     4.3 @@ -157,6 +157,8 @@
     4.4      /// MUST be used in tests only.
     4.5      /// - note: After calling this method, you MUST NOT use any privateConcurrentContext that has been created before calling this method.
     4.6      func reset() {
     4.7 +        objc_sync_enter(Stack.unitTestLock)
     4.8 +        defer { objc_sync_exit(Stack.unitTestLock) }
     4.9          guard MiscUtil.isUnitTest() else { fatalError("Not permitted to use in production code.") }
    4.10  
    4.11          mainContext.persistentStoreCoordinator?.persistentStores.forEach {
    4.12 @@ -173,6 +175,7 @@
    4.13          backgroundContext = nil
    4.14  
    4.15          Stack.shared = Stack()
    4.16 +
    4.17      }
    4.18  }
    4.19  
    4.20 @@ -217,6 +220,11 @@
    4.21          /// -note: MUST be used for MessageModelObject initialization ONLY!
    4.22          static var background: NSManagedObjectContext { return Stack.shared.backgroundContext }
    4.23      }
    4.24 +
    4.25 +    //MOVE:
    4.26 +    //!!!: must go away with mergeChanges
    4.27 +    /// Locks to assure nothing is called concurrently ito reset() (in unit tests)
    4.28 +    static let unitTestLock = NSObject()
    4.29  }
    4.30  
    4.31  // MARK: - Merge Contexts
    4.32 @@ -226,8 +234,16 @@
    4.33  extension Stack {
    4.34  
    4.35      private func mergeChanges(from notification: Notification, in context: NSManagedObjectContext) {
    4.36 -        context.perform {
    4.37 -            context.mergeChanges(fromContextDidSave: notification)
    4.38 +        if MiscUtil.isUnitTest() {
    4.39 +            objc_sync_enter(Stack.unitTestLock)
    4.40 +            context.performAndWait {
    4.41 +                context.mergeChanges(fromContextDidSave: notification)
    4.42 +            }
    4.43 +            objc_sync_exit(Stack.unitTestLock)
    4.44 +        } else {
    4.45 +            context.perform {
    4.46 +                context.mergeChanges(fromContextDidSave: notification)
    4.47 +            }
    4.48          }
    4.49      }
    4.50