Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_exp_invitation_pubsub.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 |
---|---|
55 "ps_invite", | 55 "ps_invite", |
56 ".plugin", | 56 ".plugin", |
57 in_sign="sssssss", | 57 in_sign="sssssss", |
58 out_sign="", | 58 out_sign="", |
59 method=self._send_pubsub_invitation, | 59 method=self._send_pubsub_invitation, |
60 async_=True | 60 async_=True, |
61 ) | 61 ) |
62 | 62 |
63 def register( | 63 def register(self, namespace: str, handler) -> None: |
64 self, | |
65 namespace: str, | |
66 handler | |
67 ) -> None: | |
68 self._ns_handler[namespace] = handler | 64 self._ns_handler[namespace] = handler |
69 self.host.plugins["INVITATION"].register_namespace(namespace, self.on_invitation) | 65 self.host.plugins["INVITATION"].register_namespace(namespace, self.on_invitation) |
70 | 66 |
71 def _send_pubsub_invitation( | 67 def _send_pubsub_invitation( |
72 self, invitee_jid_s, service_s, node, item_id=None, | 68 self, |
73 name=None, extra_s='', profile_key=C.PROF_KEY_NONE): | 69 invitee_jid_s, |
70 service_s, | |
71 node, | |
72 item_id=None, | |
73 name=None, | |
74 extra_s="", | |
75 profile_key=C.PROF_KEY_NONE, | |
76 ): | |
74 client = self.host.get_client(profile_key) | 77 client = self.host.get_client(profile_key) |
75 invitee_jid = jid.JID(invitee_jid_s) | 78 invitee_jid = jid.JID(invitee_jid_s) |
76 service = jid.JID(service_s) | 79 service = jid.JID(service_s) |
77 extra = data_format.deserialise(extra_s) | 80 extra = data_format.deserialise(extra_s) |
78 return defer.ensureDeferred( | 81 return defer.ensureDeferred( |
81 invitee_jid, | 84 invitee_jid, |
82 service, | 85 service, |
83 node, | 86 node, |
84 item_id or None, | 87 item_id or None, |
85 name=name or None, | 88 name=name or None, |
86 extra=extra | 89 extra=extra, |
87 ) | 90 ) |
88 ) | 91 ) |
89 | 92 |
90 async def invite( | 93 async def invite( |
91 self, | 94 self, |
92 client: SatXMPPEntity, | 95 client: SatXMPPEntity, |
93 invitee_jid: jid.JID, | 96 invitee_jid: jid.JID, |
94 service: jid.JID, | 97 service: jid.JID, |
95 node: str, | 98 node: str, |
96 item_id: Optional[str] = None, | 99 item_id: Optional[str] = None, |
97 name: str = '', | 100 name: str = "", |
98 extra: Optional[dict] = None, | 101 extra: Optional[dict] = None, |
99 ) -> None: | 102 ) -> None: |
100 if extra is None: | 103 if extra is None: |
101 extra = {} | 104 extra = {} |
102 else: | 105 else: |
110 except AttributeError: | 113 except AttributeError: |
111 log.debug(f"no invite_preflight method found for {namespace!r}") | 114 log.debug(f"no invite_preflight method found for {namespace!r}") |
112 else: | 115 else: |
113 await utils.as_deferred( | 116 await utils.as_deferred( |
114 preflight, | 117 preflight, |
115 client, invitee_jid, service, node, item_id, name, extra | 118 client, |
119 invitee_jid, | |
120 service, | |
121 node, | |
122 item_id, | |
123 name, | |
124 extra, | |
116 ) | 125 ) |
117 if item_id is None: | 126 if item_id is None: |
118 item_id = extra.pop("default_item_id", None) | 127 item_id = extra.pop("default_item_id", None) |
119 | 128 |
120 # we authorize our invitee to see the nodes of interest | 129 # we authorize our invitee to see the nodes of interest |
121 await self._p.set_node_affiliations(client, service, node, {invitee_jid: "member"}) | 130 await self._p.set_node_affiliations( |
131 client, service, node, {invitee_jid: "member"} | |
132 ) | |
122 log.debug(f"affiliation set on {service}'s {node!r} node") | 133 log.debug(f"affiliation set on {service}'s {node!r} node") |
123 | 134 |
124 # now we send the invitation | 135 # now we send the invitation |
125 self.host.plugins["INVITATION"].send_pubsub_invitation( | 136 self.host.plugins["INVITATION"].send_pubsub_invitation( |
126 client, | 137 client, invitee_jid, service, node, item_id, name=name or None, extra=extra |
127 invitee_jid, | |
128 service, | |
129 node, | |
130 item_id, | |
131 name=name or None, | |
132 extra=extra | |
133 ) | 138 ) |
134 | 139 |
135 async def on_invitation( | 140 async def on_invitation( |
136 self, | 141 self, |
137 client: SatXMPPEntity, | 142 client: SatXMPPEntity, |
139 name: str, | 144 name: str, |
140 extra: dict, | 145 extra: dict, |
141 service: jid.JID, | 146 service: jid.JID, |
142 node: str, | 147 node: str, |
143 item_id: Optional[str], | 148 item_id: Optional[str], |
144 item_elt: domish.Element | 149 item_elt: domish.Element, |
145 ) -> None: | 150 ) -> None: |
146 if extra is None: | 151 if extra is None: |
147 extra = {} | 152 extra = {} |
148 try: | 153 try: |
149 handler = self._ns_handler[namespace] | 154 handler = self._ns_handler[namespace] |
153 except AttributeError: | 158 except AttributeError: |
154 log.debug(f"no on_invitation_preflight method found for {namespace!r}") | 159 log.debug(f"no on_invitation_preflight method found for {namespace!r}") |
155 else: | 160 else: |
156 await utils.as_deferred( | 161 await utils.as_deferred( |
157 preflight, | 162 preflight, |
158 client, namespace, name, extra, service, node, item_id, item_elt | 163 client, |
164 namespace, | |
165 name, | |
166 extra, | |
167 service, | |
168 node, | |
169 item_id, | |
170 item_elt, | |
159 ) | 171 ) |
160 if item_id is None: | 172 if item_id is None: |
161 item_id = extra.pop("default_item_id", None) | 173 item_id = extra.pop("default_item_id", None) |
162 creator = extra.pop("creator", False) | 174 creator = extra.pop("creator", False) |
163 element = extra.pop("element", None) | 175 element = extra.pop("element", None) |
164 if not name: | 176 if not name: |
165 name = extra.pop("name", "") | 177 name = extra.pop("name", "") |
166 | 178 |
167 return await self.host.plugins['LIST_INTEREST'].register_pubsub( | 179 return await self.host.plugins["LIST_INTEREST"].register_pubsub( |
168 client, namespace, service, node, item_id, creator, | 180 client, namespace, service, node, item_id, creator, name, element, extra |
169 name, element, extra) | 181 ) |