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
5 changed files with 21 additions and 58 deletions
|
|
@ -226,19 +226,10 @@ class Chat(PrimitivusWidget, QuickChat):
|
||||||
self.chat_widget.header = urwid.AttrMap(self.subj_wid,'title')
|
self.chat_widget.header = urwid.AttrMap(self.subj_wid,'title')
|
||||||
self.host.redraw()
|
self.host.redraw()
|
||||||
|
|
||||||
def setPresents(self, nicks):
|
def addUser(self, param_nick):
|
||||||
"""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):
|
|
||||||
"""Add user if it is not in the group list"""
|
"""Add user if it is not in the group list"""
|
||||||
nick = unicode(param_nick) #FIXME: should be done in DBus bridge
|
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()
|
presents = self.present_wid.getAllValues()
|
||||||
if nick not in [present.value for present in presents]:
|
if nick not in [present.value for present in presents]:
|
||||||
presents.append(nick)
|
presents.append(nick)
|
||||||
|
|
@ -246,10 +237,10 @@ class Chat(PrimitivusWidget, QuickChat):
|
||||||
self.present_wid.changeValues(presents)
|
self.present_wid.changeValues(presents)
|
||||||
self.host.redraw()
|
self.host.redraw()
|
||||||
|
|
||||||
def removeUser(self, param_nick, show_info=True):
|
def removeUser(self, param_nick):
|
||||||
"""Remove a user from the group list"""
|
"""Remove a user from the group list"""
|
||||||
nick = unicode(param_nick) #FIXME: should be done in DBus bridge
|
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.present_wid.deleteValue(nick)
|
||||||
self.host.redraw()
|
self.host.redraw()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,10 +148,6 @@ class ContactList(PrimitivusWidget, QuickContactList):
|
||||||
self.update()
|
self.update()
|
||||||
self._emit('click', entity)
|
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):
|
def onNickUpdate(self, entity, new_nick, profile):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -534,10 +534,6 @@ class QuickApp(object):
|
||||||
chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile)
|
chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile)
|
||||||
chat_widget.setUserNick(user_nick)
|
chat_widget.setUserNick(user_nick)
|
||||||
chat_widget.id = room_jid # FIXME: to be removed
|
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)
|
self.contact_lists[profile].setSpecial(room_jid, C.CONTACT_SPECIAL_GROUP)
|
||||||
|
|
||||||
def roomLeftHandler(self, room_jid_s, profile):
|
def roomLeftHandler(self, room_jid_s, profile):
|
||||||
|
|
@ -553,7 +549,7 @@ class QuickApp(object):
|
||||||
"""Called when an user joined a MUC room"""
|
"""Called when an user joined a MUC room"""
|
||||||
room_jid = jid.JID(room_jid_s)
|
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 = 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})
|
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):
|
def roomUserLeftHandler(self, room_jid_s, user_nick, user_data, profile):
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,6 @@ class QuickChat(quick_widgets.QuickWidget):
|
||||||
self.type = type_
|
self.type = type_
|
||||||
self.id = "" # FIXME: to be removed
|
self.id = "" # FIXME: to be removed
|
||||||
self.nick = None
|
self.nick = None
|
||||||
self.occupants = set()
|
|
||||||
self.games = {}
|
self.games = {}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
@ -64,7 +63,6 @@ class QuickChat(quick_widgets.QuickWidget):
|
||||||
"""
|
"""
|
||||||
return (unicode(profile), target)
|
return (unicode(profile), target)
|
||||||
|
|
||||||
|
|
||||||
def addTarget(self, target):
|
def addTarget(self, target):
|
||||||
super(QuickChat, self).addTarget(target)
|
super(QuickChat, self).addTarget(target)
|
||||||
if target.resource:
|
if target.resource:
|
||||||
|
|
@ -76,6 +74,17 @@ class QuickChat(quick_widgets.QuickWidget):
|
||||||
return self.current_target.bare
|
return self.current_target.bare
|
||||||
return self.current_target
|
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):
|
def manageMessage(self, entity, mess_type):
|
||||||
"""Tell if this chat widget manage an entity and message type couple
|
"""Tell if this chat widget manage an entity and message type couple
|
||||||
|
|
||||||
|
|
@ -91,37 +100,13 @@ class QuickChat(quick_widgets.QuickWidget):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def setPresents(self, nicks):
|
def addUser(self, nick):
|
||||||
"""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):
|
|
||||||
"""Add user if it is not in the group list"""
|
"""Add user if it is not in the group list"""
|
||||||
log.debug (_("Replacing user %s") % nick)
|
self.printInfo("=> %s has joined the room" % 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)
|
|
||||||
|
|
||||||
def removeUser(self, nick, show_info=True):
|
def removeUser(self, nick):
|
||||||
"""Remove a user from the group list"""
|
"""Remove a user from the group list"""
|
||||||
log.debug(_("Removing user %s") % nick)
|
self.printInfo("<= %s has left the room" % 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)
|
|
||||||
|
|
||||||
def setUserNick(self, nick):
|
def setUserNick(self, nick):
|
||||||
"""Set the nick of the user, usefull for e.g. change the color of the user"""
|
"""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):
|
def changeUserNick(self, old_nick, new_nick):
|
||||||
"""Change nick of a user in group list"""
|
"""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))
|
self.printInfo("%s is now known as %s" % (old_nick, new_nick))
|
||||||
|
|
||||||
def setSubject(self, subject):
|
def setSubject(self, subject):
|
||||||
|
|
|
||||||
|
|
@ -403,6 +403,7 @@ class QuickContactList(QuickWidget):
|
||||||
|
|
||||||
priority_resource = max(resources_data, key=lambda res: resources_data[res][C.PRESENCE_PRIORITY])
|
priority_resource = max(resources_data, key=lambda res: resources_data[res][C.PRESENCE_PRIORITY])
|
||||||
cache[C.CONTACT_MAIN_RESOURCE] = priority_resource
|
cache[C.CONTACT_MAIN_RESOURCE] = priority_resource
|
||||||
|
self.update()
|
||||||
|
|
||||||
def onNickUpdate(self, entity, new_nick, profile):
|
def onNickUpdate(self, entity, new_nick, profile):
|
||||||
"""Update entity's nick
|
"""Update entity's nick
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue