Coverage for slidge / slixfix / roster.py: 86%
22 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-06 05:07 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-06 05:07 +0000
1import logging
2from collections.abc import Iterable
3from typing import TYPE_CHECKING, Any
5from slixmpp import JID
6from slixmpp.types import JidStr, OptJidStr, RosterState
8if TYPE_CHECKING:
9 from .. import BaseGateway
12class YesSet(set):
13 """
14 A pseudo-set which always test True for membership
15 """
17 def __contains__(self, item: object) -> bool:
18 log.debug("Test in")
19 return True
22class RosterBackend:
23 """
24 A pseudo-roster for the gateway component.
26 If a user is in the user store, this will behave as if the user is part of the
27 roster with subscription "both", and "none" otherwise.
29 This is rudimentary but the only sane way I could come up with so far.
30 """
32 def __init__(self, xmpp: "BaseGateway") -> None:
33 self.xmpp = xmpp
35 def entries(
36 self, owner: OptJidStr, db_state: dict[str, Any] | None = None
37 ) -> Iterable[str]:
38 return YesSet()
40 def save(
41 self, owner: JidStr, jid: JidStr, state: RosterState, db_state: dict[str, Any]
42 ) -> None:
43 pass
45 def load(
46 self, owner: JidStr, jid: JidStr, db_state: dict[str, Any]
47 ) -> RosterState | None:
48 session = self.xmpp.get_session_from_jid(JID(jid))
49 if session is None:
50 return {
51 "name": "",
52 "groups": [],
53 "from": False,
54 "to": False,
55 "pending_in": False,
56 "pending_out": False,
57 "whitelisted": False,
58 "subscription": "both",
59 }
60 else:
61 return {
62 "name": "",
63 "groups": [],
64 "from": True,
65 "to": True,
66 "pending_in": False,
67 "pending_out": False,
68 "whitelisted": False,
69 "subscription": "none",
70 }
73log = logging.getLogger(__name__)