primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
This commit is contained in:
parent
e81c92c549
commit
30f1169e22
1 changed files with 12 additions and 9 deletions
|
|
@ -187,12 +187,13 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
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 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
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 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
|
||||
@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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue