comparison frontends/src/quick_frontend/quick_app.py @ 1336:2ecc07a8f91b frontends_multi_profiles

primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
author Goffi <goffi@goffi.org>
date Mon, 23 Feb 2015 18:04:25 +0100
parents 781ee3539252
children f29beedb33b0
comparison
equal deleted inserted replaced
1335:2c6c93438f74 1336:2ecc07a8f91b
209 sys.exit(1) 209 sys.exit(1)
210 ProfileManager.bridge = self.bridge 210 ProfileManager.bridge = self.bridge
211 self.registerSignal("connected") 211 self.registerSignal("connected")
212 self.registerSignal("disconnected") 212 self.registerSignal("disconnected")
213 self.registerSignal("newContact") 213 self.registerSignal("newContact")
214 self.registerSignal("newMessage", self._newMessage) 214 self.registerSignal("newMessage")
215 self.registerSignal("newAlert") 215 self.registerSignal("newAlert")
216 self.registerSignal("presenceUpdate") 216 self.registerSignal("presenceUpdate")
217 self.registerSignal("subscribe") 217 self.registerSignal("subscribe")
218 self.registerSignal("paramUpdate") 218 self.registerSignal("paramUpdate")
219 self.registerSignal("contactDeleted") 219 self.registerSignal("contactDeleted")
404 def newContactHandler(self, JabberId, attributes, groups, profile): 404 def newContactHandler(self, JabberId, attributes, groups, profile):
405 entity = jid.JID(JabberId) 405 entity = jid.JID(JabberId)
406 _groups = list(groups) 406 _groups = list(groups)
407 self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True) 407 self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True)
408 408
409 def _newMessage(self, from_jid_s, msg, type_, to_jid_s, extra, profile): 409 def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile):
410 from_jid = jid.JID(from_jid_s) 410 from_jid = jid.JID(from_jid_s)
411 to_jid = jid.JID(to_jid_s) 411 to_jid = jid.JID(to_jid_s)
412 self.newMessageHandler(from_jid, to_jid, msg, type_, extra, profile)
413
414 def newMessageHandler(self, from_jid, to_jid, msg, type_, extra, profile):
415 from_me = from_jid.bare == self.profiles[profile].whoami.bare 412 from_me = from_jid.bare == self.profiles[profile].whoami.bare
416 target = to_jid if from_me else from_jid 413 target = to_jid if from_me else from_jid
417 414
418 chat_type = C.CHAT_GROUP if type_ == C.MESS_TYPE_GROUPCHAT else C.CHAT_ONE2ONE 415 chat_type = C.CHAT_GROUP if type_ == C.MESS_TYPE_GROUPCHAT else C.CHAT_ONE2ONE
419 416 contact_list = self.contact_lists[profile]
420 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=chat_type, profile=profile) 417
418 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=chat_type, on_new_widget=None, profile=profile)
421 419
422 self.current_action_ids = set() # FIXME: to be removed 420 self.current_action_ids = set() # FIXME: to be removed
423 self.current_action_ids_cb = {} # FIXME: to be removed 421 self.current_action_ids_cb = {} # FIXME: to be removed
424 422
423 if not from_jid in contact_list and from_jid.bare != self.profiles[profile].whoami.bare:
424 #XXX: needed to show entities which haven't sent any
425 # presence information and which are not in roster
426 contact_list.setContact(from_jid)
427
428 # we display the message in the widget
425 chat_widget.newMessage(from_jid, target, msg, type_, extra, profile) 429 chat_widget.newMessage(from_jid, target, msg, type_, extra, profile)
430
431 # ContactList alert
432 visible = False
433 for widget in self.visible_widgets:
434 if isinstance(widget, quick_chat.QuickChat) and widget.manageMessage(from_jid, type_):
435 visible = True
436 break
437 if not visible:
438 contact_list.setAlert(from_jid.bare if type_ == C.MESS_TYPE_GROUPCHAT else from_jid)
426 439
427 def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, callback=None, errback=None, profile_key=C.PROF_KEY_NONE): 440 def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, callback=None, errback=None, profile_key=C.PROF_KEY_NONE):
428 if callback is None: 441 if callback is None:
429 callback = lambda dummy=None: None # FIXME: optional argument is here because pyjamas doesn't support callback without arg with json proxy 442 callback = lambda dummy=None: None # FIXME: optional argument is here because pyjamas doesn't support callback without arg with json proxy
430 if errback is None: 443 if errback is None: