From ad640e163c6727a16ca4aa857ade67c84c5027da Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 12 Feb 2021 11:13:53 +0100 Subject: [PATCH] add dc_contact_get_auth_name() --- deltachat-ffi/deltachat.h | 22 ++++++++++++++++++++++ deltachat-ffi/src/lib.rs | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 47a297867..c6ee50fd9 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -4031,6 +4031,28 @@ char* dc_contact_get_addr (const dc_contact_t* contact); char* dc_contact_get_name (const dc_contact_t* contact); +/** + * Get original contact name. + * This is the name of the contact as defined by the contact themself. + * If the contact themself does not define such a name, + * an empty string is returned. + * + * This function is typically only needed for the controls that + * allow the local user to edit the name, + * eg. you want to show the original name somewhere in the edit dialog + * (you cannot use dc_contact_get_display_name() for that as + * this would return previously set edited names). + * + * In most other situations than the name-edit-dialog, + * as lists, messages etc. use dc_contact_get_display_name(). + * + * @memberof dc_contact_t + * @return String with the original name, must be released using dc_str_unref(). + * Empty string if unset, never returns NULL. + */ +char* dc_contact_get_auth_name (const dc_contact_t* contact); + + /** * Get display name. This is the name as defined by the contact himself, * modified by the user or, if both are unset, the email address. diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 9a54da7c2..0a8c53ea0 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -3220,6 +3220,16 @@ pub unsafe extern "C" fn dc_contact_get_name(contact: *mut dc_contact_t) -> *mut ffi_contact.contact.get_name().strdup() } +#[no_mangle] +pub unsafe extern "C" fn dc_contact_get_auth_name(contact: *mut dc_contact_t) -> *mut libc::c_char { + if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_get_auth_name()"); + return "".strdup(); + } + let ffi_contact = &*contact; + ffi_contact.contact.get_authname().strdup() +} + #[no_mangle] pub unsafe extern "C" fn dc_contact_get_display_name( contact: *mut dc_contact_t,