Mercurial > libervia-web
changeset 950:67a59552f3e3
server (blog): fixed avatars handling, there is now a well-known URL to SERVICE_PROFILE cache
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 03 Jun 2017 22:27:04 +0200 |
parents | 36e9747520fd |
children | 43df2bf38787 |
files | src/server/blog.py src/server/server.py |
diffstat | 2 files changed, 18 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- 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"<div ?/>|<div> *?</div>") -# 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)
--- 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()