From 4ee646ce0bbc3e4002d260930b912cbb2630063d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kl=C3=A4hn?= <39526136+Septias@users.noreply.github.com> Date: Sat, 20 Jan 2024 16:00:10 +0100 Subject: [PATCH] feat(api): Add `is_bot` to cffi and jsonrpc (#5197) @adbenitez wants this feature on Deltalab to display a bot tag. Other UIs might also want to adopt this feature :) --------- Co-authored-by: link2xt --- deltachat-ffi/deltachat.h | 9 +++++++++ deltachat-ffi/src/lib.rs | 9 +++++++++ deltachat-jsonrpc/src/api/types/contact.rs | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index b4e482202..97fe035c3 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -5072,6 +5072,15 @@ int dc_contact_is_blocked (const dc_contact_t* contact); */ int dc_contact_is_verified (dc_contact_t* contact); +/** + * Returns whether contact is a bot. + * + * @memberof dc_contact_t + * @param contact The contact object. + * @return 0 if the contact is not a bot, 1 otherwise. + */ +int dc_contact_is_bot (dc_contact_t* contact); + /** * Return the contact ID that verified a contact. diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index ac0fc05fa..5d68a940d 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -4132,6 +4132,15 @@ pub unsafe extern "C" fn dc_contact_is_verified(contact: *mut dc_contact_t) -> l } } +#[no_mangle] +pub unsafe extern "C" fn dc_contact_is_bot(contact: *mut dc_contact_t) -> libc::c_int { + if contact.is_null() { + eprintln!("ignoring careless call to dc_contact_is_bot()"); + return 0; + } + (*contact).contact.is_bot() as libc::c_int +} + #[no_mangle] pub unsafe extern "C" fn dc_contact_get_verifier_id(contact: *mut dc_contact_t) -> u32 { if contact.is_null() { diff --git a/deltachat-jsonrpc/src/api/types/contact.rs b/deltachat-jsonrpc/src/api/types/contact.rs index 60acd6b19..f6d9096bd 100644 --- a/deltachat-jsonrpc/src/api/types/contact.rs +++ b/deltachat-jsonrpc/src/api/types/contact.rs @@ -45,6 +45,9 @@ pub struct ContactObject { /// the contact's last seen timestamp last_seen: i64, was_seen_recently: bool, + + /// If the contact is a bot. + is_bot: bool, } impl ContactObject { @@ -80,6 +83,7 @@ impl ContactObject { verifier_id, last_seen: contact.last_seen(), was_seen_recently: contact.was_seen_recently(), + is_bot: contact.is_bot(), }) } }