mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 14:26:30 +03:00
Return a Result<Option<Message>> for get_draft
The function can fail, so we need to still have an error return as well as a no-draft return. Add tests.
This commit is contained in:
@@ -553,12 +553,23 @@ pub unsafe extern "C" fn dc_get_draft(context: *mut dc_context_t, chat_id: u32)
|
||||
}
|
||||
let context = &*context;
|
||||
|
||||
if let Some(message) = chat::get_draft(context, chat_id) {
|
||||
let ffi_msg = MessageWrapper { context, message };
|
||||
return Box::into_raw(Box::new(ffi_msg));
|
||||
};
|
||||
|
||||
ptr::null_mut()
|
||||
match chat::get_draft(context, chat_id) {
|
||||
Ok(Some(draft)) => {
|
||||
let ffi_msg = MessageWrapper {
|
||||
context,
|
||||
message: draft,
|
||||
};
|
||||
Box::into_raw(Box::new(ffi_msg))
|
||||
}
|
||||
Ok(None) => ptr::null_mut(),
|
||||
Err(err) => {
|
||||
error!(
|
||||
context,
|
||||
"Failed to get draft for chat #{}: {}", chat_id, err
|
||||
);
|
||||
ptr::null_mut()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
Reference in New Issue
Block a user