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
This commit is contained in:
Goffi 2012-09-28 00:26:24 +02:00
commit c520325941
2 changed files with 145 additions and 50 deletions

View file

@ -57,8 +57,10 @@ class QuickApp():
self.bridge.register("actionResult", self.actionResult)
self.bridge.register("actionResultExt", self.actionResult)
self.bridge.register("roomJoined", self.roomJoined, "plugin")
self.bridge.register("roomLeft", self.roomLeft, "plugin")
self.bridge.register("roomUserJoined", self.roomUserJoined, "plugin")
self.bridge.register("roomUserLeft", self.roomUserLeft, "plugin")
self.bridge.register("roomUserChangedNick", self.roomUserChangedNick, "plugin")
self.bridge.register("roomNewSubject", self.roomNewSubject, "plugin")
self.bridge.register("tarotGameStarted", self.tarotGameStarted, "plugin")
self.bridge.register("tarotGameNew", self.tarotGameNew, "plugin")
@ -290,6 +292,13 @@ class QuickApp():
self.chat_wins[room_jid].setPresents(list(set([user_nick]+room_nicks)))
self.contact_list.setSpecial(JID(room_jid), "MUC")
def roomLeft(self, room_jid, profile):
"""Called when a MUC room is left"""
if not self.check_profile(profile):
return
debug (_("Room [%(room_jid)s] left by %(profile)s") % {'room_jid':room_jid, 'profile': profile})
del self.chat_wins[room_jid]
self.contact_list.remove(room_jid)
def roomUserJoined(self, room_jid, user_nick, user_data, profile):
"""Called when an user joined a MUC room"""
@ -307,6 +316,14 @@ class QuickApp():
self.chat_wins[room_jid].removeUser(user_nick)
debug (_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid})
def roomUserChangedNick(self, room_jid, old_nick, new_nick, profile):
"""Called when an user joined a MUC room"""
if not self.check_profile(profile):
return
if self.chat_wins.has_key(room_jid):
self.chat_wins[room_jid].changeUserNick(old_nick, new_nick)
debug (_("user [%(old_nick)s] is now known as [%(new_nick)s] in room [%(room_jid)s]") % {'old_nick':old_nick, 'new_nick':new_nick, 'room_jid':room_jid})
def roomNewSubject(self, room_jid, subject, profile):
"""Called when subject of MUC room change"""
if not self.check_profile(profile):

View file

@ -50,7 +50,7 @@ class QuickChat():
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 @@ class QuickChat():
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 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):
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)
self.printInfo("<= %s has left the room" % 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 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 change user nick for a non group chat window"))
raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
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"""