comparison sat/plugins/plugin_exp_invitation_pubsub.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents 26c3e1bc7fb7
children
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
49 log.info(_("Pubsub Invitation plugin initialization")) 49 log.info(_("Pubsub Invitation plugin initialization"))
50 self.host = host 50 self.host = host
51 self._p = host.plugins["XEP-0060"] 51 self._p = host.plugins["XEP-0060"]
52 # namespace to handler map 52 # namespace to handler map
53 self._ns_handler = {} 53 self._ns_handler = {}
54 host.bridge.addMethod( 54 host.bridge.add_method(
55 "psInvite", 55 "ps_invite",
56 ".plugin", 56 ".plugin",
57 in_sign="sssssss", 57 in_sign="sssssss",
58 out_sign="", 58 out_sign="",
59 method=self._sendPubsubInvitation, 59 method=self._send_pubsub_invitation,
60 async_=True 60 async_=True
61 ) 61 )
62 62
63 def register( 63 def register(
64 self, 64 self,
65 namespace: str, 65 namespace: str,
66 handler 66 handler
67 ) -> None: 67 ) -> None:
68 self._ns_handler[namespace] = handler 68 self._ns_handler[namespace] = handler
69 self.host.plugins["INVITATION"].registerNamespace(namespace, self.onInvitation) 69 self.host.plugins["INVITATION"].register_namespace(namespace, self.on_invitation)
70 70
71 def _sendPubsubInvitation( 71 def _send_pubsub_invitation(
72 self, invitee_jid_s, service_s, node, item_id=None, 72 self, invitee_jid_s, service_s, node, item_id=None,
73 name=None, extra_s='', profile_key=C.PROF_KEY_NONE): 73 name=None, extra_s='', profile_key=C.PROF_KEY_NONE):
74 client = self.host.getClient(profile_key) 74 client = self.host.get_client(profile_key)
75 invitee_jid = jid.JID(invitee_jid_s) 75 invitee_jid = jid.JID(invitee_jid_s)
76 service = jid.JID(service_s) 76 service = jid.JID(service_s)
77 extra = data_format.deserialise(extra_s) 77 extra = data_format.deserialise(extra_s)
78 return defer.ensureDeferred( 78 return defer.ensureDeferred(
79 self.invite( 79 self.invite(
102 else: 102 else:
103 namespace = extra.get("namespace") 103 namespace = extra.get("namespace")
104 if namespace: 104 if namespace:
105 try: 105 try:
106 handler = self._ns_handler[namespace] 106 handler = self._ns_handler[namespace]
107 preflight = handler.invitePreflight 107 preflight = handler.invite_preflight
108 except KeyError: 108 except KeyError:
109 pass 109 pass
110 except AttributeError: 110 except AttributeError:
111 log.debug(f"no invitePreflight method found for {namespace!r}") 111 log.debug(f"no invite_preflight method found for {namespace!r}")
112 else: 112 else:
113 await utils.asDeferred( 113 await utils.as_deferred(
114 preflight, 114 preflight,
115 client, invitee_jid, service, node, item_id, name, extra 115 client, invitee_jid, service, node, item_id, name, extra
116 ) 116 )
117 if item_id is None: 117 if item_id is None:
118 item_id = extra.pop("default_item_id", None) 118 item_id = extra.pop("default_item_id", None)
119 119
120 # we authorize our invitee to see the nodes of interest 120 # we authorize our invitee to see the nodes of interest
121 await self._p.setNodeAffiliations(client, service, node, {invitee_jid: "member"}) 121 await self._p.set_node_affiliations(client, service, node, {invitee_jid: "member"})
122 log.debug(f"affiliation set on {service}'s {node!r} node") 122 log.debug(f"affiliation set on {service}'s {node!r} node")
123 123
124 # now we send the invitation 124 # now we send the invitation
125 self.host.plugins["INVITATION"].sendPubsubInvitation( 125 self.host.plugins["INVITATION"].send_pubsub_invitation(
126 client, 126 client,
127 invitee_jid, 127 invitee_jid,
128 service, 128 service,
129 node, 129 node,
130 item_id, 130 item_id,
131 name=name or None, 131 name=name or None,
132 extra=extra 132 extra=extra
133 ) 133 )
134 134
135 async def onInvitation( 135 async def on_invitation(
136 self, 136 self,
137 client: SatXMPPEntity, 137 client: SatXMPPEntity,
138 namespace: str, 138 namespace: str,
139 name: str, 139 name: str,
140 extra: dict, 140 extra: dict,
151 except KeyError: 151 except KeyError:
152 pass 152 pass
153 except AttributeError: 153 except AttributeError:
154 log.debug(f"no on_invitation_preflight method found for {namespace!r}") 154 log.debug(f"no on_invitation_preflight method found for {namespace!r}")
155 else: 155 else:
156 await utils.asDeferred( 156 await utils.as_deferred(
157 preflight, 157 preflight,
158 client, namespace, name, extra, service, node, item_id, item_elt 158 client, namespace, name, extra, service, node, item_id, item_elt
159 ) 159 )
160 if item_id is None: 160 if item_id is None:
161 item_id = extra.pop("default_item_id", None) 161 item_id = extra.pop("default_item_id", None)
162 creator = extra.pop("creator", False) 162 creator = extra.pop("creator", False)
163 element = extra.pop("element", None) 163 element = extra.pop("element", None)
164 if not name: 164 if not name:
165 name = extra.pop("name", "") 165 name = extra.pop("name", "")
166 166
167 return await self.host.plugins['LIST_INTEREST'].registerPubsub( 167 return await self.host.plugins['LIST_INTEREST'].register_pubsub(
168 client, namespace, service, node, item_id, creator, 168 client, namespace, service, node, item_id, creator,
169 name, element, extra) 169 name, element, extra)