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"
This commit is contained in:
Simon Laux
2019-08-14 13:55:56 +02:00
committed by Friedel Ziegelmayer
parent 0cb42f840d
commit a655f2cbba

View File

@@ -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);