diff 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
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Mon Feb 23 18:04:25 2015 +0100
+++ b/frontends/src/quick_frontend/quick_app.py	Mon Feb 23 18:04:25 2015 +0100
@@ -211,7 +211,7 @@
         self.registerSignal("connected")
         self.registerSignal("disconnected")
         self.registerSignal("newContact")
-        self.registerSignal("newMessage", self._newMessage)
+        self.registerSignal("newMessage")
         self.registerSignal("newAlert")
         self.registerSignal("presenceUpdate")
         self.registerSignal("subscribe")
@@ -406,24 +406,37 @@
         _groups = list(groups)
         self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True)
 
-    def _newMessage(self, from_jid_s, msg, type_, to_jid_s, extra, profile):
+    def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile):
         from_jid = jid.JID(from_jid_s)
         to_jid = jid.JID(to_jid_s)
-        self.newMessageHandler(from_jid, to_jid, msg, type_, extra, profile)
-
-    def newMessageHandler(self, from_jid, to_jid, msg, type_, extra, profile):
         from_me = from_jid.bare == self.profiles[profile].whoami.bare
         target = to_jid if from_me else from_jid
 
         chat_type = C.CHAT_GROUP if type_ == C.MESS_TYPE_GROUPCHAT else C.CHAT_ONE2ONE
+        contact_list = self.contact_lists[profile]
 
-        chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=chat_type, profile=profile)
+        chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=chat_type, on_new_widget=None, profile=profile)
 
         self.current_action_ids = set() # FIXME: to be removed
         self.current_action_ids_cb = {} # FIXME: to be removed
 
+        if not from_jid in contact_list and from_jid.bare != self.profiles[profile].whoami.bare:
+            #XXX: needed to show entities which haven't sent any
+            #     presence information and which are not in roster
+            contact_list.setContact(from_jid)
+
+        # we display the message in the widget
         chat_widget.newMessage(from_jid, target, msg, type_, extra, profile)
 
+        # ContactList alert
+        visible = False
+        for widget in self.visible_widgets:
+            if isinstance(widget, quick_chat.QuickChat) and widget.manageMessage(from_jid, type_):
+                visible = True
+                break
+        if not visible:
+            contact_list.setAlert(from_jid.bare if type_ == C.MESS_TYPE_GROUPCHAT else from_jid)
+
     def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, callback=None, errback=None, profile_key=C.PROF_KEY_NONE):
         if callback is None:
             callback = lambda dummy=None: None # FIXME: optional argument is here because pyjamas doesn't support callback without arg with json proxy