# HG changeset patch # User Goffi # Date 1496521624 -7200 # Node ID 67a59552f3e3542c603d8bd297f30273bb73b7fc # Parent 36e9747520fd5b52251b8b5549e36f932d3f62f3 server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache diff -r 36e9747520fd -r 67a59552f3e3 src/server/blog.py --- a/src/server/blog.py Tue May 23 00:06:03 2017 +0200 +++ b/src/server/blog.py Sat Jun 03 22:27:04 2017 +0200 @@ -45,10 +45,10 @@ PARAMS_TO_GET = (C.STATIC_BLOG_PARAM_TITLE, C.STATIC_BLOG_PARAM_BANNER, C.STATIC_BLOG_PARAM_KEYWORDS, C.STATIC_BLOG_PARAM_DESCRIPTION) re_strip_empty_div = re.compile(r"
|
*?
") -# TODO: chech disco features and use max_items when RSM is not available -# FIXME: Deferred are not used +# TODO: check disco features and use max_items when RSM is not available # FIXME: change navigation links handling, this is is fragile -# TODO: refactorise this +# XXX: this page will disappear, LiberviaPage will be used instead +# TODO: delete this page and create a compatibility page for links def getDefaultQueryData(request): @@ -122,30 +122,16 @@ self.host = host Resource.__init__(self) TemplateProcessor.__init__(self, host) - self.host.bridge.register_signal('entityDataUpdated', self.entityDataUpdatedHandler) self.avatars_cache = {} - self.waiting_deferreds = {} - - def entityDataUpdatedHandler(self, entity_s, key, value, dummy): - """Retrieve the avatar we've been waiting for and fires the callback. - @param entity_s (str): JID of the contact - @param key (str): entity data key - @param value (str): entity data value - @param dummy (str): that would be C.SERVICE_PROFILE - """ - if key != "avatar": - return - log.debug(_(u"Received a new avatar for entity %s") % entity_s) + def _avatarPathToUrl(self, avatar, request, bare_jid_s): + filename = os.path.basename(avatar) + avatar_url = os.path.join(self.host.service_cache_url, filename) + self.avatars_cache[bare_jid_s] = avatar_url + return avatar_url - url = os.path.join(C.AVATARS_DIR, value) if value else "" - self.avatars_cache[entity_s] = url - try: - self.waiting_deferreds.pop(entity_s).callback(url) - except KeyError: - pass - def getAvatarURL(self, pub_jid): + def getAvatarURL(self, pub_jid, request): """Return avatar of a jid if in cache, else ask for it. @param pub_jid (JID): publisher JID @@ -156,10 +142,8 @@ url = self.avatars_cache[bare_jid_s] except KeyError: self.avatars_cache[bare_jid_s] = '' # avoid to request the vcard several times - # self.host.bridge.getCard(bare_jid_s, C.SERVICE_PROFILE) - self.host.bridge.avatarGet(bare_jid_s, True, True, C.SERVICE_PROFILE) - d = defer.Deferred() - self.waiting_deferreds[bare_jid_s] = d + d = self.host.bridgeCall('avatarGet', bare_jid_s, False, False, C.SERVICE_PROFILE) + d.addCallback(self._avatarPathToUrl, request, bare_jid_s) return d return defer.succeed(url if url else C.DEFAULT_AVATAR_URL) @@ -557,7 +541,7 @@ d_list = [] options = {} - d = self.getAvatarURL(pub_jid) + d = self.getAvatarURL(pub_jid, request) d.addCallback(self._updateDict, options, 'avatar') d.addErrback(self.renderError, request, pub_jid) d_list.append(d) diff -r 36e9747520fd -r 67a59552f3e3 src/server/server.py --- a/src/server/server.py Tue May 23 00:06:03 2017 +0200 +++ b/src/server/server.py Sat Jun 03 22:27:04 2017 +0200 @@ -2128,6 +2128,12 @@ @raise IOError: the certificate file doesn't exist @raise OpenSSL.crypto.Error: the certificate file is invalid """ + # now that we have service profile connected, we add resource for its cache + service_path = regex.pathEscape(C.SERVICE_PROFILE) + cache_dir = os.path.join(self.cache_root_dir, service_path) + self.cache_resource.putChild(service_path, ProtectedFile(cache_dir)) + self.service_cache_url = os.path.join(C.CACHE_DIR, service_path) + if self.options['connection_type'] in ('https', 'both'): self._TLSOptionsCheck() context_factory = self._getTLSContextFactory()