diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 2c7a26699..c1b711670 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -3477,6 +3477,32 @@ int dc_msg_is_forwarded (const dc_msg_t* msg); int dc_msg_is_info (const dc_msg_t* msg); +/** + * Get the type of an informational message. + * If dc_msg_is_info() returns 1, this function returns the type of the informational message. + * UIs can display eg. an icon based upon the type. + * + * Currently, the following types are defined: + * - DC_INFO_PROTECTION_ENABLED (11) - Info-message for "Chat is now protected" + * - DC_INFO_PROTECTION_DISABLED (12) - Info-message for "Chat is no longer protected" + * + * Even when you display an icon, + * you should still display the text of the informational message using dc_msg_get_text() + * + * @memberof dc_msg_t + * @param msg The message object. + * @return One of the DC_INFO* constants. + * 0 or other values indicate unspecified types + * or that the message is not an info-message. + */ +int dc_msg_get_info_type (const dc_msg_t* msg); + + +// DC_INFO* uses the same values as SystemMessage in rust-land +#define DC_INFO_PROTECTION_ENABLED 11 +#define DC_INFO_PROTECTION_DISABLED 12 + + /** * Check if a message is still in creation. A message is in creation between * the calls to dc_prepare_msg() and dc_send_msg(). diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 4a3dbdc9d..7b73c0d0b 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -2843,6 +2843,16 @@ pub unsafe extern "C" fn dc_msg_is_info(msg: *mut dc_msg_t) -> libc::c_int { ffi_msg.message.is_info().into() } +#[no_mangle] +pub unsafe extern "C" fn dc_msg_get_info_type(msg: *mut dc_msg_t) -> libc::c_int { + if msg.is_null() { + eprintln!("ignoring careless call to dc_msg_get_info_type()"); + return 0; + } + let ffi_msg = &*msg; + ffi_msg.message.get_info_type() as libc::c_int +} + #[no_mangle] pub unsafe extern "C" fn dc_msg_is_increation(msg: *mut dc_msg_t) -> libc::c_int { if msg.is_null() { diff --git a/src/message.rs b/src/message.rs index 28144eced..577aa193f 100644 --- a/src/message.rs +++ b/src/message.rs @@ -589,6 +589,10 @@ impl Message { || cmd != SystemMessage::Unknown && cmd != SystemMessage::AutocryptSetupMessage } + pub fn get_info_type(&self) -> SystemMessage { + self.param.get_cmd() + } + pub fn is_system_message(&self) -> bool { let cmd = self.param.get_cmd(); cmd != SystemMessage::Unknown