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

Commit

Permalink
Preload identicon on delayed avatar lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Oct 29, 2024
1 parent a83c3aa commit 2809e75
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions plugins/avatars/avatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
(from.name?.split(/[^\p{L}]+/gu) || []).reduce((a, s) => a + (s[0] || ''), '')
.slice(0,2)
.toUpperCase(),
setIdenticon = (msg, fn, cache) => {
setIdenticon = (msg, fn, cb) => {
const from = email(msg);
if (identicons.get(from)) {
fn(identicons.get(from));
Expand All @@ -92,7 +92,7 @@
));
fn(uri);
identicons.set(email(msg), uri);
cache && avatars.set(getAvatarUid(msg), uri);
cb?.(uri);
});
}
},
Expand All @@ -101,9 +101,10 @@
if (msg.from?.[0]) {
if (getAvatarUri(msg)) {
if (rl.pluginSettingsGet('avatars', 'delay')) {
setIdenticon(msg, fn);
queue.push([msg, fn]);
runQueue();
setIdenticon(msg, fn, ()=>{
queue.push([msg, fn]);
runQueue();
});
} else {
fn(msg.avatar);
}
Expand Down Expand Up @@ -200,7 +201,7 @@
fn = url=>{element.src = url};
element.onerror = ()=>{
element.onerror = null;
setIdenticon(msg, fn, 1);
setIdenticon(msg, fn, uri=>avatars.set(getAvatarUid(msg), uri));
};
if (url) {
fn(url);
Expand Down

0 comments on commit 2809e75

Please sign in to comment.