diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 46ebb47b8..a729ac09d 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -214,6 +214,20 @@ class Account(object): :param name: (optional) display name for this contact :returns: :class:`deltachat.contact.Contact` instance. """ + (name, addr) = self.get_contact_addr_and_name(obj, name) + return self._create_contact(addr, name) + + def _create_contact(self, addr, name): + addr = as_dc_charpointer(addr) + name = as_dc_charpointer(name) + contact_id = lib.dc_create_contact(self._dc_context, name, addr) + return Contact(self, contact_id) + + def get_contact(self, obj): + (_, addr) = self.get_contact_addr_and_name(obj) + return self.get_contact_by_addr(addr) + + def get_contact_addr_and_name(self, obj, name=None): if isinstance(obj, Account): if not obj.is_configured(): raise ValueError("can only add addresses from configured accounts") @@ -229,13 +243,7 @@ class Account(object): if name is None and displayname: name = displayname - return self._create_contact(addr, name) - - def _create_contact(self, addr, name): - addr = as_dc_charpointer(addr) - name = as_dc_charpointer(name) - contact_id = lib.dc_create_contact(self._dc_context, name, addr) - return Contact(self, contact_id) + return (name, addr) def delete_contact(self, contact): """ delete a Contact. diff --git a/python/src/deltachat/chat.py b/python/src/deltachat/chat.py index 51100712c..4aa0b2d04 100644 --- a/python/src/deltachat/chat.py +++ b/python/src/deltachat/chat.py @@ -371,7 +371,7 @@ class Chat(object): :raises ValueError: if contact could not be removed :returns: None """ - contact = self.account.create_contact(obj) + contact = self.account.get_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))