Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Speedup identicons by caching them
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Oct 29, 2024
1 parent 490d808 commit 8645b0a
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions plugins/avatars/avatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
queue = [],
avatars = new Map,
ncAvatars = new Map,
identicons = new Map,
templateId = 'MailMessageView',
b64 = data => btoa(unescape(encodeURIComponent(data))),
b64url = data => b64(data).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''),
Expand Down Expand Up @@ -78,15 +79,22 @@
(from.name?.split(/[^\p{L}]+/gu) || []).reduce((a, s) => a + (s[0] || ''), '')
.slice(0,2)
.toUpperCase(),
setIdenticon = (msg, fn) => hash(msg.from[0].email).then(hash => {
const uri = 'data:image/svg+xml;base64,' + b64(window.identiconSvg(
hash,
fromChars(msg.from[0]),
window.getComputedStyle(getEl('rl-app'), null).getPropertyValue('font-family')
));
// avatars.set(getAvatarUid(msg), uri);
fn(uri);
}),
setIdenticon = (msg, fn) => {
const from = email(msg);
if (identicons.get(from)) {
fn(identicons.get(from));
} else {
hash(from).then(hash => {
const uri = 'data:image/svg+xml;base64,' + b64(window.identiconSvg(
hash,
fromChars(msg.from[0]),
window.getComputedStyle(getEl('rl-app'), null).getPropertyValue('font-family')
));
identicons.set(email(msg), uri);
fn(uri);
});
}
},

addQueue = (msg, fn) => {
if (msg.from?.[0]) {
Expand Down

0 comments on commit 8645b0a

Please sign in to comment.