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
This commit is contained in:
parent
c2314640ba
commit
c6419871ac
1 changed files with 21 additions and 58 deletions
|
|
@ -46,7 +46,6 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
self.type = type_
|
||||
self.id = "" # FIXME: to be removed
|
||||
self.nick = None
|
||||
self.occupants = set()
|
||||
self.games = {}
|
||||
|
||||
def __str__(self):
|
||||
|
|
@ -64,7 +63,6 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
"""
|
||||
return (unicode(profile), target)
|
||||
|
||||
|
||||
def addTarget(self, target):
|
||||
super(QuickChat, self).addTarget(target)
|
||||
if target.resource:
|
||||
|
|
@ -76,6 +74,17 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
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 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
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 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
|
||||
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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue