mirror of
https://github.com/chatmail/core.git
synced 2026-05-01 20:36:31 +03:00
Fix get_draft to just return null and not produce errors if there's no
draft
This commit is contained in:
@@ -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"
|
return ptr::null_mut(); // NULL explicitly defined as "no draft"
|
||||||
}
|
}
|
||||||
let context = &*context;
|
let context = &*context;
|
||||||
let message = match chat::get_draft(context, chat_id) {
|
|
||||||
Ok(msg) => msg,
|
if let Some(message) = chat::get_draft(context, chat_id) {
|
||||||
Err(e) => {
|
let ffi_msg = MessageWrapper { context, message };
|
||||||
error!(context, "Failed to get draft for chat #{}: {}", chat_id, e);
|
return Box::into_raw(Box::new(ffi_msg));
|
||||||
return ptr::null_mut();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let ffi_msg = MessageWrapper { context, message };
|
|
||||||
Box::into_raw(Box::new(ffi_msg))
|
ptr::null_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
17
src/chat.rs
17
src/chat.rs
@@ -921,12 +921,19 @@ fn get_draft_msg_id(context: &Context, chat_id: u32) -> u32 {
|
|||||||
.unwrap_or_default() as u32
|
.unwrap_or_default() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn get_draft(context: &Context, chat_id: u32) -> Result<Message, Error> {
|
pub unsafe fn get_draft(context: &Context, chat_id: u32) -> Option<Message> {
|
||||||
ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat ID");
|
println!("chat_id {}", chat_id);
|
||||||
let draft_msg_id = get_draft_msg_id(context, chat_id);
|
if chat_id < DC_CHAT_ID_LAST_SPECIAL {
|
||||||
ensure!(draft_msg_id != 0, "Invalid draft message ID");
|
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> {
|
pub fn get_chat_msgs(context: &Context, chat_id: u32, flags: u32, marker1before: u32) -> Vec<u32> {
|
||||||
|
|||||||
Reference in New Issue
Block a user