comparison libervia/backend/plugins/plugin_xep_0352.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 4b842c1fb686
children
comparison
equal deleted inserted replaced
4269:64a85ce8be70 4270:0d7bb4df2343
30 C.PI_TYPE: C.PLUG_TYPE_XEP, 30 C.PI_TYPE: C.PLUG_TYPE_XEP,
31 C.PI_PROTOCOLS: ["XEP-0352"], 31 C.PI_PROTOCOLS: ["XEP-0352"],
32 C.PI_DEPENDENCIES: [], 32 C.PI_DEPENDENCIES: [],
33 C.PI_MAIN: "XEP_0352", 33 C.PI_MAIN: "XEP_0352",
34 C.PI_HANDLER: "no", 34 C.PI_HANDLER: "no",
35 C.PI_DESCRIPTION: D_("Notify server when frontend is not actively used, to limit " 35 C.PI_DESCRIPTION: D_(
36 "traffic and save bandwidth and battery life"), 36 "Notify server when frontend is not actively used, to limit "
37 "traffic and save bandwidth and battery life"
38 ),
37 } 39 }
38 40
39 NS_CSI = "urn:xmpp:csi:0" 41 NS_CSI = "urn:xmpp:csi:0"
40 42
41 43
52 return True 54 return True
53 return client._xep_0352_active 55 return client._xep_0352_active
54 except AttributeError: 56 except AttributeError:
55 # _xep_0352_active can not be set if is_active is called before 57 # _xep_0352_active can not be set if is_active is called before
56 # profile_connected has been called 58 # profile_connected has been called
57 log.debug("is_active called when XEP-0352 plugin has not yet set the " 59 log.debug(
58 "attributes") 60 "is_active called when XEP-0352 plugin has not yet set the " "attributes"
61 )
59 return True 62 return True
60 63
61 def profile_connected(self, client): 64 def profile_connected(self, client):
62 if (NS_CSI, 'csi') in client.xmlstream.features: 65 if (NS_CSI, "csi") in client.xmlstream.features:
63 log.info(_("Client State Indication is available on this server")) 66 log.info(_("Client State Indication is available on this server"))
64 client._xep_0352_enabled = True 67 client._xep_0352_enabled = True
65 client._xep_0352_active = True 68 client._xep_0352_active = True
66 else: 69 else:
67 log.warning(_("Client State Indication is not available on this server, some" 70 log.warning(
68 " bandwidth optimisations can't be used.")) 71 _(
72 "Client State Indication is not available on this server, some"
73 " bandwidth optimisations can't be used."
74 )
75 )
69 client._xep_0352_enabled = False 76 client._xep_0352_enabled = False
70 77
71 def set_inactive(self, client): 78 def set_inactive(self, client):
72 if self.is_active(client): 79 if self.is_active(client):
73 inactive_elt = domish.Element((NS_CSI, 'inactive')) 80 inactive_elt = domish.Element((NS_CSI, "inactive"))
74 client.send(inactive_elt) 81 client.send(inactive_elt)
75 client._xep_0352_active = False 82 client._xep_0352_active = False
76 log.info("inactive state set") 83 log.info("inactive state set")
77 84
78 def set_active(self, client): 85 def set_active(self, client):
79 if not self.is_active(client): 86 if not self.is_active(client):
80 active_elt = domish.Element((NS_CSI, 'active')) 87 active_elt = domish.Element((NS_CSI, "active"))
81 client.send(active_elt) 88 client.send(active_elt)
82 client._xep_0352_active = True 89 client._xep_0352_active = True
83 log.info("active state set") 90 log.info("active state set")