Skip to content

Commit e4e738e

Browse files
committed
api(deltachat-rpc-client): accept Account as Account.create_contact() argument
1 parent 8a5a67d commit e4e738e

File tree

1 file changed

+10
-5
lines changed
  • deltachat-rpc-client/src/deltachat_rpc_client

1 file changed

+10
-5
lines changed

deltachat-rpc-client/src/deltachat_rpc_client/account.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,23 @@ def bring_online(self):
115115
self.start_io()
116116
self.wait_for_event(EventType.IMAP_INBOX_IDLE)
117117

118-
def create_contact(self, obj: Union[int, str, Contact], name: Optional[str] = None) -> Contact:
118+
def create_contact(self, obj: Union[int, str, Contact, "Account"], name: Optional[str] = None) -> Contact:
119119
"""Create a new Contact or return an existing one.
120120
121121
Calling this method will always result in the same
122122
underlying contact id. If there already is a Contact
123123
with that e-mail address, it is unblocked and its display
124124
name is updated if specified.
125125
126-
:param obj: email-address or contact id.
126+
:param obj: email-address, contact id or account.
127127
:param name: (optional) display name for this contact.
128128
"""
129+
if isinstance(obj, Account):
130+
vcard = obj.self_contact.make_vcard()
131+
[contact] = self.import_vcard(vcard)
132+
if name:
133+
contact.set_name(name)
134+
return contact
129135
if isinstance(obj, int):
130136
obj = Contact(self, obj)
131137
if isinstance(obj, Contact):
@@ -146,9 +152,8 @@ def import_vcard(self, vcard: str) -> list[Contact]:
146152
return [Contact(self, contact_id) for contact_id in contact_ids]
147153

148154
def create_chat(self, account: "Account") -> Chat:
149-
vcard = account.self_contact.make_vcard()
150-
[contact] = self.import_vcard(vcard)
151-
return contact.create_chat()
155+
"""Create a 1:1 chat with another account."""
156+
return self.create_contact(account).create_chat()
152157

153158
def get_device_chat(self) -> Chat:
154159
"""Return device chat."""

0 commit comments

Comments
 (0)