refactor(msg): use rust based allocations

This commit is contained in:
dignifiedquire
2019-08-18 21:26:53 +02:00
parent a906faeb35
commit cb6c8ac78b
13 changed files with 982 additions and 1227 deletions

View File

@@ -275,29 +275,36 @@ impl<'a> Chatlist<'a> {
let mut lastcontact = None;
let lastmsg = if 0 != lastmsg_id {
let lastmsg = dc_msg_new_untyped(self.context);
dc_msg_load_from_db(lastmsg, self.context, lastmsg_id);
if let Ok(lastmsg) = dc_msg_load_from_db(self.context, lastmsg_id) {
if lastmsg.from_id != 1 as libc::c_uint
&& (chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup)
{
lastcontact = Contact::load_from_db(self.context, lastmsg.from_id).ok();
}
if (*lastmsg).from_id != 1 as libc::c_uint
&& (chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup)
{
lastcontact = Contact::load_from_db(self.context, (*lastmsg).from_id).ok();
Some(lastmsg)
} else {
None
}
lastmsg
} else {
std::ptr::null_mut()
None
};
if chat.id == DC_CHAT_ID_ARCHIVED_LINK as u32 {
ret.text2 = None;
} else if lastmsg.is_null() || (*lastmsg).from_id == DC_CONTACT_ID_UNDEFINED as u32 {
} else if lastmsg.is_none()
|| lastmsg.as_ref().unwrap().from_id == DC_CONTACT_ID_UNDEFINED as u32
{
ret.text2 = Some(self.context.stock_str(StockMessage::NoMessages).to_string());
} else {
ret.fill(lastmsg, chat, lastcontact.as_ref(), self.context);
ret.fill(
&mut lastmsg.unwrap(),
chat,
lastcontact.as_ref(),
self.context,
);
}
dc_msg_unref(lastmsg);
ret
}
}