From 2a8c418d5419dde475c4f80fcf91dc9c62fc78d7 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Sat, 23 Jan 2021 14:06:42 +0100 Subject: [PATCH] remove dc_contact_get_first_name() api instead, dc_contact_get_display_name() should be used. dc_contact_get_first_name() was created to save some space on the screen, esp. on mobile devices, however, this does not always work and has issues on its own with some names ("Dr. Strangelove", ":) Name" and so on). as with mailing lists, more apis with first_name() would be needed, we decided to drop that instead of following that way. it is also less an issue as some years ago as screens have become larger, if really, needed, the ui can handle that more gracefully, however, just using dc_contact_get_display_name() should be fine as well. --- deltachat-ffi/deltachat.h | 15 +-------------- deltachat-ffi/src/lib.rs | 12 ------------ src/contact.rs | 20 -------------------- src/message.rs | 2 +- 4 files changed, 2 insertions(+), 47 deletions(-) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 283a7601d..ffa06ea6a 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -3834,7 +3834,7 @@ dc_msg_t* dc_msg_get_quoted_msg (const dc_msg_t* msg); * By default, these names are equal, * but functions working with contact names * (e.g. dc_contact_get_name(), dc_contact_get_display_name(), - * dc_contact_get_name_n_addr(), dc_contact_get_first_name(), + * dc_contact_get_name_n_addr(), * dc_create_contact() or dc_add_address_book()) * only affect the given-name. */ @@ -3924,19 +3924,6 @@ char* dc_contact_get_display_name (const dc_contact_t* contact); char* dc_contact_get_name_n_addr (const dc_contact_t* contact); -/** - * Get the part of the name before the first space. In most languages, this seems to be - * the prename. If there is no space, the full display name is returned. - * If the display name is not set, the e-mail address is returned. - * - * @memberof dc_contact_t - * @param contact The contact object. - * @return String with the name to display, must be released using dc_str_unref(). - * Never returns NULL. - */ -char* dc_contact_get_first_name (const dc_contact_t* contact); - - /** * Get the contact's profile image. * This is the image set by each remote user on their own diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 577de039f..f54539f4a 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -3151,18 +3151,6 @@ pub unsafe extern "C" fn dc_contact_get_name_n_addr( ffi_contact.contact.get_name_n_addr().strdup() } -#[no_mangle] -pub unsafe extern "C" fn dc_contact_get_first_name( - contact: *mut dc_contact_t, -) -> *mut libc::c_char { - if contact.is_null() { - eprintln!("ignoring careless call to dc_contact_get_first_name()"); - return "".strdup(); - } - let ffi_contact = &*contact; - ffi_contact.contact.get_first_name().strdup() -} - #[no_mangle] pub unsafe extern "C" fn dc_contact_get_profile_image( contact: *mut dc_contact_t, diff --git a/src/contact.rs b/src/contact.rs index 6a3e74452..d85a01d51 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -888,16 +888,6 @@ impl Contact { (&self.addr).into() } - /// Get the part of the name before the first space. In most languages, this seems to be - /// the prename. If there is no space, the full display name is returned. - /// If the display name is not set, the e-mail address is returned. - pub fn get_first_name(&self) -> &str { - if !self.name.is_empty() { - return get_first_name(&self.name); - } - &self.addr - } - /// Get the contact's profile image. /// This is the image set by each remote user on their own /// using dc_set_config(context, "selfavatar", image). @@ -1035,11 +1025,6 @@ impl Contact { } } -/// Extracts first name from full name. -fn get_first_name(full_name: &str) -> &str { - full_name.splitn(2, ' ').next().unwrap_or_default() -} - /// Returns false if addr is an invalid address, otherwise true. pub fn may_be_valid_addr(addr: &str) -> bool { let res = addr.parse::(); @@ -1283,11 +1268,6 @@ mod tests { assert_ne!(addr_normalize("John@Doe.com"), "john@doe.com"); } - #[test] - fn test_get_first_name() { - assert_eq!(get_first_name("John Doe"), "John"); - } - #[test] fn test_split_address_book() { let book = "Name one\nAddress one\nName two\nAddress two\nrest name"; diff --git a/src/message.rs b/src/message.rs index 2b5da1270..185edc8dd 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1032,7 +1032,7 @@ impl Lot { self.text1 = None; } } else if let Some(contact) = contact { - self.text1 = Some(contact.get_first_name().into()); + self.text1 = Some(contact.get_display_name().into()); } else { self.text1 = None; }