Skip to content
Snippets Groups Projects
Commit db852c7f authored by Oliver Wiese's avatar Oliver Wiese
Browse files

Fix encryption state in compose view

parent 40ca8bff
No related branches found
No related tags found
1 merge request!84Resolve "Missing backend features/connections for UI"
...@@ -26,9 +26,7 @@ class ComposeModel: ObservableObject { ...@@ -26,9 +26,7 @@ class ComposeModel: ObservableObject {
} }
recipientsModel.parentComposeModel = self recipientsModel.parentComposeModel = self
} }
// TODO: Add security state functionality
/// Generates mail and sends it. /// Generates mail and sends it.
func sendMail() { func sendMail() {
generateMail().send() generateMail().send()
...@@ -43,6 +41,13 @@ class ComposeModel: ObservableObject { ...@@ -43,6 +41,13 @@ class ComposeModel: ObservableObject {
for address in addresses { for address in addresses {
model.addNewAddress(address) model.addNewAddress(address)
} }
let frc = PersistentDataProvider.dataProvider.generateFetchedAddresesWithKeyResultsController(addresses: addresses)
if let records = frc.fetchedObjects {
if encryptionOn && records.count != addresses.count {
encryptionOn = false
}
}
} }
/// Generates OutgoingMail with given email contents. /// Generates OutgoingMail with given email contents.
......
...@@ -70,6 +70,9 @@ class RecipientFieldModel: ObservableObject { ...@@ -70,6 +70,9 @@ class RecipientFieldModel: ObservableObject {
/// - Parameter _: AddressRecord that gets added to array of recipients. /// - Parameter _: AddressRecord that gets added to array of recipients.
func selectContact(_ addressRecord: AddressRecord) { func selectContact(_ addressRecord: AddressRecord) {
selectedContacts.append(addressRecord) selectedContacts.append(addressRecord)
if !addressRecord.hasPublicKey {
self.parentRecipientModel?.parentComposeModel?.encryptionOn = false
}
text = "" text = ""
suggestions = [] suggestions = []
...@@ -85,8 +88,12 @@ class RecipientFieldModel: ObservableObject { ...@@ -85,8 +88,12 @@ class RecipientFieldModel: ObservableObject {
/// ///
/// - Parameter at: Index of contact to be removed from array of recipients. /// - Parameter at: Index of contact to be removed from array of recipients.
func deselectContact(at index: Int) { func deselectContact(at index: Int) {
selectedContacts.remove(at: index) let addr = selectedContacts[index]
selectedContacts.remove(at: index)
if !addr.hasPublicKey {
parentRecipientModel?.checkEncryption()
}
// TODO: See TODO in selectContact. // TODO: See TODO in selectContact.
parentRecipientModel?.parentComposeModel?.subject += "" parentRecipientModel?.parentComposeModel?.subject += ""
} }
...@@ -120,6 +127,9 @@ class RecipientFieldModel: ObservableObject { ...@@ -120,6 +127,9 @@ class RecipientFieldModel: ObservableObject {
if let addresses = frc.fetchedObjects, let addr = addresses.first { if let addresses = frc.fetchedObjects, let addr = addresses.first {
self.selectedContacts.append(addr) self.selectedContacts.append(addr)
if !addr.hasPublicKey {
self.parentRecipientModel?.parentComposeModel?.encryptionOn = false
}
} }
} }
} }
......
...@@ -32,9 +32,7 @@ class RecipientsModel: ObservableObject { ...@@ -32,9 +32,7 @@ class RecipientsModel: ObservableObject {
/// Used to show or hide Bcc field /// Used to show or hide Bcc field
var isEditingCcOrBcc: Bool = false { var isEditingCcOrBcc: Bool = false {
didSet { didSet {
print("isEditingCcOrBcc: \(isEditingCcOrBcc)")
updateShowBccField() updateShowBccField()
print("showBccField: \(showBccField)")
} }
} }
...@@ -79,6 +77,25 @@ class RecipientsModel: ObservableObject { ...@@ -79,6 +77,25 @@ class RecipientsModel: ObservableObject {
|| !bccModel.selectedContacts.isEmpty || !bccModel.selectedContacts.isEmpty
ccModel.type = showBccField ? .cc : .ccBcc ccModel.type = showBccField ? .cc : .ccBcc
} }
func checkEncryption() {
for addr in toModel.selectedContacts {
if !addr.hasPublicKey {
return
}
}
for addr in ccModel.selectedContacts {
if !addr.hasPublicKey {
return
}
}
for addr in bccModel.selectedContacts {
if !addr.hasPublicKey {
return
}
}
parentComposeModel?.encryptionOn = true
}
} }
/// Type of recipient field (to, cc, bcc). /// Type of recipient field (to, cc, bcc).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment