mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Add quote API
Sticky encryption rule, requiring that all replies to encrypted messages are encrypted, applies only to messages with a quote now. Co-Authored-By: B. Petersen <r10s@b44t.com>
This commit is contained in:
committed by
link2xt
parent
8c82a5cbfa
commit
20182b027e
@@ -3675,6 +3675,63 @@ void dc_msg_set_location (dc_msg_t* msg, double latitude, d
|
||||
void dc_msg_latefiling_mediasize (dc_msg_t* msg, int width, int height, int duration);
|
||||
|
||||
|
||||
/**
|
||||
* Set the message replying to.
|
||||
* This allows optionally to reply to an explicit message
|
||||
* instead of replying implicitly to the end of the chat.
|
||||
*
|
||||
* dc_msg_set_quote() copies some basic data from the quoted message object
|
||||
* so that dc_msg_get_quoted_text() will always work.
|
||||
* dc_msg_get_quoted_msg() gets back the quoted message only if it is _not_ deleted.
|
||||
*
|
||||
* @memberof dc_msg_t
|
||||
* @param msg The message object to set the reply to.
|
||||
* @param quote The quote to set for msg.
|
||||
*/
|
||||
void dc_msg_set_quote (dc_msg_t* msg, const dc_msg_t* quote);
|
||||
|
||||
|
||||
/**
|
||||
* Get quoted text, if any.
|
||||
* You can use this function also check if there is a quote for a message.
|
||||
*
|
||||
* The text is a summary of the original text,
|
||||
* similar to what is shown in the chatlist.
|
||||
*
|
||||
* If available, you can get the whole quoted message object using dc_msg_get_quoted_msg().
|
||||
*
|
||||
* @memberof dc_msg_t
|
||||
* @param msg The message object.
|
||||
* @return The quoted text or NULL if there is no quote.
|
||||
* Returned strings must be released using dc_str_unref().
|
||||
*/
|
||||
char* dc_msg_get_quoted_text (const dc_msg_t* msg);
|
||||
|
||||
|
||||
/**
|
||||
* Get quoted message, if available.
|
||||
* UIs might use this information to offer "jumping back" to the quoted message
|
||||
* or to enrich displaying the quote.
|
||||
*
|
||||
* If this function returns NULL,
|
||||
* this does not mean there is no quote for the message -
|
||||
* it might also mean that a quote exist but the quoted message is deleted meanwhile.
|
||||
* Therefore, do not use this function to check if there is a quote for a message.
|
||||
* To check if a message has a quote, use dc_msg_get_quoted_text().
|
||||
*
|
||||
* To display the quote in the chat, use dc_msg_get_quoted_text() as a primary source,
|
||||
* however, one might add information from the message object (eg. an image).
|
||||
*
|
||||
* It is not guaranteed that the message belong to the same chat.
|
||||
*
|
||||
* @memberof dc_msg_t
|
||||
* @param msg The message object.
|
||||
* @return The quoted message or NULL.
|
||||
* Must be freed using dc_msg_unref() after usage.
|
||||
*/
|
||||
dc_msg_t* dc_msg_get_quoted_msg (const dc_msg_t* msg);
|
||||
|
||||
|
||||
/**
|
||||
* @class dc_contact_t
|
||||
*
|
||||
|
||||
@@ -2975,6 +2975,58 @@ pub unsafe extern "C" fn dc_msg_get_error(msg: *mut dc_msg_t) -> *mut libc::c_ch
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_set_quote(msg: *mut dc_msg_t, quote: *const dc_msg_t) {
|
||||
if msg.is_null() {
|
||||
eprintln!("ignoring careless call to dc_msg_set_quote()");
|
||||
return;
|
||||
}
|
||||
let ffi_msg = &mut *msg;
|
||||
let ffi_quote = &*quote;
|
||||
|
||||
ffi_msg
|
||||
.message
|
||||
.set_quote(&ffi_quote.message)
|
||||
.log_err(&*ffi_msg.context, "failed to set quote")
|
||||
.ok();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_quoted_text(msg: *const dc_msg_t) -> *mut libc::c_char {
|
||||
if msg.is_null() {
|
||||
eprintln!("ignoring careless call to dc_msg_get_quoted_text()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
let ffi_msg: &MessageWrapper = &*msg;
|
||||
ffi_msg
|
||||
.message
|
||||
.quoted_text()
|
||||
.map_or_else(ptr::null_mut, |s| s.strdup())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_quoted_msg(msg: *const dc_msg_t) -> *mut dc_msg_t {
|
||||
if msg.is_null() {
|
||||
eprintln!("ignoring careless call to dc_get_quoted_msg()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
let ffi_msg: &MessageWrapper = &*msg;
|
||||
let context = &*ffi_msg.context;
|
||||
let res = block_on(async move {
|
||||
ffi_msg
|
||||
.message
|
||||
.quoted_message(context)
|
||||
.await
|
||||
.log_err(context, "failed to get quoted message")
|
||||
.unwrap_or(None)
|
||||
});
|
||||
|
||||
match res {
|
||||
Some(message) => Box::into_raw(Box::new(MessageWrapper { context, message })),
|
||||
None => ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
// dc_contact_t
|
||||
|
||||
/// FFI struct for [dc_contact_t]
|
||||
|
||||
Reference in New Issue
Block a user