2022-11-23 00:44:57 +08:00
|
|
|
(rl => {
|
|
|
|
// if (rl.settings.get('Nextcloud'))
|
|
|
|
const
|
2022-11-23 17:22:49 +08:00
|
|
|
queue = [],
|
|
|
|
avatars = new Map,
|
|
|
|
templateId = 'MailMessageView',
|
|
|
|
getAvatarUid = msg => {
|
|
|
|
let from = msg.from[0],
|
|
|
|
bimi = 'pass' == from.dkimStatus ? 1 : 0;
|
|
|
|
return `${bimi}/${from.email}`;
|
|
|
|
},
|
|
|
|
getAvatar = msg => avatars.get(getAvatarUid(msg)),
|
|
|
|
runQueue = (() => {
|
|
|
|
let item = queue.shift();
|
|
|
|
while (item) {
|
|
|
|
let url = getAvatar(item[0]);
|
|
|
|
if (url) {
|
|
|
|
item[1](url);
|
|
|
|
item = queue.shift();
|
|
|
|
} else {
|
|
|
|
// TODO: fetch vCard from Nextcloud contacts
|
|
|
|
// let cfg = rl.settings.get('Nextcloud'),
|
|
|
|
|
|
|
|
let from = item[0].from[0];
|
|
|
|
rl.pluginRemoteRequest((iError, data) => {
|
|
|
|
if (!iError && data?.Result.type) {
|
|
|
|
url = `data:${data.Result.type};base64,${data.Result.data}`;
|
|
|
|
avatars.set(getAvatarUid(item[0]), url);
|
|
|
|
item[1](url);
|
|
|
|
}
|
|
|
|
runQueue();
|
|
|
|
}, 'Avatar', {
|
|
|
|
bimi: 'pass' == from.dkimStatus ? 1 : 0,
|
|
|
|
email: from.email
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).debounce(1000);
|
|
|
|
|
|
|
|
ko.bindingHandlers.fromPic = {
|
|
|
|
init: (element, self, dummy, msg) => {
|
|
|
|
if (msg) {
|
|
|
|
let url = getAvatar(msg),
|
|
|
|
fn = url=>{element.src = url};
|
|
|
|
if (url) {
|
|
|
|
fn(url);
|
|
|
|
} else {
|
|
|
|
queue.push([msg, fn]);
|
|
|
|
runQueue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-11-23 00:44:57 +08:00
|
|
|
|
|
|
|
addEventListener('rl-view-model.create', e => {
|
|
|
|
if (templateId === e.detail.viewModelTemplateID) {
|
|
|
|
|
|
|
|
const
|
|
|
|
template = document.getElementById(templateId),
|
|
|
|
messageItemHeader = template.content.querySelector('.messageItemHeader');
|
|
|
|
|
|
|
|
if (messageItemHeader) {
|
|
|
|
messageItemHeader.prepend(Element.fromHTML(
|
|
|
|
`<img class="fromPic" data-bind="visible: viewUserPicVisible, attr: {'src': viewUserPic() }">`
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
let view = e.detail;
|
|
|
|
view.viewUserPic = ko.observable('');
|
|
|
|
view.viewUserPicVisible = ko.observable(false);
|
|
|
|
|
|
|
|
view.message.subscribe(msg => {
|
2022-11-23 06:54:32 +08:00
|
|
|
view.viewUserPicVisible(false);
|
2022-11-23 00:44:57 +08:00
|
|
|
if (msg) {
|
2022-11-23 17:22:49 +08:00
|
|
|
let url = getAvatar(msg),
|
|
|
|
fn = url => {
|
|
|
|
view.viewUserPic(url);
|
2022-11-23 00:44:57 +08:00
|
|
|
view.viewUserPicVisible(true);
|
2022-11-23 17:22:49 +08:00
|
|
|
};
|
|
|
|
if (url) {
|
|
|
|
fn(url);
|
|
|
|
} else {
|
|
|
|
// let from = msg.from[0], bimi = 'pass' == from.dkimStatus ? 1 : 0;
|
|
|
|
// view.viewUserPic(`?Avatar/${bimi}/${encodeURIComponent(from.email)}`);
|
|
|
|
// view.viewUserPicVisible(true);
|
|
|
|
queue.push([msg, fn]);
|
|
|
|
runQueue();
|
|
|
|
}
|
2022-11-23 00:44:57 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-11-23 17:22:49 +08:00
|
|
|
|
2022-11-23 06:54:32 +08:00
|
|
|
if ('MailMessageList' === e.detail.viewModelTemplateID) {
|
2022-11-23 17:22:49 +08:00
|
|
|
document.getElementById('MailMessageList').content.querySelector('.messageCheckbox')
|
|
|
|
.append(Element.fromHTML(`<img class="fromPic" data-bind="fromPic:$data">`));
|
2022-11-23 06:54:32 +08:00
|
|
|
}
|
2022-11-23 00:44:57 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
})(window.rl);
|