Commit 6a116676 authored by Philipp Hörist's avatar Philipp Hörist

Muclumbus: Use HTTP API for requests

- HTTP is anonymous
- Works with servers that have s2s disabled
- Add ACE setting to switch between http and iq API
parent da6d923c
Pipeline #3990 passed with stages
in 2 minutes and 49 seconds
......@@ -293,6 +293,8 @@ class Config:
'send_chatstate_default': [opt_str, 'composing_only', _('Chat state notifications that are sent to contacts. Possible values: all, composing_only, disabled')],
'send_chatstate_muc_default': [opt_str, 'composing_only', _('Chat state notifications that are sent to the group chat. Possible values: \'all\', \'composing_only\', \'disabled\'')],
'muclumbus_api_jid': [opt_str, 'rodrigo.de.mucobedo@dreckshal.de'],
'muclumbus_api_http_uri': [opt_str, 'https://search.jabbercat.org/api/1.0/search'],
'muclumbus_api_pref': [opt_str, 'http', _('API Preferences. Possible values: \'http\', \'iq\'')],
}, {}) # type: Tuple[Dict[str, List[Any]], Dict[Any, Any]]
__options_per_key = {
......
......@@ -51,6 +51,7 @@ class StartChatDialog(Gtk.ApplicationWindow):
self.set_default_size(-1, 400)
self.ready_to_destroy = False
self._parameter_form = None
self._keywords = []
self._destroyed = False
self._search_stopped = False
......@@ -470,6 +471,12 @@ class StartChatDialog(Gtk.ApplicationWindow):
text = self._ui.search_entry.get_text().strip()
self._global_search_listbox.start_search()
if app.config.get('muclumbus_api_pref') == 'http':
self._start_http_search(con, text)
else:
self._start_iq_search(con, text)
def _start_iq_search(self, con, text):
if self._parameter_form is None:
con.get_module('Muclumbus').request_parameters(
app.config.get('muclumbus_api_jid'),
......@@ -482,7 +489,15 @@ class StartChatDialog(Gtk.ApplicationWindow):
app.config.get('muclumbus_api_jid'),
self._parameter_form,
callback=self._on_search_result,
user_data=con)
user_data=(con, False))
def _start_http_search(self, con, text):
self._keywords = text.split(' ')
con.get_module('Muclumbus').set_http_search(
app.config.get('muclumbus_api_http_uri'),
self._keywords,
callback=self._on_search_result,
user_data=(con, True))
@ensure_not_destroyed
def _parameters_received(self, result, user_data):
......@@ -494,16 +509,10 @@ class StartChatDialog(Gtk.ApplicationWindow):
con, text = user_data
self._parameter_form = result
self._parameter_form.type_ = 'submit'
self._parameter_form.vars['q'].value = text
con.get_module('Muclumbus').set_search(
app.config.get('muclumbus_api_jid'),
self._parameter_form,
callback=self._on_search_result,
user_data=con)
self._start_iq_search(con, text)
@ensure_not_destroyed
def _on_search_result(self, result, con):
def _on_search_result(self, result, user_data):
if self._search_stopped:
return
......@@ -519,6 +528,13 @@ class StartChatDialog(Gtk.ApplicationWindow):
self._global_search_listbox.end_search()
return
con, http = user_data
if http:
self._continue_http_search(result, con)
else:
self._continue_iq_search(result, con)
def _continue_iq_search(self, result, con):
con.get_module('Muclumbus').set_search(
app.config.get('muclumbus_api_jid'),
self._parameter_form,
......@@ -527,6 +543,14 @@ class StartChatDialog(Gtk.ApplicationWindow):
callback=self._on_search_result,
user_data=con)
def _continue_http_search(self, result, con):
con.get_module('Muclumbus').set_http_search(
app.config.get('muclumbus_api_http_uri'),
self._keywords,
after=result.last,
callback=self._on_search_result,
user_data=con)
def _destroy(self, *args):
self._destroyed = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment