diff --git a/js/link_previews_helper.js b/js/link_previews_helper.js index 87b1899c5..11d99eada 100644 --- a/js/link_previews_helper.js +++ b/js/link_previews_helper.js @@ -13,6 +13,9 @@ window.Signal = window.Signal || {}; window.Signal.LinkPreviews = window.Signal.LinkPreviews || {}; + // A cache mapping url to fetched previews + const previewCache = {}; + async function makeChunkedRequest(url) { const PARALLELISM = 3; const size = await textsecure.messaging.getProxiedSize(url); @@ -68,7 +71,21 @@ return StringView.arrayBufferToHex(digest); } - async function getPreview(url) { + // Wrapper function which utilizes cache + async function getPreview(url, skipCache = false) { + // If we have a request cached then use that + if (!skipCache && url in previewCache) { + return previewCache[url]; + } + + // Start the request + const promise = _getPreview(url); + previewCache[url] = promise; + + return promise; + } + + async function _getPreview(url) { let html; try { html = await textsecure.messaging.makeProxiedRequest(url); diff --git a/ts/components/JazzIcon/JazzIcon.tsx b/ts/components/JazzIcon/JazzIcon.tsx index ac082c1af..c9fd2fcec 100644 --- a/ts/components/JazzIcon/JazzIcon.tsx +++ b/ts/components/JazzIcon/JazzIcon.tsx @@ -94,7 +94,11 @@ export class JazzIcon extends React.PureComponent { private hueShift(colors: Array, generator: RNG) { const amount = generator.random() * 30 - wobble / 2; - return colors.map(hex => Color(hex).rotate(amount).hex()); + return colors.map(hex => + Color(hex) + .rotate(amount) + .hex() + ); } private genShape(