use dc_add_device_msg() also to add labels-only, this is clearer as having a function with 'skip' in the name

This commit is contained in:
B. Petersen
2019-11-19 13:05:01 +01:00
parent 2a4c193601
commit 700e10bc0e
5 changed files with 65 additions and 103 deletions

View File

@@ -817,18 +817,23 @@ pub unsafe extern "C" fn dc_add_device_msg(
label: *const libc::c_char,
msg: *mut dc_msg_t,
) -> u32 {
if context.is_null() || label.is_null() || msg.is_null() {
if context.is_null() || (label.is_null() && msg.is_null()) {
eprintln!("ignoring careless call to dc_add_device_msg()");
return 0;
}
let ffi_context = &mut *context;
let ffi_msg = &mut *msg;
let msg = if msg.is_null() {
None
} else {
let ffi_msg: &mut MessageWrapper = &mut *msg;
Some(&mut ffi_msg.message)
};
ffi_context
.with_inner(|ctx| {
chat::add_device_msg(
ctx,
to_opt_string_lossy(label).as_ref().map(|x| x.as_str()),
&mut ffi_msg.message,
msg,
)
.unwrap_or_log_default(ctx, "Failed to add device message")
})
@@ -836,24 +841,6 @@ pub unsafe extern "C" fn dc_add_device_msg(
.unwrap_or(0)
}
#[no_mangle]
pub unsafe extern "C" fn dc_skip_device_msg(
context: *mut dc_context_t,
label: *const libc::c_char,
) {
if context.is_null() || label.is_null() {
eprintln!("ignoring careless call to dc_skip_device_msg()");
return;
}
let ffi_context = &mut *context;
ffi_context
.with_inner(|ctx| {
chat::skip_device_msg(ctx, &to_string_lossy(label))
.unwrap_or_log_default(ctx, "Failed to skip device message")
})
.unwrap_or(())
}
#[no_mangle]
pub unsafe extern "C" fn dc_has_device_msg(
context: *mut dc_context_t,