comparison src/cagou/plugins/plugin_wid_chat.py @ 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 7819e9efa250
comparison
equal deleted inserted replaced
41:7cac2d1a6f20 42:286865bc013a
137 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, # TODO: put this in QuickChat 137 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, # TODO: put this in QuickChat
138 profile_key=self.profile 138 profile_key=self.profile
139 ) 139 )
140 input_widget.text = '' 140 input_widget.text = ''
141 141
142 def _mucJoinCb(self, bare):
143 jid_ = jid.JID(bare)
144 self.changeWidget(jid_)
145
146 def _mucJoinEb(self, failure):
147 log.warning(u"Can't join room: {}".format(failure))
148
149 def changeWidget(self, jid_):
150 """change current widget for a new one with given jid
151
152 @param jid_(jid.JID): jid of the widget to create
153 """
154 plugin_info = G.host.getPluginInfo(main=Chat)
155 factory = plugin_info['factory']
156 G.host.switchWidget(self, factory(plugin_info, jid_, profiles=[self.profile]))
157 self.header_input.text = ''
158
142 def onHeaderInput(self): 159 def onHeaderInput(self):
143 text = self.header_input.text.strip() 160 text = self.header_input.text.strip()
144 try: 161 try:
145 if text.count(u'@') != 1 or text.count(u' '): 162 if text.count(u'@') != 1 or text.count(u' '):
146 raise ValueError 163 raise ValueError
150 return 167 return
151 168
152 def discoCb(disco): 169 def discoCb(disco):
153 # TODO: check if plugin XEP-0045 is activated 170 # TODO: check if plugin XEP-0045 is activated
154 if "conference" in [i[0] for i in disco[1]]: 171 if "conference" in [i[0] for i in disco[1]]:
155 raise NotImplementedError(u"MUC not implemented yet") 172 G.host.bridge.mucJoin(unicode(jid_), "", "", self.profile, callback=self._mucJoinCb, errback=self._mucJoinEb)
156 # G.host.bridge.MUCJoin(unicode(jid_), "", "", self.profile)
157 else: 173 else:
158 plugin_info = G.host.getPluginInfo(main=Chat) 174 self.changeWidget(jid_)
159 factory = plugin_info['factory']
160 G.host.switchWidget(self, factory(plugin_info, jid_, profiles=[self.profile]))
161 self.header_input.text = ''
162 175
163 def discoEb(failure): 176 def discoEb(failure):
164 log.warning(u"Disco failure, ignore this text: {}".format(failure)) 177 log.warning(u"Disco failure, ignore this text: {}".format(failure))
165 178
166 G.host.bridge.discoInfos(jid_.domain, self.profile, callback=discoCb, errback=discoEb) 179 G.host.bridge.discoInfos(jid_.domain, self.profile, callback=discoCb, errback=discoEb)