@@ -115,17 +115,23 @@ def bring_online(self):
115
115
self .start_io ()
116
116
self .wait_for_event (EventType .IMAP_INBOX_IDLE )
117
117
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 :
119
119
"""Create a new Contact or return an existing one.
120
120
121
121
Calling this method will always result in the same
122
122
underlying contact id. If there already is a Contact
123
123
with that e-mail address, it is unblocked and its display
124
124
name is updated if specified.
125
125
126
- :param obj: email-address or contact id.
126
+ :param obj: email-address, contact id or account .
127
127
:param name: (optional) display name for this contact.
128
128
"""
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
129
135
if isinstance (obj , int ):
130
136
obj = Contact (self , obj )
131
137
if isinstance (obj , Contact ):
@@ -146,9 +152,8 @@ def import_vcard(self, vcard: str) -> list[Contact]:
146
152
return [Contact (self , contact_id ) for contact_id in contact_ids ]
147
153
148
154
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 ()
152
157
153
158
def get_device_chat (self ) -> Chat :
154
159
"""Return device chat."""
0 commit comments