mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
streamline dc_add_device_msg_once|unlabelled() to one function
This commit is contained in:
@@ -812,41 +812,25 @@ pub unsafe extern "C" fn dc_set_draft(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_add_device_msg_unlabelled(
|
||||
context: *mut dc_context_t,
|
||||
msg: *mut dc_msg_t,
|
||||
) -> u32 {
|
||||
if context.is_null() || msg.is_null() {
|
||||
eprintln!("ignoring careless call to dc_add_device_msg_unlabelled()");
|
||||
return 0;
|
||||
}
|
||||
let ffi_context = &mut *context;
|
||||
let ffi_msg = &mut *msg;
|
||||
ffi_context
|
||||
.with_inner(|ctx| {
|
||||
chat::add_device_msg_unlabelled(ctx, &mut ffi_msg.message)
|
||||
.unwrap_or_log_default(ctx, "Failed to add device message")
|
||||
})
|
||||
.map(|msg_id| msg_id.to_u32())
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_add_device_msg_once(
|
||||
pub unsafe extern "C" fn dc_add_device_msg(
|
||||
context: *mut dc_context_t,
|
||||
label: *const libc::c_char,
|
||||
msg: *mut dc_msg_t,
|
||||
) -> u32 {
|
||||
if context.is_null() || label.is_null() || msg.is_null() {
|
||||
eprintln!("ignoring careless call to dc_add_device_msg_once()");
|
||||
eprintln!("ignoring careless call to dc_add_device_msg()");
|
||||
return 0;
|
||||
}
|
||||
let ffi_context = &mut *context;
|
||||
let ffi_msg = &mut *msg;
|
||||
ffi_context
|
||||
.with_inner(|ctx| {
|
||||
chat::add_device_msg_once(ctx, &to_string_lossy(label), &mut ffi_msg.message)
|
||||
.unwrap_or_log_default(ctx, "Failed to add device message once")
|
||||
chat::add_device_msg(
|
||||
ctx,
|
||||
to_opt_string_lossy(label).as_ref().map(|x| x.as_str()),
|
||||
&mut ffi_msg.message,
|
||||
)
|
||||
.unwrap_or_log_default(ctx, "Failed to add device message")
|
||||
})
|
||||
.map(|msg_id| msg_id.to_u32())
|
||||
.unwrap_or(0)
|
||||
|
||||
Reference in New Issue
Block a user