From 6e1b54fbd55f915f8f93ed87c3eeefdc991f444f Mon Sep 17 00:00:00 2001 From: link2xt Date: Wed, 5 Mar 2025 19:24:44 +0000 Subject: [PATCH] api(jsonrpc): add API to make and import vCards --- .../src/deltachat_rpc_client/account.py | 14 ++++++++++++-- .../src/deltachat_rpc_client/contact.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/account.py b/deltachat-rpc-client/src/deltachat_rpc_client/account.py index 9d0dd965a2..044d47b079 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/account.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/account.py @@ -118,9 +118,19 @@ def create_contact(self, obj: Union[int, str, Contact], name: Optional[str] = No obj = obj.get_snapshot().address return Contact(self, self._rpc.create_contact(self.id, obj, name)) + def make_vcard(self, contacts: list[Contact]) -> str: + """Create vCard with the given contacts.""" + assert all(contact.account == self for contact in contacts) + contact_ids = [contact.id for contact in contacts] + return self._rpc.make_vcard(self.id, contact_ids) + + def import_vcard(self, vcard: str) -> list[Contact]: + contact_ids = self._rpc.import_vcard_contents(self.id, vcard) + return [Contact(self, contact_id) for contact_id in contact_ids] + def create_chat(self, account: "Account") -> Chat: - addr = account.get_config("addr") - contact = self.create_contact(addr) + vcard = account.self_contact.make_vcard() + [contact] = self.import_vcard(vcard) return contact.create_chat() def get_contact_by_id(self, contact_id: int) -> Contact: diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/contact.py b/deltachat-rpc-client/src/deltachat_rpc_client/contact.py index 81c4bba59d..a03d6ea2dc 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/contact.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/contact.py @@ -66,4 +66,4 @@ def create_chat(self) -> "Chat": ) def make_vcard(self) -> str: - return self._rpc.make_vcard(self.account.id, [self.id]) + return self.account.make_vcard([self])