mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 01:46:34 +03:00
add dc_add_device_msg_once() to fii
This commit is contained in:
committed by
holger krekel
parent
a42e197634
commit
b42d8799b4
@@ -1113,6 +1113,28 @@ void dc_set_draft (dc_context_t* context, uint32_t ch
|
||||
uint32_t dc_add_device_msg (dc_context_t* context, dc_msg_t* msg);
|
||||
|
||||
|
||||
/**
|
||||
* Add a message only one time to the device-chat.
|
||||
* The device-message is defined by a name.
|
||||
* If a message with the same name was added before,
|
||||
* the message is not added again.
|
||||
* Use dc_add_device_msg() to add device-messages unconditionally.
|
||||
*
|
||||
* Sends the event #DC_EVENT_MSGS_CHANGED on success.
|
||||
*
|
||||
* @memberof dc_context_t
|
||||
* @param context The context as created by dc_context_new().
|
||||
* @param label A unique name for the message to add.
|
||||
* The label is typically not displayed to the user and
|
||||
* must be created from the characters `A-Z`, `a-z`, `0-9`, `_` or `-`.
|
||||
* @param msg Message to be added to the device-chat.
|
||||
* The message appears to the user as an incoming message.
|
||||
* @return The ID of the added message,
|
||||
* this might be the id of an older message with the same name.
|
||||
*/
|
||||
uint32_t dc_add_device_msg_once (dc_context_t* context, const char* label, dc_msg_t* msg);
|
||||
|
||||
|
||||
/**
|
||||
* Get draft for a chat, if any.
|
||||
* See dc_set_draft() for more details about drafts.
|
||||
|
||||
@@ -828,6 +828,27 @@ pub unsafe extern "C" fn dc_add_device_msg(context: *mut dc_context_t, msg: *mut
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_add_device_msg_once(
|
||||
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()");
|
||||
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")
|
||||
})
|
||||
.map(|msg_id| msg_id.to_u32())
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_draft(context: *mut dc_context_t, chat_id: u32) -> *mut dc_msg_t {
|
||||
if context.is_null() {
|
||||
|
||||
Reference in New Issue
Block a user