diff frontends/src/quick_frontend/quick_chat.py @ 507:f98bef71a918

frontends, core, plugin XEP-0045: leave implementation + better nick change - memory: individual entity cache can be deleted - plugin XEP-0045: nick change are now detected and userChangedNick signal is sent instead of joined/left - plugin XEP-0045: leave implementation - frontends: userChangedNick signal management - Primitivus: an alert is shown in notification bar in case of error in sendMessage
author Goffi <goffi@goffi.org>
date Fri, 28 Sep 2012 00:26:24 +0200
parents e9634d2e7b38
children 886754295efe
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_chat.py	Thu Sep 27 00:54:42 2012 +0200
+++ b/frontends/src/quick_frontend/quick_chat.py	Fri Sep 28 00:26:24 2012 +0200
@@ -50,7 +50,7 @@
             raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
         self.occupants.update(nicks)
     
-    def replaceUser(self, nick):
+    def replaceUser(self, nick, show_info=True):
         """Add user if it is not in the group list"""
         debug (_("Replacing user %s") % nick)
         if self.type != "group":
@@ -58,24 +58,35 @@
             raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
         len_before = len(self.occupants)
         self.occupants.add(nick)
-        if len_before != len(self.occupants):
+        if len_before != len(self.occupants) and show_info:
             self.printInfo("=> %s has joined the room" % nick)
-    
+
+    def removeUser(self, nick, show_info=True):
+        """Remove a user from the group list"""
+        debug(_("Removing user %s") % nick)
+        if self.type != "group":
+            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)
+        if show_info:
+            self.printInfo("<= %s has left the room" % nick)
+
     def setUserNick(self, nick):
         """Set the nick of the user, usefull for e.g. change the color of the user"""
         self.nick = nick
 
     def getUserNick(self):
         return unicode(self.nick)
-
-    def removeUser(self, nick):
-        """Remove a user from the group list"""
-        debug(_("Removing user %s") % nick)
+    
+    def changeUserNick(self, old_nick, new_nick):
+        """Change nick of a user in group list"""
+        debug(_("Changing nick of user %(old_nick)s to %(new_nick)s") % {"old_nick": old_nick, "new_nick": new_nick})
         if self.type != "group":
-            error (_("[INTERNAL] trying to remove user for a non group chat window"))
+            error (_("[INTERNAL] trying to change user nick 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)
+        self.removeUser(old_nick, show_info=False)
+        self.replaceUser(new_nick, show_info=False)
+        self.printInfo("%s is now known as %s" % (old_nick, new_nick))
 
     def setSubject(self, subject):
         """Set title for a group chat"""