add dc_skip_device_msg() and belonging tests

This commit is contained in:
B. Petersen
2019-11-18 16:01:15 +01:00
parent fed6f4ab8a
commit 035da9e5d7
4 changed files with 98 additions and 5 deletions

View File

@@ -1135,6 +1135,44 @@ uint32_t dc_add_device_msg (dc_context_t* context, dc_msg_t* m
uint32_t dc_add_device_msg_once (dc_context_t* context, const char* label, dc_msg_t* msg);
/**
* Skip a device-message permanently.
* Subsequent calls to dc_add_device_msg_once() with the same label
* won't add the device-message then.
* This might be handy if you want to add
* eg. different messages for first-install and updates.
*
* @memberof dc_context_t
* @param context The context as created by dc_context_new().
* @param label A unique name for the message to skip.
* The label is typically not displayed to the user and
* must be created from the characters `A-Z`, `a-z`, `0-9`, `_` or `-`.
* If a message with that label already exist,
* nothing happens.
* @return None.
*
* Example:
* ~~~
* dc_msg_t* welcome_msg = dc_msg_new(DC_MSG_TEXT);
* dc_msg_set_text(welcome_msg, "great that you give this app a try!");
*
* dc_msg_t* changelog_msg = dc_msg_new(DC_MSG_TEXT);
* dc_msg_set_text(changelog_msg, "we have added 3 new emojis :)");
*
* if (dc_add_device_msg_once(context, "welcome", welcome_msg)) {
* // do not add the changelog on a new installations -
* // not now and not when this code is executed again
* dc_skip_device_msg(context, "update-123");
* } else {
* // welcome message was not added now, this is an oder installation,
* // add a changelog
* dc_add_device_msg_once(context, "update-123", changelog_msg);
* }
* ~~~
*/
void dc_skip_device_msg (dc_context_t* context, const char* label);
/**
* Get draft for a chat, if any.
* See dc_set_draft() for more details about drafts.

View File

@@ -849,6 +849,24 @@ pub unsafe extern "C" fn dc_add_device_msg_once(
.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_get_draft(context: *mut dc_context_t, chat_id: u32) -> *mut dc_msg_t {
if context.is_null() {