diff frontends/src/quick_frontend/quick_chat.py @ 2007:19b9d3f8a6c7

plugin XEP-0085, quick_frontends, primitivus: chat states are working again
author Goffi <goffi@goffi.org>
date Sun, 17 Jul 2016 16:47:33 +0200
parents 981e2abbb56c
children b536dd121da1
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_chat.py	Fri Jul 15 22:13:09 2016 +0200
+++ b/frontends/src/quick_frontend/quick_chat.py	Sun Jul 17 16:47:33 2016 +0200
@@ -126,11 +126,22 @@
         self.affiliation = data['affiliation']
         self.role = data['role']
         self.widgets = set()  # widgets linked to this occupant
+        self._state = None
 
     @property
     def host(self):
         return self.parent.host
 
+    @property
+    def state(self):
+        return self._state
+
+    @state.setter
+    def state(self, new_state):
+        self._state = new_state
+        for w in self.widgets:
+            w.updated(["state"])
+
 
 class QuickChat(quick_widgets.QuickWidget):
 
@@ -407,5 +418,17 @@
         """
         raise NotImplementedError
 
+    ## events ##
+
+    def onChatState(self, from_jid, state, profile):
+        """A chat state has been received"""
+        if self.type == C.CHAT_GROUP:
+            nick = from_jid.resource
+            try:
+                self.occupants[nick].state = state
+            except KeyError:
+                log.warning(u"{nick} not found in {room}, ignoring new chat state".format(
+                    nick=nick, room=self.target.bare))
+
 
 quick_widgets.register(QuickChat)