IOS-358 SendLayerDelegate -> MessageFolderDelegate
authorDirk Zimmermann <dirk@pep-project.org>
Mon, 19 Dec 2016 17:00:48 +0100
changeset 134847fb980d20d4
parent 1347 a0479265154f
child 1349 abfa065128fa
IOS-358 SendLayerDelegate -> MessageFolderDelegate
pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
pEpForiOS/UI/MockData.swift
pEpForiOSTests/NetworkServiceTests.swift
     1.1 --- a/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Mon Dec 19 14:58:40 2016 +0100
     1.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Mon Dec 19 17:00:48 2016 +0100
     1.3 @@ -29,7 +29,6 @@
     1.4  
     1.5      var config: EmailListConfig?
     1.6      var state = UIState()
     1.7 -    var accounts = [Account]()
     1.8      let searchController = UISearchController(searchResultsController: nil)
     1.9  
    1.10      required init?(coder aDecoder: NSCoder) {
    1.11 @@ -55,6 +54,13 @@
    1.12  
    1.13          initialConfig()
    1.14          updateModel()
    1.15 +
    1.16 +        MessageModelConfig.messageFolderDelegate = self
    1.17 +    }
    1.18 +
    1.19 +    override func viewWillDisappear(_ animated: Bool) {
    1.20 +        super.viewWillDisappear(animated)
    1.21 +        MessageModelConfig.messageFolderDelegate = nil
    1.22      }
    1.23      
    1.24      func initialConfig() {
    1.25 @@ -66,8 +72,7 @@
    1.26              config = EmailListConfig(appConfig: appDelegate.appConfig,
    1.27                                       folder: Folder.unifiedInbox())
    1.28          }
    1.29 -        accounts = Account.all()
    1.30 -        if accounts.isEmpty {
    1.31 +        if Account.all().isEmpty {
    1.32              performSegue(withIdentifier:.segueAddNewAccount, sender: self)
    1.33          }
    1.34      }
    1.35 @@ -359,3 +364,15 @@
    1.36          }
    1.37      }
    1.38  }
    1.39 +
    1.40 +// MARK: - MessageFolderDelegate
    1.41 +
    1.42 +extension EmailListViewController: MessageFolderDelegate {
    1.43 +    func didChange(messageFolder: MessageFolder) {
    1.44 +        if let msg = messageFolder as? Message {
    1.45 +            if msg.isOriginal {
    1.46 +                // new message, add it
    1.47 +            }
    1.48 +        }
    1.49 +    }
    1.50 +}
     2.1 --- a/pEpForiOS/UI/MockData.swift	Mon Dec 19 14:58:40 2016 +0100
     2.2 +++ b/pEpForiOS/UI/MockData.swift	Mon Dec 19 17:00:48 2016 +0100
     2.3 @@ -29,8 +29,7 @@
     2.4              [("INBOX", FolderType.inbox), ("Drafts", FolderType.drafts),
     2.5               ("Outbox", FolderType.localOutbox)] {
     2.6                  let folder = Folder.createRootFolder(
     2.7 -                    name: name, uuid: UUID.generate(), account: account)
     2.8 -                folder.folderType = folderType
     2.9 +                    name: name, uuid: UUID.generate(), account: account, folderType: folderType)
    2.10                  insertMessages(folder: folder)
    2.11          }
    2.12      }
    2.13 @@ -48,8 +47,8 @@
    2.14      }
    2.15      
    2.16      static func createFolder(_ account: Account) -> Folder {
    2.17 -        let f = Folder.createRootFolder(name: "pEpSi", uuid: UUID.generate(), account: account)
    2.18 -        f.folderType = .normal
    2.19 +        let f = Folder.createRootFolder(name: "pEpSi", uuid: UUID.generate(), account: account,
    2.20 +                                        folderType: .normal)
    2.21          MockData.insertMessages(folder: f)
    2.22          return f
    2.23      }
     3.1 --- a/pEpForiOSTests/NetworkServiceTests.swift	Mon Dec 19 14:58:40 2016 +0100
     3.2 +++ b/pEpForiOSTests/NetworkServiceTests.swift	Mon Dec 19 17:00:48 2016 +0100
     3.3 @@ -142,11 +142,11 @@
     3.4          XCTAssertGreaterThan(allCdMessages.count, cdDecryptAgainCount)
     3.5  
     3.6          var decryptAgainCount = 0
     3.7 -        let inbox = Folder.unifiedInbox()
     3.8 -        let mc = inbox.messageCount()
     3.9 +        let unifiedInbox = Folder.unifiedInbox()
    3.10 +        let mc = unifiedInbox.messageCount()
    3.11          XCTAssertGreaterThan(mc, 0)
    3.12          for i in 0..<mc {
    3.13 -            let msg = inbox.messageAt(index: i)
    3.14 +            let msg = unifiedInbox.messageAt(index: i)
    3.15              XCTAssertNotNil(msg?.shortMessage)
    3.16              XCTAssertTrue(
    3.17                  msg?.longMessage != nil || msg?.longMessageFormatted != nil ||
    3.18 @@ -161,11 +161,14 @@
    3.19          }
    3.20          XCTAssertEqual(cdDecryptAgainCount, decryptAgainCount)
    3.21  
    3.22 +        let inbox = Folder.from(cdFolder: cdFolder)
    3.23          XCTAssertEqual(sendLayerDelegate.messageIDs.count, mc)
    3.24          XCTAssertEqual(modelDelegate.messages.count, mc)
    3.25          for msg in modelDelegate.messages {
    3.26              XCTAssertTrue(msg.isOriginal)
    3.27              XCTAssertTrue(sendLayerDelegate.messageIDs.contains(msg.messageID))
    3.28 +            XCTAssertTrue(inbox.contains(message: msg))
    3.29 +            XCTAssertTrue(unifiedInbox.contains(message: msg))
    3.30          }
    3.31      }
    3.32