From a655f2cbba1e352701e3ff0f9f907d682367861d Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Wed, 14 Aug 2019 13:55:56 +0200 Subject: [PATCH] fix: properly handle chat name when contact has no name * fix chat name empty when contact has no name Show contacts display_name instead as defined in: https://c.delta.chat/classdc__chat__t.html#a0fb1b4850bcd899eaa06d23648a1efaf "For one-to-one chats, this is the name of the contact" --- src/dc_chat.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/dc_chat.rs b/src/dc_chat.rs index ba879ed03..999ced1c2 100644 --- a/src/dc_chat.rs +++ b/src/dc_chat.rs @@ -180,6 +180,22 @@ pub fn dc_chat_load_from_db(chat: *mut Chat, chat_id: u32) -> bool { .strdup(); }, _ => { + unsafe { + if (*chat).type_0 == DC_CHAT_TYPE_SINGLE { + free((*chat).name as *mut libc::c_void); + let contacts = dc_get_chat_contacts((*chat).context, (*chat).id); + let mut chat_name = "Err [Name not found]".to_owned(); + if !(*contacts).is_empty() { + if let Ok(contact) = + Contact::get_by_id((*chat).context, contacts[0]) + { + chat_name = contact.get_display_name().to_owned(); + } + } + (*chat).name = (&chat_name).strdup(); + } + } + if unsafe { &(*chat).param }.exists(Param::Selftalk) { unsafe { free((*chat).name as *mut libc::c_void);