mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-09-20 07:35:55 +08:00
Improved cache handling of remote avatars (delayed or not)
This commit is contained in:
parent
10450dea8b
commit
57d1021d51
|
@ -76,6 +76,8 @@
|
|||
if (rl.pluginSettingsGet('avatars', 'delay')) {
|
||||
queue.push([msg, fn]);
|
||||
runQueue();
|
||||
} else if (msg.avatar) {
|
||||
fn(getAvatarUrl(msg));
|
||||
}
|
||||
},
|
||||
runQueue = (() => {
|
||||
|
@ -88,6 +90,8 @@
|
|||
item[1](url);
|
||||
item = queue.shift();
|
||||
continue;
|
||||
} else if (item[0].avatar) {
|
||||
item[1](getAvatarUrl(item[0]));
|
||||
} else if (!avatars.has(uid)) {
|
||||
let from = item[0].from[0];
|
||||
rl.pluginRemoteRequest((iError, data) => {
|
||||
|
@ -104,7 +108,6 @@
|
|||
bimiSelector: getBimiSelector(item[0]),
|
||||
email: from.email
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
runQueue();
|
||||
|
@ -112,10 +115,22 @@
|
|||
}
|
||||
}).debounce(1000);
|
||||
|
||||
/**
|
||||
* Loads images from Nextcloud contacts
|
||||
*/
|
||||
addEventListener('DOMContentLoaded', () => {
|
||||
// addEventListener('DOMContentLoaded', () => {
|
||||
/**
|
||||
* Modify templates
|
||||
*/
|
||||
getEl('MailMessageList').content.querySelectorAll('.messageCheckbox')
|
||||
.forEach(el => el.append(Element.fromHTML(`<img class="fromPic" data-bind="fromPic:$data" loading="lazy">`)));
|
||||
const messageItemHeader = getEl(templateId).content.querySelector('.messageItemHeader');
|
||||
if (messageItemHeader) {
|
||||
messageItemHeader.prepend(Element.fromHTML(
|
||||
`<img class="fromPic" data-bind="visible: viewUserPicVisible, attr: {'src': viewUserPic() }" loading="lazy">`
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads images from Nextcloud contacts
|
||||
*/
|
||||
// rl.pluginSettingsGet('avatars', 'nextcloud');
|
||||
if (parent.OC?.requestToken) {
|
||||
const OC = parent.OC,
|
||||
|
@ -160,24 +175,21 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// });
|
||||
|
||||
/**
|
||||
* Used by MailMessageList
|
||||
*/
|
||||
ko.bindingHandlers.fromPic = {
|
||||
init: (element, self, dummy, msg) => {
|
||||
try {
|
||||
if (msg?.from?.[0]) {
|
||||
let url = getAvatar(msg),
|
||||
from = msg.from[0],
|
||||
fn = url=>{element.src = url};
|
||||
if (url) {
|
||||
fn(url);
|
||||
} else if (msg.avatar) {
|
||||
if (msg.avatar?.startsWith('data:')) {
|
||||
fn(msg.avatar);
|
||||
} else {
|
||||
element.onerror = () => setIdenticon(from, fn);
|
||||
fn(getAvatarUrl(msg));
|
||||
}
|
||||
} else if (msg.avatar?.startsWith('data:')) {
|
||||
fn(msg.avatar);
|
||||
} else {
|
||||
addQueue(msg, fn);
|
||||
}
|
||||
|
@ -190,17 +202,6 @@
|
|||
|
||||
addEventListener('rl-view-model.create', e => {
|
||||
if (templateId === e.detail.viewModelTemplateID) {
|
||||
|
||||
const
|
||||
template = getEl(templateId),
|
||||
messageItemHeader = template.content.querySelector('.messageItemHeader');
|
||||
|
||||
if (messageItemHeader) {
|
||||
messageItemHeader.prepend(Element.fromHTML(
|
||||
`<img class="fromPic" data-bind="visible: viewUserPicVisible, attr: {'src': viewUserPic() }" loading="lazy">`
|
||||
));
|
||||
}
|
||||
|
||||
let view = e.detail;
|
||||
view.viewUserPic = ko.observable('');
|
||||
view.viewUserPicVisible = ko.observable(false);
|
||||
|
@ -226,11 +227,6 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ('MailMessageList' === e.detail.viewModelTemplateID) {
|
||||
getEl('MailMessageList').content.querySelectorAll('.messageCheckbox')
|
||||
.forEach(el => el.append(Element.fromHTML(`<img class="fromPic" data-bind="fromPic:$data" loading="lazy">`)));
|
||||
}
|
||||
});
|
||||
|
||||
})(window.rl);
|
||||
|
|
|
@ -10,8 +10,8 @@ class AvatarsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
NAME = 'Avatars',
|
||||
AUTHOR = 'SnappyMail',
|
||||
URL = 'https://snappymail.eu/',
|
||||
VERSION = '1.18',
|
||||
RELEASE = '2024-06-24',
|
||||
VERSION = '1.19',
|
||||
RELEASE = '2024-07-08',
|
||||
REQUIRED = '2.33.0',
|
||||
CATEGORY = 'Contacts',
|
||||
LICENSE = 'MIT',
|
||||
|
@ -28,7 +28,12 @@ class AvatarsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$this->addJs("{$identicon}.js");
|
||||
}
|
||||
// https://github.com/the-djmaze/snappymail/issues/714
|
||||
if ($this->Config()->Get('plugin', 'service', true) || !$this->Config()->Get('plugin', 'delay', true)) {
|
||||
if ($this->Config()->Get('plugin', 'service', true)
|
||||
// || !$this->Config()->Get('plugin', 'delay', true)
|
||||
|| $this->Config()->Get('plugin', 'gravatar', false)
|
||||
|| $this->Config()->Get('plugin', 'bimi', false)
|
||||
|| $this->Config()->Get('plugin', 'favicon', false)
|
||||
) {
|
||||
$this->addHook('json.after-message', 'JsonMessage');
|
||||
$this->addHook('json.after-messagelist', 'JsonMessageList');
|
||||
}
|
||||
|
@ -69,8 +74,8 @@ class AvatarsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$mFrom = $mFrom->jsonSerialize();
|
||||
}
|
||||
if (\is_array($mFrom)) {
|
||||
if (!$this->Config()->Get('plugin', 'delay', true)
|
||||
&& ($this->Config()->Get('plugin', 'gravatar', false)
|
||||
if (/*!$this->Config()->Get('plugin', 'delay', true)
|
||||
&& */($this->Config()->Get('plugin', 'gravatar', false)
|
||||
|| ($this->Config()->Get('plugin', 'bimi', false) && 'pass' == $mFrom['dkimStatus'])
|
||||
|| ($this->Config()->Get('plugin', 'favicon', false) && 'pass' == $mFrom['dkimStatus'])
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue