# HG changeset patch # User souliane # Date 1427274599 -3600 # Node ID 337be531817759fd8b9e895e5d45439c1248a54c # Parent eb907923dce9cf62bd042a4ed8af9a06609d4846 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position diff -r eb907923dce9 -r 337be5318177 frontends/src/primitivus/chat.py --- 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)