address @hocuri comment -- remove as_contact() as it's synonym with create_contact

and the latter is already an established API and conveys better that a contact
object will be created if it doesn't exist.
This commit is contained in:
holger krekel
2020-06-09 13:14:22 +02:00
parent 0bb4ef0bd9
commit 0c8f951d8f
4 changed files with 19 additions and 22 deletions

View File

@@ -213,21 +213,18 @@ class Account(object):
"""
return Contact(self, const.DC_CONTACT_ID_SELF)
def create_contact(self, addr, name=None):
""" create a (new) Contact. If there already is a Contact
with that e-mail address, it is unblocked and its display
name is updated.
def create_contact(self, obj, name=None):
""" create a (new) Contact or return an existing one.
:param addr: email-address, Account or Contact instance.
:param name: display name for this contact (optional)
Calling this method will always resulut in the same
underlying contact id. If there already is a Contact
with that e-mail address, it is unblocked and its display
`name` is updated if specified.
:param obj: email-address, Account or Contact instance.
:param name: (optional) display name for this contact
:returns: :class:`deltachat.contact.Contact` instance.
"""
if not isinstance(addr, (Account, Contact, str)):
raise TypeError(str(addr))
return self.as_contact(addr, name=name)
def as_contact(self, obj, name=None):
""" Create a contact from an Account, Contact or e-mail address. """
if isinstance(obj, Account):
if not obj.is_configured():
raise ValueError("can only add addresses from configured accounts")
@@ -309,7 +306,7 @@ class Account(object):
def create_chat(self, obj):
""" Create a 1:1 chat with Account, Contact or e-mail address. """
return self.as_contact(obj).create_chat()
return self.create_contact(obj).create_chat()
def _create_chat_by_message_id(self, msg_id):
return Chat(self, lib.dc_create_chat_by_msg_id(self._dc_context, msg_id))

View File

@@ -337,7 +337,7 @@ class Chat(object):
:raises ValueError: if contact could not be added
:returns: None
"""
contact = self.account.as_contact(obj)
contact = self.account.create_contact(obj)
ret = lib.dc_add_contact_to_chat(self.account._dc_context, self.id, contact.id)
if ret != 1:
raise ValueError("could not add contact {!r} to chat".format(contact))
@@ -350,7 +350,7 @@ class Chat(object):
:raises ValueError: if contact could not be removed
:returns: None
"""
contact = self.account.as_contact(obj)
contact = self.account.create_contact(obj)
ret = lib.dc_remove_contact_from_chat(self.account._dc_context, self.id, contact.id)
if ret != 1:
raise ValueError("could not remove contact {!r} from chat".format(contact))