Skip to content

Commit

Permalink
api(jsonrpc): add API to make and import vCards
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Mar 5, 2025
1 parent 2ef7efb commit 6e1b54f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions deltachat-rpc-client/src/deltachat_rpc_client/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion deltachat-rpc-client/src/deltachat_rpc_client/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

0 comments on commit 6e1b54f

Please sign in to comment.