From d4c4070b3fac6162883da3c37f629e0df147d5af Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Thu, 2 Jan 2020 01:37:21 +0100 Subject: [PATCH] Add C interface for autodelete timer settings --- deltachat-ffi/deltachat.h | 22 ++++++++++++++++++++++ deltachat-ffi/src/lib.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 8c443a943..648ed2a26 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -1481,6 +1481,16 @@ void dc_delete_chat (dc_context_t* context, uint32_t ch */ dc_array_t* dc_get_chat_contacts (dc_context_t* context, uint32_t chat_id); +/** + * Get the chat's autodelete message timer. + * + * @memberof dc_context_t + * @param context The context as created by dc_context_new(). + * @param chat_id The chat ID. + * + * @return autodelete timer value in seconds or 0 if the timer is disabled. + */ +uint32_t dc_get_chat_autodelete_timer (dc_context_t* context, uint32_t chat_id); /** * Search messages containing the given query string. @@ -1613,6 +1623,17 @@ int dc_remove_contact_from_chat (dc_context_t* context, uint32_t ch */ int dc_set_chat_name (dc_context_t* context, uint32_t chat_id, const char* name); +/** + * Set the chat's autodelete message timer. + * + * @memberof dc_context_t + * @param context The context as created by dc_context_new(). + * @param chat_id The chat ID to set the autodelete message timer for. + * @param timer The timer value in seconds or 0 to disable the timer. + * + * @return 1=success, 0=error + */ +int dc_set_chat_autodelete_timer (dc_context_t* context, uint32_t chat_id, uint32_t timer); /** * Set group profile image. @@ -2861,6 +2882,7 @@ char* dc_chat_get_name (const dc_chat_t* chat); char* dc_chat_get_profile_image (const dc_chat_t* chat); + /** * Get a color for the chat. * For 1:1 chats, the color is calculated from the contact's email address. diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 1e75bd359..d3cd481e9 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -1451,6 +1451,41 @@ pub unsafe extern "C" fn dc_set_chat_mute_duration( .unwrap_or(0) } +#[no_mangle] +pub unsafe extern "C" fn dc_get_chat_autodelete_timer( + context: *mut dc_context_t, + chat_id: u32, +) -> u32 { + if context.is_null() || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 { + eprintln!("ignoring careless call to dc_set_chat_autodelete_timer()"); + return 0; + } + let ffi_context = &*context; + ffi_context + .with_inner(|ctx| chat::get_autodelete_timer(ctx, ChatId::new(chat_id))) + .unwrap_or_default() +} + +#[no_mangle] +pub unsafe extern "C" fn dc_set_chat_autodelete_timer( + context: *mut dc_context_t, + chat_id: u32, + timer: u32, +) -> libc::c_int { + if context.is_null() || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 { + eprintln!("ignoring careless call to dc_set_chat_autodelete_timer()"); + return 0; + } + let ffi_context = &*context; + ffi_context + .with_inner(|ctx| { + chat::set_autodelete_timer(ctx, ChatId::new(chat_id), timer) + .map(|_| 1) + .unwrap_or_log_default(ctx, "Failed to set autodelete timer") + }) + .unwrap_or(0) +} + #[no_mangle] pub unsafe extern "C" fn dc_get_msg_info( context: *mut dc_context_t,