api(jsonrpc): Add set_draft_vcard(.., msg_id, contacts)

Add a function setting a vCard containing the given contacts to the message draft. This should
simplify sending contacts as vCards for apps.
This commit is contained in:
iequidoo
2024-06-06 12:02:53 -03:00
committed by iequidoo
parent 0a0e7156e0
commit 889b947792
3 changed files with 61 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ use crate::chat::{
};
use crate::chatlist::Chatlist;
use crate::constants::{DC_GCL_FOR_FORWARDING, DC_GCL_NO_SPECIALS};
use crate::contact;
use crate::download::MIN_DOWNLOAD_LIMIT;
use crate::imap::prefetch_should_download;
use crate::imex::{imex, ImexMode};
@@ -4697,6 +4698,39 @@ async fn test_receive_vcard() -> Result<()> {
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_make_n_send_vcard() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let vcard = "BEGIN:VCARD\n\
VERSION:4.0\n\
FN:Claire\n\
EMAIL;TYPE=work:claire@example.org\n\
END:VCARD";
let contact_ids = contact::import_vcard(alice, vcard).await?;
assert_eq!(contact_ids.len(), 1);
let mut msg = Message::new(Viewtype::File);
msg.make_vcard(alice, &contact_ids).await?;
let alice_bob_chat = alice.create_chat(bob).await;
let sent = alice.send_msg(alice_bob_chat.id, &mut msg).await;
let rcvd = bob.recv_msg(&sent).await;
let sent = Message::load_from_db(alice, sent.sender_msg_id).await?;
assert_eq!(sent.viewtype, Viewtype::Vcard);
assert_eq!(rcvd.viewtype, Viewtype::Vcard);
let vcard = tokio::fs::read(rcvd.get_file(bob).unwrap()).await?;
let vcard = std::str::from_utf8(&vcard)?;
let parsed = deltachat_contact_tools::parse_vcard(vcard);
assert_eq!(parsed.len(), 1);
assert_eq!(&parsed[0].addr, "claire@example.org");
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_group_no_recipients() -> Result<()> {
let t = &TestContext::new_alice().await;