Delta-Chat Contact. You obtain instances of it through :class:`deltachat.account.Account`.
| 10 | |
| 11 | |
| 12 | class Contact: |
| 13 | """Delta-Chat Contact. |
| 14 | |
| 15 | You obtain instances of it through :class:`deltachat.account.Account`. |
| 16 | """ |
| 17 | |
| 18 | def __init__(self, account, id) -> None: |
| 19 | from .account import Account |
| 20 | |
| 21 | assert isinstance(account, Account), repr(account) |
| 22 | self.account = account |
| 23 | self.id = id |
| 24 | |
| 25 | def __eq__(self, other) -> bool: |
| 26 | if other is None: |
| 27 | return False |
| 28 | return self.account._dc_context == other.account._dc_context and self.id == other.id |
| 29 | |
| 30 | def __ne__(self, other) -> bool: |
| 31 | return not self == other |
| 32 | |
| 33 | def __repr__(self) -> str: |
| 34 | return f"<Contact id={self.id} addr={self.addr} dc_context={self.account._dc_context}>" |
| 35 | |
| 36 | @property |
| 37 | def _dc_contact(self): |
| 38 | return ffi.gc(lib.dc_get_contact(self.account._dc_context, self.id), lib.dc_contact_unref) |
| 39 | |
| 40 | @props.with_doc |
| 41 | def addr(self) -> str: |
| 42 | """normalized e-mail address for this account.""" |
| 43 | return from_dc_charpointer(lib.dc_contact_get_addr(self._dc_contact)) |
| 44 | |
| 45 | @props.with_doc |
| 46 | def name(self) -> str: |
| 47 | """display name for this contact.""" |
| 48 | return from_dc_charpointer(lib.dc_contact_get_display_name(self._dc_contact)) |
| 49 | |
| 50 | # deprecated alias |
| 51 | display_name = name |
| 52 | |
| 53 | @props.with_doc |
| 54 | def last_seen(self) -> date: |
| 55 | """Last seen timestamp.""" |
| 56 | return datetime.fromtimestamp(lib.dc_contact_get_last_seen(self._dc_contact), timezone.utc) |
| 57 | |
| 58 | def is_blocked(self): |
| 59 | """Return True if the contact is blocked.""" |
| 60 | return lib.dc_contact_is_blocked(self._dc_contact) |
| 61 | |
| 62 | def set_blocked(self, block=True): |
| 63 | """[Deprecated, use block/unblock methods] Block or unblock a contact.""" |
| 64 | return lib.dc_block_contact(self.account._dc_context, self.id, block) |
| 65 | |
| 66 | def block(self): |
| 67 | """Block this contact. Message will not be seen/retrieved from this contact.""" |
| 68 | return lib.dc_block_contact(self.account._dc_context, self.id, True) |
| 69 |
no outgoing calls
no test coverage detected