IOS-1521 cleanup
authorbuff <andreas@pep-project.org>
Fri, 07 Jun 2019 13:20:04 +0200
changeset 89650c001040c45c
parent 8960 18293306da7d
child 8966 7e88f3d23d86
IOS-1521 cleanup
pEpForiOS/Util/IdentityImageTool.swift
pEpForiOSTests/Models/SetOwnKeyViewModelTests.swift
pEpForiOSTests/TestUtils/Message+TestUtils.swift
pEpForiOSTests/TestUtils/TestUtil.swift
     1.1 --- a/pEpForiOS/Util/IdentityImageTool.swift	Thu Jun 06 17:42:26 2019 +0200
     1.2 +++ b/pEpForiOS/Util/IdentityImageTool.swift	Fri Jun 07 13:20:04 2019 +0200
     1.3 @@ -64,85 +64,10 @@
     1.4          IdentityImageTool.imageCache.removeAll()
     1.5      }
     1.6  
     1.7 -    //    func cachedIdentityImage(for identity: Identity) -> UIImage? { //!!!: cleanup
     1.8 -//        var searchKey: IdentityKey? = nil
     1.9 -//        let session = Session()
    1.10 -//        session.performAndWait {
    1.11 -//            let safeIdentity = identity.safeForSession(session)
    1.12 -//            searchKey = IdentityKey(identity: safeIdentity)
    1.13 -//        }
    1.14 -//        guard let key = searchKey else {
    1.15 -//            return nil
    1.16 -//        }
    1.17 -//        return IdentityImageTool.imageCache[key]
    1.18 -//    }
    1.19 -
    1.20      func cachedIdentityImage(for key: IdentityKey) -> UIImage? {
    1.21          return IdentityImageTool.imageCache[key]
    1.22      }
    1.23  
    1.24 -    /// Creates (and caches) the contact image to display for an identity.
    1.25 -    /// This is a possibly time consuming process and shold not be called from the main thread.
    1.26 -    ///
    1.27 -    /// - Parameters:
    1.28 -    ///   - identity: identity to create contact image to doisplay for
    1.29 -    ///   - imageSize: size of the image to create
    1.30 -    ///   - textColor: text color to use in case the resulting images contains the users initials
    1.31 -    ///   - backgroundColor: backgroundcolor to use in case the resulting images contains
    1.32 -    ///     the users initials
    1.33 -    /// - Returns: contact image to display
    1.34 -//    func identityImage(for identity: Identity, //!!!: cleanup
    1.35 -//                       imageSize: CGSize = CGSize.defaultAvatarSize,
    1.36 -//                       textColor: UIColor = UIColor.white,
    1.37 -//                       backgroundColor: UIColor = UIColor(hexString: "#c8c7cc")) -> UIImage? {
    1.38 -//        if let cachedImage = cachedIdentityImage(for: identity) {
    1.39 -//            // We have the image in cache. Return it.
    1.40 -//            return cachedImage
    1.41 -//        }
    1.42 -//
    1.43 -//        var image:UIImage?
    1.44 -//
    1.45 -//        let session = Session()
    1.46 -//        let safeIdentity = identity.safeForSession(session)
    1.47 -//        session.performAndWait { [weak self] in
    1.48 -//
    1.49 -//
    1.50 -//            guard let me = self else {
    1.51 -//                Log.shared.errorAndCrash(component: #function, errorString: "Lost myself")
    1.52 -//                return
    1.53 -//            }
    1.54 -//
    1.55 -//            if let addressBookID = safeIdentity.addressBookID {
    1.56 -//                // Get image from system AddressBook if any
    1.57 -//                let ab = AddressBook()
    1.58 -//                if let contact = ab.contactBy(addressBookID: addressBookID),
    1.59 -//                    let imgData = contact.thumbnailImageData {
    1.60 -//                    image = UIImage(data: imgData)
    1.61 -//                }
    1.62 -//            }
    1.63 -//
    1.64 -//            if image == nil {
    1.65 -//                // We cound not find an image anywhere. Let's create one with the initials
    1.66 -//                var initials = "?"
    1.67 -//                if let userName = safeIdentity.userName {
    1.68 -//                    initials = userName.initials()
    1.69 -//                } else {
    1.70 -//                    let namePart = safeIdentity.address.namePartOfEmail()
    1.71 -//                    initials = namePart.initials()
    1.72 -//                }
    1.73 -//                image =  me.identityImageFromName(initials: initials,
    1.74 -//                                              size: imageSize,
    1.75 -//                                              textColor: textColor,
    1.76 -//                                              imageBackgroundColor: backgroundColor)
    1.77 -//            }
    1.78 -//            if let safeImage = image {
    1.79 -//                // cache image
    1.80 -//                let saveKey = IdentityKey(identity: safeIdentity)
    1.81 -//                IdentityImageTool.imageCache[saveKey] = safeImage
    1.82 -//            }
    1.83 -//        }
    1.84 -//        return image
    1.85 -//    }
    1.86  
    1.87      func identityImage(for identityKey: IdentityKey,
    1.88                         imageSize: CGSize = CGSize.defaultAvatarSize,
     2.1 --- a/pEpForiOSTests/Models/SetOwnKeyViewModelTests.swift	Thu Jun 06 17:42:26 2019 +0200
     2.2 +++ b/pEpForiOSTests/Models/SetOwnKeyViewModelTests.swift	Fri Jun 07 13:20:04 2019 +0200
     2.3 @@ -127,7 +127,7 @@
     2.4          let attachments = theCdMessage.attachments?.array as? [CdAttachment] ?? []
     2.5          XCTAssertEqual(attachments.count, 0)
     2.6  
     2.7 -        guard let msg = theCdMessage.message() else {
     2.8 +        guard let msg = MessageModelObjectUtils.getMessage(fromCdMessage: theCdMessage) else {
     2.9              XCTFail()
    2.10              return
    2.11          }
     3.1 --- a/pEpForiOSTests/TestUtils/Message+TestUtils.swift	Thu Jun 06 17:42:26 2019 +0200
     3.2 +++ b/pEpForiOSTests/TestUtils/Message+TestUtils.swift	Fri Jun 07 13:20:04 2019 +0200
     3.3 @@ -55,7 +55,9 @@
     3.4          let pFolder =
     3.5              CdMessage.PredicateFactory.belongingToParentFolderNamed(parentFolderName: folderName)
     3.6          let p = NSCompoundPredicate(andPredicateWithSubpredicates: [pAccount, pUid, pFolder])
     3.7 -        let cdMessage = CdMessage.all(predicate: p)?.first as? CdMessage
     3.8 -        return cdMessage?.message()
     3.9 +        guard let cdMessage = CdMessage.all(predicate: p)?.first as? CdMessage else {
    3.10 +            return nil
    3.11 +        }
    3.12 +        return MessageModelObjectUtils.getMessage(fromCdMessage: cdMessage)
    3.13      }
    3.14  }
     4.1 --- a/pEpForiOSTests/TestUtils/TestUtil.swift	Thu Jun 06 17:42:26 2019 +0200
     4.2 +++ b/pEpForiOSTests/TestUtils/TestUtil.swift	Fri Jun 07 13:20:04 2019 +0200
     4.3 @@ -710,14 +710,16 @@
     4.4      static func setUpPepFromMail(emailFilePath: String,
     4.5                                   decryptDelegate: DecryptMessagesOperationDelegateProtocol? = nil)
     4.6          -> (mySelf: Identity, partner: Identity, message: Message)? {
     4.7 -            if let (mySelfID, partnerID, message) = cdMessageAndSetUpPepFromMail(
     4.8 -                emailFilePath: emailFilePath, decryptDelegate: decryptDelegate),
     4.9 -                let msg = message.message(),
    4.10 +            guard
    4.11 +                let (mySelfID, partnerID, cdMessage) = cdMessageAndSetUpPepFromMail(
    4.12 +                    emailFilePath: emailFilePath, decryptDelegate: decryptDelegate),
    4.13                  let mySelf = mySelfID.identity(),
    4.14 -                let partner = partnerID.identity() {
    4.15 -                return (mySelf: mySelf, partner: partner, message: msg)
    4.16 +                let partner = partnerID.identity()
    4.17 +                else {
    4.18 +                    return nil
    4.19              }
    4.20 -            return nil
    4.21 +            let msg = MessageModelObjectUtils.getMessage(fromCdMessage: cdMessage)
    4.22 +            return (mySelf: mySelf, partner: partner, message: msg)
    4.23      }
    4.24  
    4.25      /**