diff frontends/src/quick_frontend/quick_app.py @ 1378:3dae6964c071

quick_frontends, primitivus: move the chat states logic to quick_frontend
author souliane <souliane@mailoo.org>
date Fri, 20 Mar 2015 16:28:19 +0100
parents 017270e6eea4
children 8aa32bcc3a9c
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py	Fri Mar 20 16:25:38 2015 +0100
+++ b/frontends/src/quick_frontend/quick_app.py	Fri Mar 20 16:28:19 2015 +0100
@@ -574,16 +574,22 @@
         log.debug("new subject for room [%(room_jid)s]: %(subject)s" % {'room_jid': room_jid, "subject": subject})
 
     def chatStateReceivedHandler(self, from_jid_s, state, profile):
-        """Called when a new chat state is received.
+        """Called when a new chat state (XEP-0085) is received.
 
-        @param from_jid_s: JID of the contact who sent his state, or '@ALL@'
-        @param state: new state (string)
-        @profile: current profile
+        @param from_jid_s (unicode): JID of a contact or C.ENTITY_ALL
+        @param state (unicode): new state
+        @param profile (unicode): current profile
         """
         from_jid = jid.JID(from_jid_s) if from_jid_s != C.ENTITY_ALL else C.ENTITY_ALL
         for widget in self.widgets.getWidgets(quick_chat.QuickChat):
-            if from_jid == C.ENTITY_ALL or from_jid.bare == widget.target.bare:
-                widget.updateChatState(from_jid, state)
+            if profile != widget.profile:
+                continue
+            to_display = C.USER_CHAT_STATES[state] if (state and widget.type == C.CHAT_GROUP) else state
+            if widget.type == C.CHAT_GROUP and from_jid_s == C.ENTITY_ALL:
+                for occupant in [jid.newResource(self.target, nick) for nick in widget.occupants]:
+                    widget.updateEntityState(occupant, 'chat_state', to_display)
+            elif from_jid.bare == widget.target.bare:  # roster contact or MUC occupant
+                widget.updateEntityState(from_jid, 'chat_state', to_display)
 
     def personalEventHandler(self, sender, event_type, data):
         """Called when a PEP event is received.