IOS-851 shows receipient, not sender, in drafts and sent folders
authorbuff <andreas@pep-project.org>
Tue, 05 Dec 2017 10:40:25 +0100
changeset 35229326deae631d
parent 3521 2628538df4d5
child 3523 b5dacb7d0c9a
IOS-851 shows receipient, not sender, in drafts and sent folders
pEpForiOS/Base.lproj/Main.storyboard
pEpForiOS/UI/EmailDisplay/EmailListViewCell.swift
pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
pEpForiOS/UI/EmailDisplay/EmailListViewModel.swift
pEpForiOS/UI/EmailDisplay/PreviewMessage.swift
     1.1 --- a/pEpForiOS/Base.lproj/Main.storyboard	Mon Dec 04 17:39:36 2017 +0100
     1.2 +++ b/pEpForiOS/Base.lproj/Main.storyboard	Tue Dec 05 10:40:25 2017 +0100
     1.3 @@ -117,12 +117,12 @@
     1.4                                  </tableViewCellContentView>
     1.5                                  <connections>
     1.6                                      <outlet property="accessoryDisclosureIndicator" destination="MDV-jl-oqJ" id="qFC-0O-RXG"/>
     1.7 +                                    <outlet property="addressLabel" destination="tWZ-jW-sUg" id="4xO-Zs-PDB"/>
     1.8                                      <outlet property="attachmentIcon" destination="3BC-6k-zL0" id="ZMO-5d-OGj"/>
     1.9                                      <outlet property="contactImageView" destination="YqR-ga-Tf9" id="E2c-EP-D1U"/>
    1.10                                      <outlet property="dateLabel" destination="Wkg-wf-Dbd" id="TSP-tH-GR2"/>
    1.11                                      <outlet property="flaggedImageView" destination="BLq-0g-OgR" id="a6H-Fv-kDq"/>
    1.12                                      <outlet property="ratingImage" destination="m0u-Jn-mQU" id="Xod-5v-9K3"/>
    1.13 -                                    <outlet property="senderLabel" destination="tWZ-jW-sUg" id="lM6-YZ-J7S"/>
    1.14                                      <outlet property="subjectLabel" destination="5Py-55-oem" id="UtV-Po-SPg"/>
    1.15                                      <outlet property="summaryLabel" destination="BvI-Zi-zU6" id="oGG-8D-EeC"/>
    1.16                                  </connections>
     2.1 --- a/pEpForiOS/UI/EmailDisplay/EmailListViewCell.swift	Mon Dec 04 17:39:36 2017 +0100
     2.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailListViewCell.swift	Tue Dec 05 10:40:25 2017 +0100
     2.3 @@ -15,7 +15,7 @@
     2.4      static var flaggedImage: UIImage? = nil
     2.5      static var emptyContactImage = UIImage.init(named: "empty-avatar")
     2.6  
     2.7 -    @IBOutlet weak var senderLabel: UILabel!
     2.8 +    @IBOutlet weak var addressLabel: UILabel!
     2.9      @IBOutlet weak var subjectLabel: UILabel!
    2.10      @IBOutlet weak var summaryLabel: UILabel!
    2.11      @IBOutlet weak var dateLabel: UILabel!
    2.12 @@ -87,7 +87,7 @@
    2.13      }
    2.14  
    2.15      private func resetToDefault() {
    2.16 -        senderLabel.text = nil
    2.17 +        addressLabel.text = nil
    2.18          subjectLabel.text = nil
    2.19          summaryLabel.text = nil
    2.20          dateLabel.text = nil
    2.21 @@ -116,21 +116,21 @@
    2.22      }
    2.23  
    2.24      private func setSeen() {
    2.25 -        if let font = senderLabel.font {
    2.26 +        if let font = addressLabel.font {
    2.27              let font = UIFont.systemFont(ofSize: font.pointSize)
    2.28              setupLabels(font: font)
    2.29          }
    2.30      }
    2.31  
    2.32      private func unsetSeen() {
    2.33 -        if let font = senderLabel.font {
    2.34 +        if let font = addressLabel.font {
    2.35              let font = UIFont.boldSystemFont(ofSize: font.pointSize)
    2.36              setupLabels(font: font)
    2.37          }
    2.38      }
    2.39  
    2.40      func setupLabels(font: UIFont) {
    2.41 -        senderLabel.font = font
    2.42 +        addressLabel.font = font
    2.43          subjectLabel.font = font
    2.44          summaryLabel.font = font
    2.45          dateLabel.font = font
     3.1 --- a/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Mon Dec 04 17:39:36 2017 +0100
     3.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Tue Dec 05 10:40:25 2017 +0100
     3.3 @@ -143,6 +143,42 @@
     3.4      private func realNameOfFolderToShow() -> String? {
     3.5          return folderToShow?.realName
     3.6      }
     3.7 +
     3.8 +    private func address(forRowAt indexPath: IndexPath) -> String {
     3.9 +        guard
    3.10 +            let saveModel = model,
    3.11 +            let row = saveModel.row(for: indexPath),
    3.12 +            let folder = folderToShow
    3.13 +            else {
    3.14 +                Log.shared.errorAndCrash(component: #function, errorString: "Invalid state")
    3.15 +                return ""
    3.16 +        }
    3.17 +        switch folder.folderType {
    3.18 +        case .all: fallthrough
    3.19 +        case .archive: fallthrough
    3.20 +        case .spam: fallthrough
    3.21 +        case .trash: fallthrough
    3.22 +        case .flagged: fallthrough
    3.23 +        case .inbox: fallthrough
    3.24 +        case .normal:
    3.25 +            return row.from
    3.26 +        case .drafts: fallthrough
    3.27 +        case .sent:
    3.28 +            return row.to
    3.29 +        }
    3.30 +    }
    3.31 +
    3.32 +    private func shouldShowAccessoryDisclosureIndicator() -> Bool {
    3.33 +        guard let folder = folderToShow else {
    3.34 +            Log.shared.errorAndCrash(component: #function, errorString: "No folder")
    3.35 +            return true
    3.36 +        }
    3.37 +        if folder.folderType == .drafts {
    3.38 +            // Mails in drafts folder can only be opened in compose mode, which is shown modally.
    3.39 +            return false
    3.40 +        }
    3.41 +        return true
    3.42 +    }
    3.43      
    3.44      private func configure(cell: EmailListViewCell, for indexPath: IndexPath) {
    3.45          // Configure lightweight stuff on main thread ...
    3.46 @@ -153,15 +189,9 @@
    3.47              Log.shared.errorAndCrash(component: #function, errorString: "We should have a row here")
    3.48              return
    3.49          }
    3.50 -        guard let folder = folderToShow else {
    3.51 -            Log.shared.errorAndCrash(component: #function, errorString: "No folder")
    3.52 -            return
    3.53 -        }
    3.54 -        if folder.folderType == .drafts {
    3.55 -            // Mails in drafts folder can only be opened in compose mode, which is shown modally.
    3.56 -            cell.accessoryDisclosureIndicator.isHidden = true
    3.57 -        }
    3.58 -        cell.senderLabel.text = row.from
    3.59 +        // Mails in drafts folder can only be opened in compose mode, which is shown modally.
    3.60 +        cell.accessoryDisclosureIndicator.isHidden = shouldShowAccessoryDisclosureIndicator()
    3.61 +        cell.addressLabel.text = address(forRowAt: indexPath)
    3.62          cell.subjectLabel.text = row.subject
    3.63          cell.summaryLabel.text = row.bodyPeek
    3.64          cell.isFlagged = row.isFlagged
    3.65 @@ -182,7 +212,7 @@
    3.66                  var senderImage: UIImage?
    3.67                  if row.senderContactImage == nil {
    3.68                      // image for identity has not been cached yet
    3.69 -                    // Get and cache it here in the background ...
    3.70 +                    // Get (and cache) it here in the background ...
    3.71                      senderImage = strongSelf.model?.senderImage(forCellAt: indexPath)
    3.72                      
    3.73                      // ... and set it on the main queue
     4.1 --- a/pEpForiOS/UI/EmailDisplay/EmailListViewModel.swift	Mon Dec 04 17:39:36 2017 +0100
     4.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailListViewModel.swift	Tue Dec 05 10:40:25 2017 +0100
     4.3 @@ -35,6 +35,7 @@
     4.4          var ratingImage: UIImage?
     4.5          var showAttchmentIcon: Bool = false
     4.6          let from: String
     4.7 +        let to: String
     4.8          let subject: String
     4.9          let bodyPeek: String
    4.10          var isFlagged: Bool = false
    4.11 @@ -45,6 +46,7 @@
    4.12              self.senderContactImage = senderContactImage
    4.13              showAttchmentIcon = pvmsg.hasAttachments
    4.14              from = pvmsg.from.userNameOrAddress
    4.15 +            to = pvmsg.to
    4.16              subject = pvmsg.subject
    4.17              bodyPeek = pvmsg.bodyPeek
    4.18              isFlagged = pvmsg.isFlagged
     5.1 --- a/pEpForiOS/UI/EmailDisplay/PreviewMessage.swift	Mon Dec 04 17:39:36 2017 +0100
     5.2 +++ b/pEpForiOS/UI/EmailDisplay/PreviewMessage.swift	Tue Dec 05 10:40:25 2017 +0100
     5.3 @@ -17,6 +17,7 @@
     5.4      var pEpRating: Int
     5.5      let hasAttachments: Bool
     5.6      let from: Identity
     5.7 +    let to: String
     5.8      let subject: String
     5.9      var bodyPeek: String
    5.10      var isFlagged = false
    5.11 @@ -34,6 +35,7 @@
    5.12              pEpRating = rating
    5.13              hasAttachments = msg.attachments.count > 0
    5.14              from = saveFrom
    5.15 +            to = msg.to.first?.userNameOrAddress ?? ""
    5.16              subject = msg.shortMessage ?? ""
    5.17              isFlagged = msg.imapFlags?.flagged ?? false
    5.18              isSeen = msg.imapFlags?.seen ?? false
    5.19 @@ -52,6 +54,7 @@
    5.20              pEpRating = 0
    5.21              hasAttachments = msg.attachments.count > 0
    5.22              from = Identity(address: "")
    5.23 +            to = msg.to.first?.userNameOrAddress ?? ""
    5.24              subject = msg.shortMessage ?? ""
    5.25              bodyPeek = msg.longMessageFormatted ?? msg.longMessage ?? ""
    5.26              isFlagged = msg.imapFlags?.flagged ?? false
    5.27 @@ -60,7 +63,6 @@
    5.28          }
    5.29      }
    5.30  
    5.31 -
    5.32      private func displayBody(fromMessage msg: Message) -> String {
    5.33          var body: String?
    5.34          if let text = msg.longMessage {