diff 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
line wrap: on
line diff
--- a/libervia/backend/core/xmpp.py	Fri Apr 11 18:19:17 2025 +0200
+++ b/libervia/backend/core/xmpp.py	Fri Apr 11 18:19:28 2025 +0200
@@ -941,7 +941,7 @@
 
 
 @implementer(iwokkel.IDisco)
-class SatXMPPClient(SatXMPPEntity, wokkel_client.XMPPClient):
+class SatXMPPClient(SatXMPPEntity, core_types.SatXMPPClient, wokkel_client.XMPPClient):
     trigger_suffix = ""
     is_component = False
 
@@ -1553,8 +1553,8 @@
         self.host = host
         self.got_roster = defer.Deferred()  # called when roster is received and ready
         # XXX: the two following dicts keep a local copy of the roster
-        self._jids = {}  # map from jids to RosterItem: key=jid value=RosterItem
-        self._groups = {}  # map from groups to jids: key=group value=set of jids
+        self._jids: dict[jid.JID, xmppim.RosterItem] = {}
+        self._groups: dict[str, set[jid.JID]] = {}  # map from groups to jids
 
     def __contains__(self, entity_jid):
         return self.is_jid_in_roster(entity_jid)
@@ -1773,11 +1773,11 @@
         # then we send the bridge signal
         self.host.bridge.contact_deleted(entity.full(), self.parent.profile)
 
-    def get_groups(self):
+    def get_groups(self) -> list[str]:
         """Return a list of groups"""
         return list(self._groups.keys())
 
-    def get_item(self, entity_jid):
+    def get_item(self, entity_jid) -> xmppim.RosterItem | None:
         """Return RosterItem for a given jid
 
         @param entity_jid(jid.JID): jid of the contact
@@ -1786,11 +1786,11 @@
         """
         return self._jids.get(entity_jid, None)
 
-    def get_jids(self):
+    def get_jids(self) -> list[jid.JID]:
         """Return all jids of the roster"""
         return list(self._jids.keys())
 
-    def is_jid_in_roster(self, entity_jid):
+    def is_jid_in_roster(self, entity_jid) -> bool:
         """Return True if jid is in roster"""
         if not isinstance(entity_jid, jid.JID):
             raise exceptions.InternalError(