api: add ContactId.set_name()

This API allows to explicitly set
a name of the contact
instead of trying to create a new contact
with the same address.

Not all contacts are identified
by the email address
and we are going to introduce
contacts identified by their keys.
This commit is contained in:
link2xt
2025-03-19 18:22:42 +00:00
committed by l
parent 5280448cd3
commit b5fa6553af
2 changed files with 26 additions and 4 deletions

View File

@@ -1537,6 +1537,7 @@ impl CommandApi {
Ok(())
}
/// Sets display name for existing contact.
async fn change_contact_name(
&self,
account_id: u32,
@@ -1545,9 +1546,7 @@ impl CommandApi {
) -> Result<()> {
let ctx = self.get_context(account_id).await?;
let contact_id = ContactId::new(contact_id);
let contact = Contact::get_by_id(&ctx, contact_id).await?;
let addr = contact.get_addr();
Contact::create(&ctx, &name, addr).await?;
contact_id.set_name(&ctx, &name).await?;
Ok(())
}