Skip to content

Commit

Permalink
refactor: Fix the shouldAddUserProposal
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu-dgl committed Jan 13, 2025
1 parent 1168ce4 commit e7aac2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Mail/Views/New Message/AutocompletionCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ struct AutocompletionCell: View {
) {
self.addRecipient = { addRecipient($0 as! MergedContact) }
self.autocompletion = autocompletion
self.highlight = highlight
self.alreadyAppend = alreadyAppend
self.unknownRecipient = unknownRecipient
title = autocompletion.name
title = autocompletion.email
subtitle = autocompletion.email
}

Expand All @@ -97,6 +98,7 @@ struct AutocompletionCell: View {
) {
self.addRecipient = { addRecipient($0 as! GroupContact) }
self.autocompletion = autocompletion
self.highlight = highlight
self.alreadyAppend = alreadyAppend
self.unknownRecipient = unknownRecipient
self.title = title
Expand Down
12 changes: 7 additions & 5 deletions Mail/Views/New Message/AutocompletionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,19 @@ struct AutocompletionView: View {

shouldAddUserProposal = !(realResults.count == 1 && realResults.first?.autocompletableName == textDebounce.text)

if shouldAddUserProposal {
combinedResults.append(MergedContact(email: textDebounce.text, local: nil, remote: nil))
}

combinedResults.sort { lhs, rhs in
guard let lhsContact = lhs as? MergedContact,
let rhsContact = rhs as? MergedContact else { return false }
return sortByRemoteAndName(lhs: lhsContact, rhs: rhsContact)
}

let result = combinedResults.prefix(10)
var result = combinedResults.prefix(10)

if shouldAddUserProposal {
let mergedContact = MergedContact(email: textDebounce.text, local: nil, remote: nil)
mergedContact.name = textDebounce.text
result.append(mergedContact)
}

autocompletion = Array(result)
}
Expand Down

0 comments on commit e7aac2a

Please sign in to comment.