comparison frontends/src/primitivus/chat.py @ 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 50d5d6325f62
comparison
equal deleted inserted replaced
1389:eb907923dce9 1390:337be5318177
185 values.append(self._buildOccupantMarkup(jid.newResource(self.target, nick))) 185 values.append(self._buildOccupantMarkup(jid.newResource(self.target, nick)))
186 self.occupants_list.changeValues(values) 186 self.occupants_list.changeValues(values)
187 else: # add, remove or update only one occupant 187 else: # add, remove or update only one occupant
188 nick = entity.resource 188 nick = entity.resource
189 show = contact_list.getCache(entity, C.PRESENCE_SHOW) 189 show = contact_list.getCache(entity, C.PRESENCE_SHOW)
190 if show == C.PRESENCE_UNAVAILABLE: 190 if show == C.PRESENCE_UNAVAILABLE or show is None:
191 self.occupants_list.deleteValue(nick) 191 self.occupants_list.deleteValue(nick)
192 else: 192 else:
193 values = self.occupants_list.getAllValues() 193 values = self.occupants_list.getAllValues()
194 markup = self._buildOccupantMarkup(entity)
194 if not values: # room has just been created 195 if not values: # room has just been created
195 self.occupants_list.changeValues([self._buildOccupantMarkup(entity)]) 196 values = [markup]
196 else: # add or update the occupant, keep the list sorted 197 else: # add or update the occupant, keep the list sorted
197 index = 0 198 index = 0
198 for entry in values: 199 for entry in values:
199 order = cmp(entry.value if hasattr(entry, 'value') else entry, nick) 200 order = cmp(entry.value if hasattr(entry, 'value') else entry, nick)
200 if order < 0: 201 if order < 0:
201 index += 1 202 index += 1
202 continue 203 continue
203 if order > 0: # insert the occupant the occupant 204 if order > 0: # insert the occupant
204 values.insert(index, self._buildOccupantMarkup(entity)) 205 values.insert(index, markup)
205 else: # update the occupant 206 else: # update an existing occupant
206 values[index] = self._buildOccupantMarkup(entity) 207 values[index] = markup
207 self.occupants_list.changeValues(values)
208 break 208 break
209 if index == len(values): # add to the end of the list
210 values.append(markup)
211 self.occupants_list.changeValues(values)
209 self.host.redraw() 212 self.host.redraw()
210 213
211 def _buildOccupantMarkup(self, entity): 214 def _buildOccupantMarkup(self, entity):
212 """Return the option attributes for a MUC occupant. 215 """Return the option attributes for a MUC occupant.
213 216
214 @param nick (unicode): occupant nickname 217 @param nick (unicode): occupant nickname
215 """ 218 """
219 # TODO: for now it's not a markup but a simple text, the problem is that ListOption is unicode and not urwid.Text
216 contact_list = self.host.contact_lists[self.profile] 220 contact_list = self.host.contact_lists[self.profile]
217 show = contact_list.getCache(entity, C.PRESENCE_SHOW) 221 show = contact_list.getCache(entity, C.PRESENCE_SHOW)
218 states = self.getEntityStates(entity) 222 states = self.getEntityStates(entity)
219 nick = entity.resource 223 nick = entity.resource
220 # TODO: use entity_attr and return (nick, markup), but ListOption is unicode and not urwid.Text 224 show_icon, entity_attr = C.PRESENCE.get(show, (u'', u'default')) # TODO: use entity_attr and return (nick, markup)
221 show_icon, entity_attr = C.PRESENCE.get(show, (u'', u'default'))
222 text = "%s%s %s" % (u''.join(states.values()), show_icon, nick) 225 text = "%s%s %s" % (u''.join(states.values()), show_icon, nick)
223 return (nick, text) 226 return (nick, text)
224 227
225 def _occupantsClicked(self, list_wid, clicked_wid): 228 def _occupantsClicked(self, list_wid, clicked_wid):
226 assert self.type == C.CHAT_GROUP 229 assert self.type == C.CHAT_GROUP