From 385cd9588cd041718a7c525a4faeef0cc6c7f15e Mon Sep 17 00:00:00 2001 From: djmaze Date: Tue, 15 Sep 2020 20:40:55 +0200 Subject: [PATCH] Bugfix: i've wrecked rendering of inline images --- dev/Model/Message.js | 52 ++++++++++++++++++-------------------- dev/Stores/User/Message.js | 4 ++- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/dev/Model/Message.js b/dev/Model/Message.js index f16a06a14..966b95175 100644 --- a/dev/Model/Message.js +++ b/dev/Model/Message.js @@ -655,37 +655,33 @@ class MessageModel extends AbstractModel { } showInternalImages() { - if (this.body && !this.body.rlInitInternalImages) { - this.body.rlInitInternalImages = true; + const body = this.body; + if (body && !body.rlInitInternalImages) { + const findAttachmentByCid = cid => this.attachments.findByCid(cid); - const body = this.body, - findAttachmentByCid = cid => this.attachments.findByCid(cid); + body.rlInitInternalImages = true; - body.querySelectorAll('[data-x-src-cid]').forEach(node => { - const attachment = findAttachmentByCid(node.dataset.xSrcCid); - if (attachment && attachment.download) { - node.src = attachment.linkPreview(); - } - }); - - body.querySelectorAll('[data-x-src-location]').forEach(node => { - const attachment = this.attachments.find(item => node.dataset.xSrcLocation === item.contentLocation) - || findAttachmentByCid(node.dataset.xSrcLocation); - if (attachment && attachment.download) { - if (node.matches('img')) { - node.loading = 'lazy'; + body.querySelectorAll('[data-x-src-cid],[data-x-src-location],[data-x-style-cid]').forEach(el => { + const data = el.dataset; + if (data.xSrcCid) { + const attachment = findAttachmentByCid(data.xSrcCid); + if (attachment && attachment.download) { + el.src = attachment.linkPreview(); + } + } else if (data.xSrcLocation) { + const attachment = this.attachments.find(item => data.xSrcLocation === item.contentLocation) + || findAttachmentByCid(data.xSrcLocation); + if (attachment && attachment.download) { + el.loading = 'lazy'; + el.src = attachment.linkPreview(); + } + } else if (data.xStyleCid) { + const name = data.xStyleCidName, + attachment = findAttachmentByCid(data.xStyleCid); + if (attachment && attachment.linkPreview && name) { + el.setAttribute('style', name + ": url('" + attachment.linkPreview() + "');" + + (el.getAttribute('style') || '')); } - node.src = attachment.linkPreview(); - } - }); - - body.querySelectorAll('[style-cid]').forEach(node => { - const name = node.dataset.xStyleCidName, - attachment = findAttachmentByCid(node.dataset.xStyleCid); - if (attachment && attachment.linkPreview && name) { - node.setAttribute('style', ((node.getAttribute('style')||'') - + ';' + name + ": url('" + attachment.linkPreview() + "')") - .replace(/^[;\s]+/,'')); } }); } diff --git a/dev/Stores/User/Message.js b/dev/Stores/User/Message.js index ecb687a9f..62a226bec 100644 --- a/dev/Stores/User/Message.js +++ b/dev/Stores/User/Message.js @@ -494,6 +494,7 @@ class MessageUserStore { iMessageBodyCacheCount += 1; textBody.rlCacheCount = iMessageBodyCacheCount; message.fetchDataFromDom(); + message.body = textBody; } else { let isHtml = false; if (data.Result.Html) { @@ -542,6 +543,8 @@ class MessageUserStore { + ''); body.rlCacheCount = iMessageBodyCacheCount; + message.body = body; + message.isHtml(!!isHtml); message.hasImages(!!data.Result.HasExternals); @@ -560,7 +563,6 @@ class MessageUserStore { this.purgeMessageBodyCacheThrottle(); } - message.body = body || textBody; this.messageActiveDom(message.body); this.hideMessageBodies();