Mercurial > libervia-backend
comparison libervia/backend/core/xmpp.py @ 4355:01ee3b902d33
types: Add `SatXMPPClient` to core types, add `roster` and improve type hints.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 11 Apr 2025 18:19:28 +0200 |
parents | 17fa953c8cd7 |
children | 676a320415b9 |
comparison
equal
deleted
inserted
replaced
4354:4a8bb49b9d0f | 4355:01ee3b902d33 |
---|---|
939 | 939 |
940 ExtraDict = dict # TODO | 940 ExtraDict = dict # TODO |
941 | 941 |
942 | 942 |
943 @implementer(iwokkel.IDisco) | 943 @implementer(iwokkel.IDisco) |
944 class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient): | 944 class SatXMPPClient(SatXMPPEntity, core_types.SatXMPPClient, wokkel_client.XMPPClient): |
945 trigger_suffix = "" | 945 trigger_suffix = "" |
946 is_component = False | 946 is_component = False |
947 | 947 |
948 def __init__( | 948 def __init__( |
949 self, | 949 self, |
1551 def __init__(self, host): | 1551 def __init__(self, host): |
1552 xmppim.RosterClientProtocol.__init__(self) | 1552 xmppim.RosterClientProtocol.__init__(self) |
1553 self.host = host | 1553 self.host = host |
1554 self.got_roster = defer.Deferred() # called when roster is received and ready | 1554 self.got_roster = defer.Deferred() # called when roster is received and ready |
1555 # XXX: the two following dicts keep a local copy of the roster | 1555 # XXX: the two following dicts keep a local copy of the roster |
1556 self._jids = {} # map from jids to RosterItem: key=jid value=RosterItem | 1556 self._jids: dict[jid.JID, xmppim.RosterItem] = {} |
1557 self._groups = {} # map from groups to jids: key=group value=set of jids | 1557 self._groups: dict[str, set[jid.JID]] = {} # map from groups to jids |
1558 | 1558 |
1559 def __contains__(self, entity_jid): | 1559 def __contains__(self, entity_jid): |
1560 return self.is_jid_in_roster(entity_jid) | 1560 return self.is_jid_in_roster(entity_jid) |
1561 | 1561 |
1562 @property | 1562 @property |
1771 ) | 1771 ) |
1772 | 1772 |
1773 # then we send the bridge signal | 1773 # then we send the bridge signal |
1774 self.host.bridge.contact_deleted(entity.full(), self.parent.profile) | 1774 self.host.bridge.contact_deleted(entity.full(), self.parent.profile) |
1775 | 1775 |
1776 def get_groups(self): | 1776 def get_groups(self) -> list[str]: |
1777 """Return a list of groups""" | 1777 """Return a list of groups""" |
1778 return list(self._groups.keys()) | 1778 return list(self._groups.keys()) |
1779 | 1779 |
1780 def get_item(self, entity_jid): | 1780 def get_item(self, entity_jid) -> xmppim.RosterItem | None: |
1781 """Return RosterItem for a given jid | 1781 """Return RosterItem for a given jid |
1782 | 1782 |
1783 @param entity_jid(jid.JID): jid of the contact | 1783 @param entity_jid(jid.JID): jid of the contact |
1784 @return(RosterItem, None): RosterItem instance | 1784 @return(RosterItem, None): RosterItem instance |
1785 None if contact is not in cache | 1785 None if contact is not in cache |
1786 """ | 1786 """ |
1787 return self._jids.get(entity_jid, None) | 1787 return self._jids.get(entity_jid, None) |
1788 | 1788 |
1789 def get_jids(self): | 1789 def get_jids(self) -> list[jid.JID]: |
1790 """Return all jids of the roster""" | 1790 """Return all jids of the roster""" |
1791 return list(self._jids.keys()) | 1791 return list(self._jids.keys()) |
1792 | 1792 |
1793 def is_jid_in_roster(self, entity_jid): | 1793 def is_jid_in_roster(self, entity_jid) -> bool: |
1794 """Return True if jid is in roster""" | 1794 """Return True if jid is in roster""" |
1795 if not isinstance(entity_jid, jid.JID): | 1795 if not isinstance(entity_jid, jid.JID): |
1796 raise exceptions.InternalError( | 1796 raise exceptions.InternalError( |
1797 f"a JID is expected, not {type(entity_jid)}: {entity_jid!r}" | 1797 f"a JID is expected, not {type(entity_jid)}: {entity_jid!r}" |
1798 ) | 1798 ) |