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

@@ -16,7 +16,7 @@ use crate::config::Config;
use crate::constants::{
Blocked, Chattype, VideochatType, DC_CHAT_ID_TRASH, DC_DESIRED_TEXT_LEN, DC_MSG_ID_LAST_SPECIAL,
};
use crate::contact::{Contact, ContactId};
use crate::contact::{self, Contact, ContactId};
use crate::context::Context;
use crate::debug_logging::set_debug_logging_xdc;
use crate::download::DownloadState;
@@ -1081,6 +1081,18 @@ impl Message {
Ok(())
}
/// Makes message a vCard-containing message using the specified contacts.
pub async fn make_vcard(&mut self, context: &Context, contacts: &[ContactId]) -> Result<()> {
ensure!(
matches!(self.viewtype, Viewtype::File | Viewtype::Vcard),
"Wrong viewtype for vCard: {}",
self.viewtype,
);
let vcard = contact::make_vcard(context, contacts).await?;
self.set_file_from_bytes(context, "vcard.vcf", vcard.as_bytes(), None)
.await
}
/// Set different sender name for a message.
/// This overrides the name set by the `set_config()`-option `displayname`.
pub fn set_override_sender_name(&mut self, name: Option<String>) {