Mercurial > libervia-backend
diff frontends/src/quick_frontend/quick_chat.py @ 1377:017270e6eea4
quick_frontends, primitivus: know who are the MUC occupants from the presence informations:
- QuickChat.occupants is now a property using cached information
- some MUC handlers are no more needed, the presence handler is enough
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 20 Mar 2015 16:25:38 +0100 |
parents | ba87b940f07a |
children | 3dae6964c071 |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_chat.py Thu Mar 19 20:40:10 2015 +0100 +++ b/frontends/src/quick_frontend/quick_chat.py Fri Mar 20 16:25:38 2015 +0100 @@ -46,7 +46,6 @@ self.type = type_ self.id = "" # FIXME: to be removed self.nick = None - self.occupants = set() self.games = {} def __str__(self): @@ -64,7 +63,6 @@ """ return (unicode(profile), target) - def addTarget(self, target): super(QuickChat, self).addTarget(target) if target.resource: @@ -76,6 +74,17 @@ return self.current_target.bare return self.current_target + @property + def occupants(self): + """Return the occupants of a group chat (nicknames). + + @return: set(unicode) + """ + if self.type != C.CHAT_GROUP: + return set() + contact_list = self.host.contact_lists[self.profile] + return contact_list.getCache(self.target, C.CONTACT_RESOURCES).keys() + def manageMessage(self, entity, mess_type): """Tell if this chat widget manage an entity and message type couple @@ -91,37 +100,13 @@ return True return False - def setPresents(self, nicks): - """Set the occupants of a group chat. - - @param nicks (list[unicode]): sorted list of nicknames - """ - log.debug(_("Adding users %s to room") % nicks) - if self.type != C.CHAT_GROUP: - log.error(_("[INTERNAL] trying to set presents nicks for a non group chat window")) - raise Exception("INTERNAL ERROR") # TODO: raise proper Exception here - self.occupants.update(nicks) - - def replaceUser(self, nick, show_info=True): + def addUser(self, nick): """Add user if it is not in the group list""" - log.debug (_("Replacing user %s") % nick) - if self.type != C.CHAT_GROUP: - log.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) and show_info: - self.printInfo("=> %s has joined the room" % nick) + self.printInfo("=> %s has joined the room" % nick) - def removeUser(self, nick, show_info=True): + def removeUser(self, nick): """Remove a user from the group list""" - log.debug(_("Removing user %s") % nick) - if self.type != C.CHAT_GROUP: - log.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) + 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""" @@ -132,12 +117,6 @@ def changeUserNick(self, old_nick, new_nick): """Change nick of a user in group list""" - log.debug(_("Changing nick of user %(old_nick)s to %(new_nick)s") % {"old_nick": old_nick, "new_nick": new_nick}) - if self.type != C.CHAT_GROUP: - log.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):