Coverage for slidge/slixfix/roster.py: 88%

24 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-07 05:11 +0000

1import logging 

2from typing import TYPE_CHECKING 

3 

4from slixmpp import JID 

5 

6if TYPE_CHECKING: 

7 from .. import BaseGateway 

8 

9 

10class YesSet(set): 

11 """ 

12 A pseudo-set which always test True for membership 

13 """ 

14 

15 def __contains__(self, item): 

16 log.debug("Test in") 

17 return True 

18 

19 

20class RosterBackend: 

21 """ 

22 A pseudo-roster for the gateway component. 

23 

24 If a user is in the user store, this will behave as if the user is part of the 

25 roster with subscription "both", and "none" otherwise. 

26 

27 This is rudimentary but the only sane way I could come up with so far. 

28 """ 

29 

30 def __init__(self, xmpp: "BaseGateway"): 

31 self.xmpp = xmpp 

32 

33 @staticmethod 

34 def entries(_owner_jid, _default=None): 

35 return YesSet() 

36 

37 @staticmethod 

38 def save(_owner_jid, _jid, _item_state, _db_state): 

39 pass 

40 

41 def load(self, _owner_jid, jid, _db_state): 

42 log.debug("Load %s", jid) 

43 user = self.xmpp.store.users.get(JID(jid)) 

44 log.debug("User %s", user) 

45 if user is None: 

46 return { 

47 "name": "", 

48 "groups": [], 

49 "from": False, 

50 "to": False, 

51 "pending_in": False, 

52 "pending_out": False, 

53 "whitelisted": False, 

54 "subscription": "both", 

55 } 

56 else: 

57 return { 

58 "name": "", 

59 "groups": [], 

60 "from": True, 

61 "to": True, 

62 "pending_in": False, 

63 "pending_out": False, 

64 "whitelisted": False, 

65 "subscription": "none", 

66 } 

67 

68 

69log = logging.getLogger(__name__)