From f992739212ad374476d750b694199bc92284412c Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 9 Sep 2016 23:54:33 +0200 Subject: [PATCH] quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO) --- frontends/src/quick_frontend/quick_app.py | 5 ++- .../src/quick_frontend/quick_contact_list.py | 41 ++++++++++++++----- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/frontends/src/quick_frontend/quick_app.py b/frontends/src/quick_frontend/quick_app.py index 383d8d6b..f7dfbfd1 100644 --- a/frontends/src/quick_frontend/quick_app.py +++ b/frontends/src/quick_frontend/quick_app.py @@ -764,7 +764,10 @@ class QuickApp(object): 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) diff --git a/frontends/src/quick_frontend/quick_contact_list.py b/frontends/src/quick_frontend/quick_contact_list.py index fff684d3..5e4cdce6 100644 --- a/frontends/src/quick_frontend/quick_contact_list.py +++ b/frontends/src/quick_frontend/quick_contact_list.py @@ -207,13 +207,14 @@ class ProfileContactList(object): 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 @@ class ProfileContactList(object): 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 @@ class ProfileContactList(object): # 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