changeset 42:286865bc013a

chat: joining MUC using header input is now working: in case of error, a simple log warning is used for now. TODO: need to display a proper notification
author Goffi <goffi@goffi.org>
date Sun, 28 Aug 2016 16:49:28 +0200
parents 7cac2d1a6f20
children 12fdc7d1feb1
files src/cagou/plugins/plugin_wid_chat.py
diffstat 1 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/cagou/plugins/plugin_wid_chat.py	Sun Aug 28 16:11:07 2016 +0200
+++ b/src/cagou/plugins/plugin_wid_chat.py	Sun Aug 28 16:49:28 2016 +0200
@@ -139,6 +139,23 @@
             )
         input_widget.text = ''
 
+    def _mucJoinCb(self, bare):
+        jid_ = jid.JID(bare)
+        self.changeWidget(jid_)
+
+    def _mucJoinEb(self, failure):
+        log.warning(u"Can't join room: {}".format(failure))
+
+    def changeWidget(self, jid_):
+        """change current widget for a new one with given jid
+
+        @param jid_(jid.JID): jid of the widget to create
+        """
+        plugin_info = G.host.getPluginInfo(main=Chat)
+        factory = plugin_info['factory']
+        G.host.switchWidget(self, factory(plugin_info, jid_, profiles=[self.profile]))
+        self.header_input.text = ''
+
     def onHeaderInput(self):
         text = self.header_input.text.strip()
         try:
@@ -152,13 +169,9 @@
         def discoCb(disco):
             # TODO: check if plugin XEP-0045 is activated
             if "conference" in [i[0] for i in disco[1]]:
-                raise NotImplementedError(u"MUC not implemented yet")
-                # G.host.bridge.MUCJoin(unicode(jid_), "", "", self.profile)
+                G.host.bridge.mucJoin(unicode(jid_), "", "", self.profile, callback=self._mucJoinCb, errback=self._mucJoinEb)
             else:
-                plugin_info = G.host.getPluginInfo(main=Chat)
-                factory = plugin_info['factory']
-                G.host.switchWidget(self, factory(plugin_info, jid_, profiles=[self.profile]))
-                self.header_input.text = ''
+                self.changeWidget(jid_)
 
         def discoEb(failure):
             log.warning(u"Disco failure, ignore this text: {}".format(failure))