diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index e756866a1..46ebb47b8 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -263,6 +263,17 @@ class Account(object): """ return Contact(self, contact_id) + def get_blocked_contacts(self): + """ return a list of all blocked contacts. + + :returns: list of :class:`deltachat.contact.Contact` objects. + """ + dc_array = ffi.gc( + lib.dc_get_blocked_contacts(self._dc_context), + lib.dc_array_unref + ) + return list(iter_array(dc_array, lambda x: Contact(self, x))) + def get_contacts(self, query=None, with_self=False, only_verified=False): """ get a (filtered) list of contacts. diff --git a/python/src/deltachat/contact.py b/python/src/deltachat/contact.py index 5571bcf13..04a7b8610 100644 --- a/python/src/deltachat/contact.py +++ b/python/src/deltachat/contact.py @@ -52,9 +52,17 @@ class Contact(object): return lib.dc_contact_is_blocked(self._dc_contact) def set_blocked(self, block=True): - """ Block or unblock a contact. """ + """ [Deprecated, use block/unblock methods] Block or unblock a contact. """ return lib.dc_block_contact(self.account._dc_context, self.id, block) + def block(self): + """ Block this contact. Message will not be seen/retrieved from this contact. """ + return lib.dc_block_contact(self.account._dc_context, self.id, True) + + def unblock(self): + """ Unblock this contact. Messages from this contact will be retrieved (again).""" + return lib.dc_block_contact(self.account._dc_context, self.id, False) + def is_verified(self): """ Return True if the contact is verified. """ return lib.dc_contact_is_verified(self._dc_contact) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index f14bbe032..3a8cc3c41 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -129,6 +129,20 @@ class TestOfflineContact: assert not contact1.is_blocked() assert not contact1.is_verified() + def test_get_blocked(self, acfactory): + ac1 = acfactory.get_configured_offline_account() + contact1 = ac1.create_contact("some1@example.org", name="some1") + contact2 = ac1.create_contact("some2@example.org", name="some2") + ac1.create_contact("some3@example.org", name="some3") + assert ac1.get_blocked_contacts() == [] + contact1.block() + assert ac1.get_blocked_contacts() == [contact1] + contact2.block() + blocked = ac1.get_blocked_contacts() + assert len(blocked) == 2 and contact1 in blocked and contact2 in blocked + contact2.unblock() + assert ac1.get_blocked_contacts() == [contact1] + def test_create_self_contact(self, acfactory): ac1 = acfactory.get_configured_offline_account() contact1 = ac1.create_contact(ac1.get_config("addr"))