in components/autofill/src/sync/address/incoming.rs [38:79]
fn update_name(payload_content: &mut IncomingContent<AddressPayload>, local_name: String) {
// Check if the kind is IncomingKind::Content and get a mutable reference to internal_address
let internal_address =
if let IncomingKind::Content(internal_address) = &mut payload_content.kind {
internal_address
} else {
return;
};
let entry = &mut internal_address.entry;
// Return early if the name is not empty or `*-name`` parts are empty
if !entry.name.is_empty()
|| (entry.given_name.is_empty()
&& entry.additional_name.is_empty()
&& entry.family_name.is_empty())
{
return;
}
// Split the local name into its parts
let NameParts {
given,
middle,
family,
} = split_name(&local_name);
// Check if the local name matches the entry names
let is_local_name_matching =
entry.given_name == given && entry.additional_name == middle && entry.family_name == family;
// Update the name based on whether the local name matches
entry.name = if is_local_name_matching {
local_name
} else {
join_name_parts(&NameParts {
given: entry.given_name.clone(),
middle: entry.additional_name.clone(),
family: entry.family_name.clone(),
})
};
}