Mercurial > libervia-backend
changeset 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 | d44360763262 |
children | e22ab34c68f6 |
files | frontends/src/quick_frontend/quick_app.py frontends/src/quick_frontend/quick_contact_list.py |
diffstat | 2 files changed, 34 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py Fri Sep 09 23:54:33 2016 +0200 +++ b/frontends/src/quick_frontend/quick_app.py Fri Sep 09 23:54:33 2016 +0200 @@ -764,7 +764,10 @@ self.contact_lists[profile].setCache(entity, 'nick', value) self.callListeners('nick', entity, value, profile=profile) elif key == "avatar": - if value and entity in self.contact_lists[profile]: + if value: # and entity in self.contact_lists[profile]: + # FIXME: contact_list check is removed to work around 'avatar' issues + # (avatar can't be requested if we don't save them here) + # avatar need to be refactored properly in backend and here def gotFilename(filename): self.contact_lists[profile].setCache(entity, 'avatar', filename) self.callListeners('avatar', entity, filename, profile=profile)
--- a/frontends/src/quick_frontend/quick_contact_list.py Fri Sep 09 23:54:33 2016 +0200 +++ b/frontends/src/quick_frontend/quick_contact_list.py Fri Sep 09 23:54:33 2016 +0200 @@ -207,13 +207,14 @@ def getCache(self, entity, name=None): """Return a cache value for a contact - @param entity(entity.entity): entity of the contact from who we want data (resource is used if given) + @param entity(jid.JID): entity of the contact from who we want data (resource is used if given) if a resource specific information is requested: - if no resource is given (bare jid), the main resource is used, according to priority - if resource is given, it is used @param name(unicode): name the data to get, or None to get everything @return: full cache if no name is given, or value of "name", or None """ + # FIXME: resource handling need to be reworked try: cache = self._cache[entity.bare] except KeyError: @@ -222,19 +223,33 @@ if name is None: return cache - try: - if name in ('status', C.PRESENCE_STATUSES, C.PRESENCE_PRIORITY, C.PRESENCE_SHOW): - # these data are related to the resource - if not entity.resource: + + if name in ('status', C.PRESENCE_STATUSES, C.PRESENCE_PRIORITY, C.PRESENCE_SHOW): + # these data are related to the resource + if not entity.resource: + try: main_resource = cache[C.CONTACT_MAIN_RESOURCE] - cache = cache[C.CONTACT_RESOURCES][main_resource] - else: - cache = cache[C.CONTACT_RESOURCES][entity.resource] + except KeyError: + # we ignore presence info if we don't have any resource in cache + # FIXME: to be checked + return + cache = cache[C.CONTACT_RESOURCES].setdefault(main_resource, {}) + else: + cache = cache[C.CONTACT_RESOURCES].setdefault(entity.resource, {}) - if name == 'status': # XXX: we get the first status for 'status' key - # TODO: manage main language for statuses - return cache[C.PRESENCE_STATUSES].get(C.PRESENCE_STATUSES_DEFAULT, '') + if name == 'status': # XXX: we get the first status for 'status' key + # TODO: manage main language for statuses + return cache[C.PRESENCE_STATUSES].get(C.PRESENCE_STATUSES_DEFAULT, '') + elif entity.resource: + # if we have a resource, we first check if the value is not available for the resource + # and we fallback to main cache if not found + try: + return cache[C.CONTACT_RESOURCES][entity.resource][name] + except KeyError: + pass + + try: return cache[name] except KeyError: return None @@ -373,6 +388,10 @@ # now the attributes we keep in cache for attribute, value in attributes.iteritems(): + if attribute == 'avatar' and entity.resource: + # FIXME: Q&D hack to workaround avatar issue. + # TODO: Need to refactor avatar handling in backend and here + cache[C.CONTACT_RESOURCES].setdefault(entity.resource, {})[attribute] = value cache[attribute] = value # we can update the display