Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0055.py @ 1552:e0bde0d0b321
core (disco): use of “profile” instead of “profile_key” in several disco methods
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Nov 2015 22:02:41 +0100 |
parents | 72e6ee3fdf53 |
children | 94c450972346 |
comparison
equal
deleted
inserted
replaced
1551:591c32dbfb0b | 1552:e0bde0d0b321 |
---|---|
25 from twisted.words.protocols.jabber import jid | 25 from twisted.words.protocols.jabber import jid |
26 from twisted.internet import defer | 26 from twisted.internet import defer |
27 from wokkel import data_form | 27 from wokkel import data_form |
28 from sat.core.constants import Const as C | 28 from sat.core.constants import Const as C |
29 from sat.core.exceptions import DataError | 29 from sat.core.exceptions import DataError |
30 from sat.memory.memory import Sessions | |
31 from sat.tools import xml_tools | 30 from sat.tools import xml_tools |
32 | 31 |
33 from wokkel import disco, iwokkel | 32 from wokkel import disco, iwokkel |
34 try: | 33 try: |
35 from twisted.words.protocols.xmlstream import XMPPHandler | 34 from twisted.words.protocols.xmlstream import XMPPHandler |
82 if "XEP-0050" in host.plugins: | 81 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")) | 82 host.importMenu((D_("Service"), D_("Directory subscription")), self.subscribe, security_limit=1, help_string=D_("User directory subscription")) |
84 | 83 |
85 def _getHostServices(self, profile): | 84 def _getHostServices(self, profile): |
86 """Return the jabber search services associated to the user host. | 85 """Return the jabber search services associated to the user host. |
87 | 86 |
88 @param profile (unicode): %(doc_profile)s | 87 @param profile (unicode): %(doc_profile)s |
89 @return: list[jid.JID] | 88 @return: list[jid.JID] |
90 """ | 89 """ |
91 d = self.host.findFeaturesSet([NS_SEARCH], profile_key=profile) | 90 d = self.host.findFeaturesSet([NS_SEARCH], profile=profile) |
92 return d.addCallback(lambda set_: list(set_)) | 91 return d.addCallback(lambda set_: list(set_)) |
93 | 92 |
94 | 93 |
95 ## Main search UI (menu item callback) ## | 94 ## Main search UI (menu item callback) ## |
96 | 95 |
123 d.addCallback(lambda dummy: self._addAdvancedSearchUI(services, main_ui, data, profile)) | 122 d.addCallback(lambda dummy: self._addAdvancedSearchUI(services, main_ui, data, profile)) |
124 return d.addCallback(lambda dummy: {'xmlui': main_ui.toXml()}) | 123 return d.addCallback(lambda dummy: {'xmlui': main_ui.toXml()}) |
125 | 124 |
126 def _addSimpleSearchUI(self, services, main_ui, data, profile): | 125 def _addSimpleSearchUI(self, services, main_ui, data, profile): |
127 """Add to the main UI a tab for the simple search. | 126 """Add to the main UI a tab for the simple search. |
128 | 127 |
129 Display a single input field and search on the main service (it actually does one search per search field and then compile the results). | 128 Display a single input field and search on the main service (it actually does one search per search field and then compile the results). |
130 | 129 |
131 @param services (list[jid.JID]): search services offered by the user server | 130 @param services (list[jid.JID]): search services offered by the user server |
132 @param main_ui (XMLUI): the main XMLUI instance | 131 @param main_ui (XMLUI): the main XMLUI instance |
133 @param data (dict): form data without SAT_FORM_PREFIX | 132 @param data (dict): form data without SAT_FORM_PREFIX |
141 form.addField(data_form.Field('text-single', FIELD_SINGLE, label=_('Search for'), value=data.get(FIELD_SINGLE, ''))) | 140 form.addField(data_form.Field('text-single', FIELD_SINGLE, label=_('Search for'), value=data.get(FIELD_SINGLE, ''))) |
142 | 141 |
143 sub_cont = main_ui.main_container.addTab("simple_search", label=_("Simple search"), container=xml_tools.VerticalContainer) | 142 sub_cont = main_ui.main_container.addTab("simple_search", label=_("Simple search"), container=xml_tools.VerticalContainer) |
144 main_ui.changeContainer(sub_cont.append(xml_tools.PairsContainer(main_ui))) | 143 main_ui.changeContainer(sub_cont.append(xml_tools.PairsContainer(main_ui))) |
145 xml_tools.dataForm2Widgets(main_ui, form) | 144 xml_tools.dataForm2Widgets(main_ui, form) |
146 | 145 |
147 # FIXME: add colspan attribute to divider? (we are in a PairsContainer) | 146 # FIXME: add colspan attribute to divider? (we are in a PairsContainer) |
148 main_ui.addDivider('blank') | 147 main_ui.addDivider('blank') |
149 main_ui.addDivider('blank') # here we added a blank line before the button | 148 main_ui.addDivider('blank') # here we added a blank line before the button |
150 main_ui.addDivider('blank') | 149 main_ui.addDivider('blank') |
151 main_ui.addButton(self.__search_menu_id, _("Search"), (FIELD_SINGLE,)) | 150 main_ui.addButton(self.__search_menu_id, _("Search"), (FIELD_SINGLE,)) |
241 # FIXME: wokkel's data_form.Form.fromElement doesn't parse the values, so we do it directly in XMLUI for now | 240 # FIXME: wokkel's data_form.Form.fromElement doesn't parse the values, so we do it directly in XMLUI for now |
242 for widget in main_ui.current_container.elem.childNodes: | 241 for widget in main_ui.current_container.elem.childNodes: |
243 name = widget.getAttribute("name") | 242 name = widget.getAttribute("name") |
244 if adv_data.get(name): | 243 if adv_data.get(name): |
245 widget.setAttribute("value", adv_data[name]) | 244 widget.setAttribute("value", adv_data[name]) |
246 | 245 |
247 # FIXME: add colspan attribute to divider? (we are in a PairsContainer) | 246 # FIXME: add colspan attribute to divider? (we are in a PairsContainer) |
248 main_ui.addDivider('blank') | 247 main_ui.addDivider('blank') |
249 main_ui.addDivider('blank') # here we added a blank line before the button | 248 main_ui.addDivider('blank') # here we added a blank line before the button |
250 main_ui.addDivider('blank') | 249 main_ui.addDivider('blank') |
251 main_ui.addButton(self.__search_menu_id, _("Search"), adv_fields + [FIELD_CURRENT_SERVICE]) | 250 main_ui.addButton(self.__search_menu_id, _("Search"), adv_fields + [FIELD_CURRENT_SERVICE]) |
265 return defer.succeed(None) | 264 return defer.succeed(None) |
266 | 265 |
267 | 266 |
268 def _displaySearchResult(self, main_ui, elt): | 267 def _displaySearchResult(self, main_ui, elt): |
269 """Display the search results. | 268 """Display the search results. |
270 | 269 |
271 @param main_ui (XMLUI): the main XMLUI instance | 270 @param main_ui (XMLUI): the main XMLUI instance |
272 @param elt (domish.Element): form result element | 271 @param elt (domish.Element): form result element |
273 """ | 272 """ |
274 if [child for child in elt.children if child.name == "item"]: | 273 if [child for child in elt.children if child.name == "item"]: |
275 headers, xmlui_data = xml_tools.dataFormResult2XMLUIData(elt) | 274 headers, xmlui_data = xml_tools.dataFormResult2XMLUIData(elt) |
276 if "jid" in headers: # use XMLUI JidsListWidget to display the results | 275 if "jid" in headers: # use XMLUI JidsListWidget to display the results |
277 values = {} | 276 values = {} |
278 for i in range(len(xmlui_data)): | 277 for i in range(len(xmlui_data)): |
279 header = headers.keys()[i % len(headers)] | 278 header = headers.keys()[i % len(headers)] |
456 @param raw_data (dict): data received from the frontend | 455 @param raw_data (dict): data received from the frontend |
457 @param profile (unicode): %(doc_profile)s | 456 @param profile (unicode): %(doc_profile)s |
458 @return: a deferred dict{unicode: unicode} | 457 @return: a deferred dict{unicode: unicode} |
459 """ | 458 """ |
460 d = self._getHostServices(profile) | 459 d = self._getHostServices(profile) |
461 | 460 |
462 def got_services(services): | 461 def got_services(services): |
463 service_jid = services[0] | 462 service_jid = services[0] |
464 d = self.host.plugins["XEP-0050"].requestCommandsList(service_jid, profile) | 463 d = self.host.plugins["XEP-0050"].requestCommandsList(service_jid, profile) |
465 return d.addCallback(got_commands, service_jid) | 464 return d.addCallback(got_commands, service_jid) |
466 | 465 |