streamline dc_add_device_msg_once|unlabelled() to one function

This commit is contained in:
B. Petersen
2019-11-19 11:49:02 +01:00
parent 1534a07ded
commit d3fa289f27
5 changed files with 30 additions and 73 deletions

View File

@@ -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)