diff --git a/enzevalos_iphone/SwiftUI/Data/DisplayProtocols.swift b/enzevalos_iphone/SwiftUI/Data/DisplayProtocols.swift index 85537697b9c9bf9fb721986eecf099344b77c8a3..e8e38c658c256c9cfbaf9efde91578288f14f9b2 100644 --- a/enzevalos_iphone/SwiftUI/Data/DisplayProtocols.swift +++ b/enzevalos_iphone/SwiftUI/Data/DisplayProtocols.swift @@ -76,6 +76,13 @@ protocol DisplayContact { var keyRecord: KeyRecord? { get } } +extension DisplayContact { + + func findAddress(temp: Bool) -> MailAddress { + return DataHandler.handler.getMailAddress(addr, temporary: temp) + } +} + protocol DisplayMail { associatedtype C: DisplayContact diff --git a/enzevalos_iphone/SwiftUI/Read/ReadViewCoordinator.swift b/enzevalos_iphone/SwiftUI/Read/ReadViewCoordinator.swift index 570a2e2f0d705f3c3d1392b22a1acb2b4bbf631e..19d831b8fe88a0244c5701b4972ce84e489906b4 100644 --- a/enzevalos_iphone/SwiftUI/Read/ReadViewCoordinator.swift +++ b/enzevalos_iphone/SwiftUI/Read/ReadViewCoordinator.swift @@ -84,7 +84,7 @@ class ReadViewCoordinator { AppDelegate.getAppDelegate().mailHandler.move(mails: [mail], from: mail.folder.path, to: UserManager.backendArchiveFolderPath) } - func pushComposeView(to: [EnzevalosContact], cc: [EnzevalosContact], bcc: [EnzevalosContact], subject: String?, body: String?, responseType: ResponseType?) { + func pushComposeView(to: [MailAddress], cc: [MailAddress], bcc: [MailAddress], subject: String?, body: String?, responseType: ResponseType?) { let vc = mainStoryboard.instantiateViewController(identifier: ViewID.ComposeView.rawValue) var prefilledMail: EphemeralMail? if let subject = subject, let body = body, let responseType = responseType { @@ -158,13 +158,10 @@ class ReadViewCoordinator { delete(mail: m) } func invitePerson <M: DisplayMail> (mail: M) { - guard let sender = mail.sender.keyRecord else { - return - } let body = String(format: NSLocalizedString("inviteText", comment: "Body for the invitation mail"),StudySettings.studyID) let subject = NSLocalizedString("inviteSubject", comment: "Subject for the invitation mail") - var to = [EnzevalosContact] () - to.append(sender.ezContact) + var to = [MailAddress] () + to.append(mail.sender.findAddress(temp: false)) to.append(contentsOf: findPersisentContact(persons: mail.ccs)) to.append(contentsOf: findPersisentContact(persons: mail.tos)) to = to.filter({!$0.hasKey}) @@ -176,7 +173,7 @@ class ReadViewCoordinator { guard let sender = mail.sender.keyRecord else { return } - let to = [sender.contact] + let to = [sender.findAddress(temp: false)] var body = NSLocalizedString("ReadView.PrefilledMail.AskForResend.Body", comment: "") body += preparePreviousMailBody(mail: mail) pushComposeView(to: to, cc: [], bcc: [], subject: mail.subject, body: body, responseType: .Reply) @@ -187,17 +184,14 @@ class ReadViewCoordinator { guard let sender = mail.sender.keyRecord else { return } - let to = [sender.contact] + let to = [sender.findAddress(temp: false)] let body = NSLocalizedString("ReadView.PrefilledMail.AskForPK.Body", comment: "") let subject = NSLocalizedString("ReadView.PrefilledMail.AskForPK.Subject", comment: "") pushComposeView(to: to, cc: [], bcc: [], subject: subject, body: body, responseType: .none) } func askSenderToConfirm <M: DisplayMail>(mail: M) { - guard let sender = mail.sender.keyRecord else { - return - } - let to = [sender.contact] + let to = [mail.sender.findAddress(temp: false)] let body = NSLocalizedString("didYouSendThis", comment: "Did you sent this mail?") + "\n"+preparePreviousMailBody(mail: mail) pushComposeView(to: to, cc: [], bcc: [], subject: mail.subject, body: body, responseType: .Reply) } @@ -230,11 +224,11 @@ class ReadViewCoordinator { return body } - private func findPersisentContact (persons: [DisplayContact]) -> [EnzevalosContact] { - var result = [EnzevalosContact] () + private func findPersisentContact (persons: [DisplayContact]) -> [MailAddress] { + var result = [MailAddress] () for p in persons { if let contact = p.keyRecord { - result.append(contact.ezContact) + result.append(contact.findAddress(temp: true)) } // TODO: Add data handler? } diff --git a/enzevalos_iphone/SwiftUI/Read/Tabbed Views/MessageViewMain.swift b/enzevalos_iphone/SwiftUI/Read/Tabbed Views/MessageViewMain.swift index 60ca018b0f81a9e6a09e2d17dfb61ec8297b3328..52248f2b2730afe66e7ab864bd3576ced2d9e68d 100644 --- a/enzevalos_iphone/SwiftUI/Read/Tabbed Views/MessageViewMain.swift +++ b/enzevalos_iphone/SwiftUI/Read/Tabbed Views/MessageViewMain.swift @@ -211,11 +211,11 @@ struct MessageViewMain <M: DisplayMail>: View { private func newMail(type: ResponseType, toAll: Bool) { if let coord = AppDelegate.getAppDelegate().readViewCoordinator { - var to = [EnzevalosContact] () - var cc = [EnzevalosContact]() - var bcc = [EnzevalosContact] () - if let sender = mail.sender.keyRecord?.ezContact, type != .Forward { - to.append(sender) + var to = [MailAddress] () + var cc = [MailAddress]() + var bcc = [MailAddress] () + if type != .Forward { + to.append(mail.sender.findAddress(temp: false)) } if toAll { to.append(contentsOf: makeEnzContactArray(contacts: mail.tos)) @@ -226,8 +226,8 @@ struct MessageViewMain <M: DisplayMail>: View { } } - private func makeEnzContactArray(contacts: [DisplayContact]) -> [EnzevalosContact] { - let enzContacts = contacts.map({$0.keyRecord?.ezContact}) + private func makeEnzContactArray(contacts: [DisplayContact]) -> [MailAddress] { + let enzContacts = contacts.map({$0.findAddress(temp: true)}) return enzContacts.compactMap({$0}) } }