comparison src/plugins/plugin_xep_0055.py @ 1509:72e6ee3fdf53

plugin XEP-0055: add "Directory subscription" menu + use the category "Service" for this plugin's menus instead of "Communication"
author souliane <souliane@mailoo.org>
date Wed, 02 Sep 2015 14:59:28 +0200
parents ec60682a9d17
children e0bde0d0b321
comparison
equal deleted inserted replaced
1508:ec60682a9d17 1509:72e6ee3fdf53
44 "name": "Jabber Search", 44 "name": "Jabber Search",
45 "import_name": "XEP-0055", 45 "import_name": "XEP-0055",
46 "type": "XEP", 46 "type": "XEP",
47 "protocols": ["XEP-0055"], 47 "protocols": ["XEP-0055"],
48 "dependencies": [], 48 "dependencies": [],
49 "recommendations": ["XEP-0059"], 49 "recommendations": ["XEP-0050", "XEP-0059"],
50 "main": "XEP_0055", 50 "main": "XEP_0055",
51 "handler": "no", 51 "handler": "no",
52 "description": _("""Implementation of Jabber Search""") 52 "description": _("""Implementation of Jabber Search""")
53 } 53 }
54 54
76 host.bridge.addMethod("searchRequest", ".plugin", in_sign='sa{ss}s', out_sign='s', 76 host.bridge.addMethod("searchRequest", ".plugin", in_sign='sa{ss}s', out_sign='s',
77 method=self._searchRequest, 77 method=self._searchRequest,
78 async=True) 78 async=True)
79 79
80 self.__search_menu_id = host.registerCallback(self._getMainUI, with_data=True) 80 self.__search_menu_id = host.registerCallback(self._getMainUI, with_data=True)
81 host.importMenu((D_("Communication"), D_("Search directory")), self._getMainUI, security_limit=1, help_string=D_("Search use directory")) 81 host.importMenu((D_("Service"), D_("Search directory")), self._getMainUI, security_limit=1, help_string=D_("Search user directory"))
82 if "XEP-0050" in host.plugins:
83 host.importMenu((D_("Service"), D_("Directory subscription")), self.subscribe, security_limit=1, help_string=D_("User directory subscription"))
84
85 def _getHostServices(self, profile):
86 """Return the jabber search services associated to the user host.
87
88 @param profile (unicode): %(doc_profile)s
89 @return: list[jid.JID]
90 """
91 d = self.host.findFeaturesSet([NS_SEARCH], profile_key=profile)
92 return d.addCallback(lambda set_: list(set_))
82 93
83 94
84 ## Main search UI (menu item callback) ## 95 ## Main search UI (menu item callback) ##
85 96
86 97
90 @param raw_data (dict): data received from the frontend 101 @param raw_data (dict): data received from the frontend
91 @param profile (unicode): %(doc_profile)s 102 @param profile (unicode): %(doc_profile)s
92 @return: a deferred XMLUI string representation 103 @return: a deferred XMLUI string representation
93 """ 104 """
94 # check if the user's server offers some search services 105 # check if the user's server offers some search services
95 d = self.host.findFeaturesSet([NS_SEARCH], profile_key=profile) 106 d = self._getHostServices(profile)
96 return d.addCallback(lambda services: self.getMainUI(list(services), raw_data, profile)) 107 return d.addCallback(lambda services: self.getMainUI(services, raw_data, profile))
97 108
98 def getMainUI(self, services, raw_data, profile): 109 def getMainUI(self, services, raw_data, profile):
99 """Get the XMLUI for selecting a service and searching the directory. 110 """Get the XMLUI for selecting a service and searching the directory.
100 111
101 @param services (list[jid.JID]): search services offered by the user server 112 @param services (list[jid.JID]): search services offered by the user server
434 """ 445 """
435 log.info(_("Search request failure: %s") % unicode(failure.getErrorMessage())) 446 log.info(_("Search request failure: %s") % unicode(failure.getErrorMessage()))
436 raise failure 447 raise failure
437 448
438 449
450 ## Subscription ##
451
452
453 def subscribe(self, raw_data, profile):
454 """Request available commands on the jabber search service associated to profile's host.
455
456 @param raw_data (dict): data received from the frontend
457 @param profile (unicode): %(doc_profile)s
458 @return: a deferred dict{unicode: unicode}
459 """
460 d = self._getHostServices(profile)
461
462 def got_services(services):
463 service_jid = services[0]
464 d = self.host.plugins["XEP-0050"].requestCommandsList(service_jid, profile)
465 return d.addCallback(got_commands, service_jid)
466
467 def got_commands(form_ui, service_jid):
468 session_id, session_data = self.host.plugins["XEP-0050"].requesting.newSession(profile=profile)
469 session_data["jid"] = service_jid
470 form_ui.session_id = session_id
471 return {'xmlui': form_ui.toXml()}
472
473 return d.addCallback(got_services)
474
475
439 class XEP_0059_handler(XMPPHandler): 476 class XEP_0059_handler(XMPPHandler):
440 implements(iwokkel.IDisco) 477 implements(iwokkel.IDisco)
441 478
442 def __init__(self, plugin_parent, profile): 479 def __init__(self, plugin_parent, profile):
443 self.plugin_parent = plugin_parent 480 self.plugin_parent = plugin_parent