Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_contact_list.py @ 2061:748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 09 Sep 2016 23:54:33 +0200 |
parents | d941fa9954f4 |
children | f3167c873e7b |
comparison
equal
deleted
inserted
replaced
2060:d44360763262 | 2061:748e539c5feb |
---|---|
205 handler.fill(self.profile) | 205 handler.fill(self.profile) |
206 | 206 |
207 def getCache(self, entity, name=None): | 207 def getCache(self, entity, name=None): |
208 """Return a cache value for a contact | 208 """Return a cache value for a contact |
209 | 209 |
210 @param entity(entity.entity): entity of the contact from who we want data (resource is used if given) | 210 @param entity(jid.JID): entity of the contact from who we want data (resource is used if given) |
211 if a resource specific information is requested: | 211 if a resource specific information is requested: |
212 - if no resource is given (bare jid), the main resource is used, according to priority | 212 - if no resource is given (bare jid), the main resource is used, according to priority |
213 - if resource is given, it is used | 213 - if resource is given, it is used |
214 @param name(unicode): name the data to get, or None to get everything | 214 @param name(unicode): name the data to get, or None to get everything |
215 @return: full cache if no name is given, or value of "name", or None | 215 @return: full cache if no name is given, or value of "name", or None |
216 """ | 216 """ |
217 # FIXME: resource handling need to be reworked | |
217 try: | 218 try: |
218 cache = self._cache[entity.bare] | 219 cache = self._cache[entity.bare] |
219 except KeyError: | 220 except KeyError: |
220 self.setContact(entity) | 221 self.setContact(entity) |
221 cache = self._cache[entity.bare] | 222 cache = self._cache[entity.bare] |
222 | 223 |
223 if name is None: | 224 if name is None: |
224 return cache | 225 return cache |
226 | |
227 if name in ('status', C.PRESENCE_STATUSES, C.PRESENCE_PRIORITY, C.PRESENCE_SHOW): | |
228 # these data are related to the resource | |
229 if not entity.resource: | |
230 try: | |
231 main_resource = cache[C.CONTACT_MAIN_RESOURCE] | |
232 except KeyError: | |
233 # we ignore presence info if we don't have any resource in cache | |
234 # FIXME: to be checked | |
235 return | |
236 cache = cache[C.CONTACT_RESOURCES].setdefault(main_resource, {}) | |
237 else: | |
238 cache = cache[C.CONTACT_RESOURCES].setdefault(entity.resource, {}) | |
239 | |
240 if name == 'status': # XXX: we get the first status for 'status' key | |
241 # TODO: manage main language for statuses | |
242 return cache[C.PRESENCE_STATUSES].get(C.PRESENCE_STATUSES_DEFAULT, '') | |
243 | |
244 elif entity.resource: | |
245 # if we have a resource, we first check if the value is not available for the resource | |
246 # and we fallback to main cache if not found | |
247 try: | |
248 return cache[C.CONTACT_RESOURCES][entity.resource][name] | |
249 except KeyError: | |
250 pass | |
251 | |
225 try: | 252 try: |
226 if name in ('status', C.PRESENCE_STATUSES, C.PRESENCE_PRIORITY, C.PRESENCE_SHOW): | |
227 # these data are related to the resource | |
228 if not entity.resource: | |
229 main_resource = cache[C.CONTACT_MAIN_RESOURCE] | |
230 cache = cache[C.CONTACT_RESOURCES][main_resource] | |
231 else: | |
232 cache = cache[C.CONTACT_RESOURCES][entity.resource] | |
233 | |
234 if name == 'status': # XXX: we get the first status for 'status' key | |
235 # TODO: manage main language for statuses | |
236 return cache[C.PRESENCE_STATUSES].get(C.PRESENCE_STATUSES_DEFAULT, '') | |
237 | |
238 return cache[name] | 253 return cache[name] |
239 except KeyError: | 254 except KeyError: |
240 return None | 255 return None |
241 | 256 |
242 def setCache(self, entity, name, value): | 257 def setCache(self, entity, name, value): |
371 self._specials.add(entity) | 386 self._specials.add(entity) |
372 cache[C.CONTACT_MAIN_RESOURCE] = None | 387 cache[C.CONTACT_MAIN_RESOURCE] = None |
373 | 388 |
374 # now the attributes we keep in cache | 389 # now the attributes we keep in cache |
375 for attribute, value in attributes.iteritems(): | 390 for attribute, value in attributes.iteritems(): |
391 if attribute == 'avatar' and entity.resource: | |
392 # FIXME: Q&D hack to workaround avatar issue. | |
393 # TODO: Need to refactor avatar handling in backend and here | |
394 cache[C.CONTACT_RESOURCES].setdefault(entity.resource, {})[attribute] = value | |
376 cache[attribute] = value | 395 cache[attribute] = value |
377 | 396 |
378 # we can update the display | 397 # we can update the display |
379 self.update([entity], update_type, self.profile) | 398 self.update([entity], update_type, self.profile) |
380 | 399 |