Philipp Hörist pushed to branch master at gajim / gajim


Commits:
6a116676 by Philipp Hörist at 2019-08-03T10:58:05Z
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

- - - - -


2 changed files:

- gajim/common/config.py
- gajim/gtk/start_chat.py


Changes:

=====================================
gajim/common/config.py
=====================================
@@ -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, '[email protected]'],
+        '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 = {


=====================================
gajim/gtk/start_chat.py
=====================================
@@ -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
 



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/6a11667681b40f09eedecbe0cff3b5c913d4ccfb

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/6a11667681b40f09eedecbe0cff3b5c913d4ccfb
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to