Fix get_draft to just return null and not produce errors if there's no

draft
This commit is contained in:
jikstra
2019-09-13 18:19:52 +02:00
parent aefddf7f5e
commit 75b7de712a
2 changed files with 18 additions and 13 deletions

View File

@@ -552,15 +552,13 @@ pub unsafe extern "C" fn dc_get_draft(context: *mut dc_context_t, chat_id: u32)
return ptr::null_mut(); // NULL explicitly defined as "no draft"
}
let context = &*context;
let message = match chat::get_draft(context, chat_id) {
Ok(msg) => msg,
Err(e) => {
error!(context, "Failed to get draft for chat #{}: {}", chat_id, e);
return ptr::null_mut();
}
if let Some(message) = chat::get_draft(context, chat_id) {
let ffi_msg = MessageWrapper { context, message };
return Box::into_raw(Box::new(ffi_msg));
};
let ffi_msg = MessageWrapper { context, message };
Box::into_raw(Box::new(ffi_msg))
ptr::null_mut()
}
#[no_mangle]

View File

@@ -921,12 +921,19 @@ fn get_draft_msg_id(context: &Context, chat_id: u32) -> u32 {
.unwrap_or_default() as u32
}
pub unsafe fn get_draft(context: &Context, chat_id: u32) -> Result<Message, Error> {
ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat ID");
let draft_msg_id = get_draft_msg_id(context, chat_id);
ensure!(draft_msg_id != 0, "Invalid draft message ID");
pub unsafe fn get_draft(context: &Context, chat_id: u32) -> Option<Message> {
println!("chat_id {}", chat_id);
if chat_id < DC_CHAT_ID_LAST_SPECIAL {
warn!(context, "Invalid chat ID");
return None;
}
dc_msg_load_from_db(context, draft_msg_id)
let draft_msg_id = get_draft_msg_id(context, chat_id);
if draft_msg_id == 0 {
return None;
}
Some(dc_msg_load_from_db(context, draft_msg_id).unwrap())
}
pub fn get_chat_msgs(context: &Context, chat_id: u32, flags: u32, marker1before: u32) -> Vec<u32> {