Commit e83706ef authored by Oliver Wiese's avatar Oliver Wiese

improve user interaction

parent a6ff2ddb
......@@ -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
......
......@@ -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?
}
......
......@@ -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})
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment