Mercurial > libervia-backend
changeset 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 | 28fd9e838f8f |
children | 3dae6964c071 |
files | frontends/src/primitivus/chat.py frontends/src/primitivus/contact_list.py frontends/src/quick_frontend/quick_app.py frontends/src/quick_frontend/quick_chat.py frontends/src/quick_frontend/quick_contact_list.py |
diffstat | 5 files changed, 21 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/chat.py Thu Mar 19 20:40:10 2015 +0100 +++ b/frontends/src/primitivus/chat.py Fri Mar 20 16:25:38 2015 +0100 @@ -226,19 +226,10 @@ self.chat_widget.header = urwid.AttrMap(self.subj_wid,'title') self.host.redraw() - def setPresents(self, nicks): - """Set the occupants of a group chat. - - @param nicks (list[unicode]): sorted list of nicknames - """ - QuickChat.setPresents(self, nicks) - self.present_wid.changeValues(nicks) - self.host.redraw() - - def replaceUser(self, param_nick, show_info=True): + def addUser(self, param_nick): """Add user if it is not in the group list""" nick = unicode(param_nick) #FIXME: should be done in DBus bridge - QuickChat.replaceUser(self, nick, show_info) + QuickChat.addUser(self, nick) presents = self.present_wid.getAllValues() if nick not in [present.value for present in presents]: presents.append(nick) @@ -246,10 +237,10 @@ self.present_wid.changeValues(presents) self.host.redraw() - def removeUser(self, param_nick, show_info=True): + def removeUser(self, param_nick): """Remove a user from the group list""" nick = unicode(param_nick) #FIXME: should be done in DBus bridge - QuickChat.removeUser(self, nick, show_info) + QuickChat.removeUser(self, nick) self.present_wid.deleteValue(nick) self.host.redraw()
--- a/frontends/src/primitivus/contact_list.py Thu Mar 19 20:40:10 2015 +0100 +++ b/frontends/src/primitivus/contact_list.py Fri Mar 20 16:25:38 2015 +0100 @@ -148,10 +148,6 @@ self.update() self._emit('click', entity) - def onPresenceUpdate(self, entity, show, priority, statuses, profile): - super(ContactList, self).onPresenceUpdate(entity, show, priority, statuses, profile) - self.update() - def onNickUpdate(self, entity, new_nick, profile): self.update()
--- a/frontends/src/quick_frontend/quick_app.py Thu Mar 19 20:40:10 2015 +0100 +++ b/frontends/src/quick_frontend/quick_app.py Fri Mar 20 16:25:38 2015 +0100 @@ -534,10 +534,6 @@ chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) chat_widget.setUserNick(user_nick) chat_widget.id = room_jid # FIXME: to be removed - room_nicks = [unicode(nick) for nick in room_nicks] # FIXME: should be done in DBus bridge / is that still needed?! - nicks = list(set([user_nick] + room_nicks)) - nicks.sort() - chat_widget.setPresents(nicks) self.contact_lists[profile].setSpecial(room_jid, C.CONTACT_SPECIAL_GROUP) def roomLeftHandler(self, room_jid_s, profile): @@ -553,7 +549,7 @@ """Called when an user joined a MUC room""" room_jid = jid.JID(room_jid_s) chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) - chat_widget.replaceUser(user_nick) + chat_widget.addUser(user_nick) log.debug("user [%(user_nick)s] joined room [%(room_jid)s]" % {'user_nick': user_nick, 'room_jid': room_jid}) def roomUserLeftHandler(self, room_jid_s, user_nick, user_data, profile):
--- 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):
--- a/frontends/src/quick_frontend/quick_contact_list.py Thu Mar 19 20:40:10 2015 +0100 +++ b/frontends/src/quick_frontend/quick_contact_list.py Fri Mar 20 16:25:38 2015 +0100 @@ -403,6 +403,7 @@ priority_resource = max(resources_data, key=lambda res: resources_data[res][C.PRESENCE_PRIORITY]) cache[C.CONTACT_MAIN_RESOURCE] = priority_resource + self.update() def onNickUpdate(self, entity, new_nick, profile): """Update entity's nick