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

Commit 2809e75

Browse files
author
the-djmaze
committed
Preload identicon on delayed avatar lookup
1 parent a83c3aa commit 2809e75

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

plugins/avatars/avatars.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
(from.name?.split(/[^\p{L}]+/gu) || []).reduce((a, s) => a + (s[0] || ''), '')
8080
.slice(0,2)
8181
.toUpperCase(),
82-
setIdenticon = (msg, fn, cache) => {
82+
setIdenticon = (msg, fn, cb) => {
8383
const from = email(msg);
8484
if (identicons.get(from)) {
8585
fn(identicons.get(from));
@@ -92,7 +92,7 @@
9292
));
9393
fn(uri);
9494
identicons.set(email(msg), uri);
95-
cache && avatars.set(getAvatarUid(msg), uri);
95+
cb?.(uri);
9696
});
9797
}
9898
},
@@ -101,9 +101,10 @@
101101
if (msg.from?.[0]) {
102102
if (getAvatarUri(msg)) {
103103
if (rl.pluginSettingsGet('avatars', 'delay')) {
104-
setIdenticon(msg, fn);
105-
queue.push([msg, fn]);
106-
runQueue();
104+
setIdenticon(msg, fn, ()=>{
105+
queue.push([msg, fn]);
106+
runQueue();
107+
});
107108
} else {
108109
fn(msg.avatar);
109110
}
@@ -200,7 +201,7 @@
200201
fn = url=>{element.src = url};
201202
element.onerror = ()=>{
202203
element.onerror = null;
203-
setIdenticon(msg, fn, 1);
204+
setIdenticon(msg, fn, uri=>avatars.set(getAvatarUid(msg), uri));
204205
};
205206
if (url) {
206207
fn(url);

0 commit comments

Comments
 (0)