Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0055.py @ 1810:25c3569abb71
plugin XEP-0055, tmp_directory_subscription: move directory subscription to a new temporary plugin
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 17 Sep 2015 11:04:17 +0200 |
parents | d17772b0fe22 |
children | 2daf7b4c6756 |
comparison
equal
deleted
inserted
replaced
1809:821c77574ad9 | 1810:25c3569abb71 |
---|---|
43 "name": "Jabber Search", | 43 "name": "Jabber Search", |
44 "import_name": "XEP-0055", | 44 "import_name": "XEP-0055", |
45 "type": "XEP", | 45 "type": "XEP", |
46 "protocols": ["XEP-0055"], | 46 "protocols": ["XEP-0055"], |
47 "dependencies": [], | 47 "dependencies": [], |
48 "recommendations": ["XEP-0050", "XEP-0059"], | 48 "recommendations": ["XEP-0059"], |
49 "main": "XEP_0055", | 49 "main": "XEP_0055", |
50 "handler": "no", | 50 "handler": "no", |
51 "description": _("""Implementation of Jabber Search""") | 51 "description": _("""Implementation of Jabber Search""") |
52 } | 52 } |
53 | 53 |
76 method=self._searchRequest, | 76 method=self._searchRequest, |
77 async=True) | 77 async=True) |
78 | 78 |
79 self.__search_menu_id = host.registerCallback(self._getMainUI, with_data=True) | 79 self.__search_menu_id = host.registerCallback(self._getMainUI, with_data=True) |
80 host.importMenu((D_("Contacts"), D_("Search directory")), self._getMainUI, security_limit=1, help_string=D_("Search user directory")) | 80 host.importMenu((D_("Contacts"), D_("Search directory")), self._getMainUI, security_limit=1, help_string=D_("Search user directory")) |
81 if "XEP-0050" in host.plugins: | |
82 host.importMenu((D_("Service"), D_("Directory subscription")), self.subscribe, security_limit=1, help_string=D_("User directory subscription")) | |
83 | 81 |
84 def _getHostServices(self, profile): | 82 def _getHostServices(self, profile): |
85 """Return the jabber search services associated to the user host. | 83 """Return the jabber search services associated to the user host. |
86 | 84 |
87 @param profile (unicode): %(doc_profile)s | 85 @param profile (unicode): %(doc_profile)s |
444 """ | 442 """ |
445 log.info(_("Search request failure: %s") % unicode(failure.getErrorMessage())) | 443 log.info(_("Search request failure: %s") % unicode(failure.getErrorMessage())) |
446 raise failure | 444 raise failure |
447 | 445 |
448 | 446 |
449 ## Subscription ## | 447 class XEP_0055_handler(XMPPHandler): |
450 | |
451 | |
452 def subscribe(self, raw_data, profile): | |
453 """Request available commands on the jabber search service associated to profile's host. | |
454 | |
455 @param raw_data (dict): data received from the frontend | |
456 @param profile (unicode): %(doc_profile)s | |
457 @return: a deferred dict{unicode: unicode} | |
458 """ | |
459 d = self._getHostServices(profile) | |
460 | |
461 def got_services(services): | |
462 service_jid = services[0] | |
463 d = self.host.plugins["XEP-0050"].requestCommandsList(service_jid, profile) | |
464 return d.addCallback(got_commands, service_jid) | |
465 | |
466 def got_commands(form_ui, service_jid): | |
467 session_id, session_data = self.host.plugins["XEP-0050"].requesting.newSession(profile=profile) | |
468 session_data["jid"] = service_jid | |
469 form_ui.session_id = session_id | |
470 return {'xmlui': form_ui.toXml()} | |
471 | |
472 return d.addCallback(got_services) | |
473 | |
474 | |
475 class XEP_0059_handler(XMPPHandler): | |
476 implements(iwokkel.IDisco) | 448 implements(iwokkel.IDisco) |
477 | 449 |
478 def __init__(self, plugin_parent, profile): | 450 def __init__(self, plugin_parent, profile): |
479 self.plugin_parent = plugin_parent | 451 self.plugin_parent = plugin_parent |
480 self.host = plugin_parent.host | 452 self.host = plugin_parent.host |