From 1d4c03eaf409b7a536ecea56478d4335edb2f5c4 Mon Sep 17 00:00:00 2001 From: Niko Date: Fri, 18 Feb 2022 11:42:49 +0100 Subject: [PATCH] Make use of http.cache module on instance_emojis --- web/src/app/js/app.js | 17 ++++++----------- web/src/app/js/pages/meet.js | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/web/src/app/js/app.js b/web/src/app/js/app.js index 3fe2400..4bfa998 100644 --- a/web/src/app/js/app.js +++ b/web/src/app/js/app.js @@ -207,10 +207,9 @@ app.emoji = { return value; }, get: function(name) { - var emojis = app.storage.get('emojis_cache'); - if (emojis === undefined) return null; - emojis = JSON.parse(emojis); - if (emojis[name] === undefined) return null; + var emojis = http.cache.get('instance_emojis'); + if (emojis === undefined || + emojis[name] === undefined) return null; return emojis[name].url; }, } @@ -244,14 +243,10 @@ window.onload = function(e) { scriptPageHandler('pages.chat', { exact: 'chat' }); } - const ts = new Date().getTime(); - const ts2 = parseInt(app.storage.get('emojis_cache_ts')); - const diff = isNaN(ts2) ? -1 : ((ts - ts2) / 1000); - if (diff === -1 || diff >= (30 * 60)) { - app.storage.del('emojis_cache'); + if (http.cache.expired('instance_emojis', 30*60)) { + http.cache.del('instance_emojis'); http.get('/api/v1/instance/emojis', {}, function(data) { - app.storage.set('emojis_cache', data); - app.storage.set('emojis_cache_ts', ts); + http.cache.set('instance_emojis', data); }) } diff --git a/web/src/app/js/pages/meet.js b/web/src/app/js/pages/meet.js index 9792d46..0dd0a67 100644 --- a/web/src/app/js/pages/meet.js +++ b/web/src/app/js/pages/meet.js @@ -14,7 +14,7 @@ app.pages.meet = { app.pages.meet.data = json; app.template.loadMany(['meet.item','meet.actions'], async function(_) { await waitUntil(function() { - return app.storage.get('emojis_cache') !== undefined; + return http.cache.get('instance_emojis') !== undefined; }, 3); app.pages.meet.paint(json); app.pages.meet.paintInterval();