Skip to content

Commit 4ee646c

Browse files
Septiaslink2xt
andauthored
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 <link2xt@testrun.org>
1 parent 1f7b4a7 commit 4ee646c

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

deltachat-ffi/deltachat.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5072,6 +5072,15 @@ int dc_contact_is_blocked (const dc_contact_t* contact);
50725072
*/
50735073
int dc_contact_is_verified (dc_contact_t* contact);
50745074

5075+
/**
5076+
* Returns whether contact is a bot.
5077+
*
5078+
* @memberof dc_contact_t
5079+
* @param contact The contact object.
5080+
* @return 0 if the contact is not a bot, 1 otherwise.
5081+
*/
5082+
int dc_contact_is_bot (dc_contact_t* contact);
5083+
50755084

50765085
/**
50775086
* Return the contact ID that verified a contact.

deltachat-ffi/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4132,6 +4132,15 @@ pub unsafe extern "C" fn dc_contact_is_verified(contact: *mut dc_contact_t) -> l
41324132
}
41334133
}
41344134

4135+
#[no_mangle]
4136+
pub unsafe extern "C" fn dc_contact_is_bot(contact: *mut dc_contact_t) -> libc::c_int {
4137+
if contact.is_null() {
4138+
eprintln!("ignoring careless call to dc_contact_is_bot()");
4139+
return 0;
4140+
}
4141+
(*contact).contact.is_bot() as libc::c_int
4142+
}
4143+
41354144
#[no_mangle]
41364145
pub unsafe extern "C" fn dc_contact_get_verifier_id(contact: *mut dc_contact_t) -> u32 {
41374146
if contact.is_null() {

deltachat-jsonrpc/src/api/types/contact.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ pub struct ContactObject {
4545
/// the contact's last seen timestamp
4646
last_seen: i64,
4747
was_seen_recently: bool,
48+
49+
/// If the contact is a bot.
50+
is_bot: bool,
4851
}
4952

5053
impl ContactObject {
@@ -80,6 +83,7 @@ impl ContactObject {
8083
verifier_id,
8184
last_seen: contact.last_seen(),
8285
was_seen_recently: contact.was_seen_recently(),
86+
is_bot: contact.is_bot(),
8387
})
8488
}
8589
}

0 commit comments

Comments
 (0)