Mercurial > libervia-backend
changeset 1390:337be5318177
primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 25 Mar 2015 10:09:59 +0100 |
parents | eb907923dce9 |
children | 1276e6a0716b |
files | frontends/src/primitivus/chat.py |
diffstat | 1 files changed, 12 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/chat.py Wed Mar 25 09:42:05 2015 +0100 +++ b/frontends/src/primitivus/chat.py Wed Mar 25 10:09:59 2015 +0100 @@ -187,12 +187,13 @@ else: # add, remove or update only one occupant nick = entity.resource show = contact_list.getCache(entity, C.PRESENCE_SHOW) - if show == C.PRESENCE_UNAVAILABLE: + if show == C.PRESENCE_UNAVAILABLE or show is None: self.occupants_list.deleteValue(nick) else: values = self.occupants_list.getAllValues() + markup = self._buildOccupantMarkup(entity) if not values: # room has just been created - self.occupants_list.changeValues([self._buildOccupantMarkup(entity)]) + values = [markup] else: # add or update the occupant, keep the list sorted index = 0 for entry in values: @@ -200,12 +201,14 @@ if order < 0: index += 1 continue - if order > 0: # insert the occupant the occupant - values.insert(index, self._buildOccupantMarkup(entity)) - else: # update the occupant - values[index] = self._buildOccupantMarkup(entity) - self.occupants_list.changeValues(values) + if order > 0: # insert the occupant + values.insert(index, markup) + else: # update an existing occupant + values[index] = markup break + if index == len(values): # add to the end of the list + values.append(markup) + self.occupants_list.changeValues(values) self.host.redraw() def _buildOccupantMarkup(self, entity): @@ -213,12 +216,12 @@ @param nick (unicode): occupant nickname """ + # TODO: for now it's not a markup but a simple text, the problem is that ListOption is unicode and not urwid.Text contact_list = self.host.contact_lists[self.profile] show = contact_list.getCache(entity, C.PRESENCE_SHOW) states = self.getEntityStates(entity) nick = entity.resource - # TODO: use entity_attr and return (nick, markup), but ListOption is unicode and not urwid.Text - show_icon, entity_attr = C.PRESENCE.get(show, (u'', u'default')) + show_icon, entity_attr = C.PRESENCE.get(show, (u'', u'default')) # TODO: use entity_attr and return (nick, markup) text = "%s%s %s" % (u''.join(states.values()), show_icon, nick) return (nick, text)