diff frontends/quick_frontend/quick_chat.py @ 190:31632472e857

quick_frontend, wix, primitivus: informations in chat window - user joined/left information - messages starting with /me are managed
author Goffi <goffi@goffi.org>
date Wed, 18 Aug 2010 21:42:30 +0800
parents 80661755ea8d
children 9face609f83c
line wrap: on
line diff
--- a/frontends/quick_frontend/quick_chat.py	Wed Aug 18 20:50:45 2010 +0800
+++ b/frontends/quick_frontend/quick_chat.py	Wed Aug 18 21:42:30 2010 +0800
@@ -56,7 +56,10 @@
         if self.type != "group":
             error (_("[INTERNAL] trying to replace user for a non group chat window"))
             raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
+        len_before = len(self.occupants)
         self.occupants.add(nick)
+        if len_before != len(self.occupants):
+            self.printInfo("=> %s has joined the room" % nick)
     
     def setUserNick(self, nick):
         """Set the nick of the user, usefull for e.g. change the color of the user"""
@@ -69,6 +72,7 @@
             error (_("[INTERNAL] trying to remove user for a non group chat window"))
             raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
         self.occupants.remove(nick)
+        self.printInfo("=> %s has left the room" % nick)
 
     def setSubject(self, subject):
         """Set title for a group chat"""
@@ -88,9 +92,29 @@
         if keep_last:  ##FIXME hack for sortilege
             self.last_history = stamps[-1] if stamps else None
 
+    def _get_nick(self, jid):
+        """Return nick of this jid when possible"""
+        return jid.resource if self.type == "group" else (self.host.CM.getAttr(jid,'nick') or self.host.CM.getAttr(jid,'name') or jid.node)
+    
     def printMessage(self, from_jid, msg, profile, timestamp):
         """Print message in chat window. Must be implemented by child class"""
+        jid=JID(from_jid)
+        nick = self._get_nick(jid) 
+        mymess = (jid.resource == self.nick) if self.type == "group" else (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user
+        if msg.startswith('/me '):
+            self.printInfo('* %s %s' % (nick, msg[4:]),type='me')
+            return
+        return jid, nick, mymess
+
+    def printInfo(self, msg, type='normal'):
+        """Print general info
+        @param msg: message to print
+        @type: one of:
+            normal: general info like "toto has joined the room"
+            me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
+        """
         raise NotImplementedError
+
     
     def startGame(self, game_type, referee, players):
         """Configure the chat window to start a game"""