comparison sat/plugins/plugin_misc_lists.py @ 3463:483bcfeb11c9

plugin misc list: register lists for pubsub invitations
author Goffi <goffi@goffi.org>
date Fri, 19 Feb 2021 15:52:28 +0100
parents 02a8d227d5bb
children 54b9cdbeb335
comparison
equal deleted inserted replaced
3462:12dc234f698c 3463:483bcfeb11c9
14 14
15 # You should have received a copy of the GNU Affero General Public License 15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>. 16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import shortuuid 18 import shortuuid
19 from typing import Tuple 19 from typing import List, Tuple, Optional
20 from twisted.internet import defer 20 from twisted.internet import defer
21 from twisted.words.xish import domish 21 from twisted.words.xish import domish
22 from twisted.words.protocols.jabber import jid 22 from twisted.words.protocols.jabber import jid
23 from wokkel import data_form 23 from wokkel import data_form
24 from sat.core.i18n import _, D_ 24 from sat.core.i18n import _, D_
25 from sat.core.xmpp import SatXMPPEntity
25 from sat.core.constants import Const as C 26 from sat.core.constants import Const as C
26 from sat.tools.common import uri 27 from sat.tools.common import uri
27 from sat.tools.common import data_format 28 from sat.tools.common import data_format
28 from sat.core.log import getLogger 29 from sat.core.log import getLogger
29 30
37 PLUGIN_INFO = { 38 PLUGIN_INFO = {
38 C.PI_NAME: _("Pubsub Lists"), 39 C.PI_NAME: _("Pubsub Lists"),
39 C.PI_IMPORT_NAME: "LISTS", 40 C.PI_IMPORT_NAME: "LISTS",
40 C.PI_TYPE: "EXP", 41 C.PI_TYPE: "EXP",
41 C.PI_PROTOCOLS: [], 42 C.PI_PROTOCOLS: [],
42 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0346", "XEP-0277", "IDENTITY"], 43 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0346", "XEP-0277", "IDENTITY",
44 "PUBSUB_INVITATION"],
43 C.PI_MAIN: "PubsubLists", 45 C.PI_MAIN: "PubsubLists",
44 C.PI_HANDLER: "no", 46 C.PI_HANDLER: "no",
45 C.PI_DESCRIPTION: _("""Pubsub lists management plugin"""), 47 C.PI_DESCRIPTION: _("""Pubsub lists management plugin"""),
46 } 48 }
47 49
206 log.info(_("Pubsub lists plugin initialization")) 208 log.info(_("Pubsub lists plugin initialization"))
207 self.host = host 209 self.host = host
208 self._s = self.host.plugins["XEP-0346"] 210 self._s = self.host.plugins["XEP-0346"]
209 self.namespace = self._s.getSubmittedNS(APP_NS_TICKETS) 211 self.namespace = self._s.getSubmittedNS(APP_NS_TICKETS)
210 host.registerNamespace("tickets", APP_NS_TICKETS) 212 host.registerNamespace("tickets", APP_NS_TICKETS)
213 self.host.plugins["PUBSUB_INVITATION"].register(
214 APP_NS_TICKETS, self
215 )
211 self._p = self.host.plugins["XEP-0060"] 216 self._p = self.host.plugins["XEP-0060"]
212 self._m = self.host.plugins["XEP-0277"] 217 self._m = self.host.plugins["XEP-0277"]
213 host.bridge.addMethod( 218 host.bridge.addMethod(
214 "listGet", 219 "listGet",
215 ".plugin", 220 ".plugin",
272 in_sign="ssss", 277 in_sign="ssss",
273 out_sign="(ss)", 278 out_sign="(ss)",
274 method=self._createTemplate, 279 method=self._createTemplate,
275 async_=True, 280 async_=True,
276 ) 281 )
282
283 async def onInvitationPreflight(
284 self,
285 client: SatXMPPEntity,
286 namespace: str,
287 name: str,
288 extra: dict,
289 service: jid.JID,
290 node: str,
291 item_id: Optional[str],
292 item_elt: domish.Element
293 ) -> None:
294 try:
295 schema = await self._s.getSchemaForm(client, service, node)
296 except Exception as e:
297 log.warning(f"Can't retrive node schema as {node!r} [{service}]: {e}")
298 else:
299 try:
300 field_type = schema[NS_TICKETS_TYPE]
301 except KeyError:
302 log.debug("no type found in list schema")
303 else:
304 list_elt = extra["element"] = domish.Element((APP_NS_TICKETS, "list"))
305 list_elt["type"] = field_type
277 306
278 def _set(self, service, node, values, schema=None, item_id=None, extra='', 307 def _set(self, service, node, values, schema=None, item_id=None, extra='',
279 profile_key=C.PROF_KEY_NONE): 308 profile_key=C.PROF_KEY_NONE):
280 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet( 309 client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(
281 service, node, schema, item_id, extra, profile_key 310 service, node, schema, item_id, extra, profile_key