From 194dca8ed0ccac2b3d918adf9def011d88876863 Mon Sep 17 00:00:00 2001 From: Thomas Lynch Date: Tue, 21 Sep 2021 12:52:00 +0000 Subject: [PATCH] show spoiler image in some cases for notification, improve e24cdcb8 --- gulp/res/js/yous.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/gulp/res/js/yous.js b/gulp/res/js/yous.js index 8e3e10d0..472b9a6a 100644 --- a/gulp/res/js/yous.js +++ b/gulp/res/js/yous.js @@ -72,22 +72,27 @@ const handleNewYous = (e) => { const notificationOptions = { body: postData.nomarkup ? postData.nomarkup.substring(0,100) : '' } - if (postData.files.length > 0 && !postData.spoiler) { + if (postData.files.length > 0) { //tries to use a thumb instead of full files, will be lighter on bandwidth and able to show for video and some audio too + let notificationImageURL; + const spoilerNotification = (postData.spoiler || postData.files.some(f => f.spoiler === true)); const notificationFile = postData.files.find(f => (!f.spoiler && (f.hasThumb === true || f.mimetype.startsWith('image/')))); - if (notificationFile) { - let notificationImageURL; - if (notificationFile.hasThumb) { - notificationImageURL = `/file/thumb/${notificationFile.hash}${notificationFile.thumbextension}`; - } else { - notificationImageURL = `/file/${notificationFile.filename}`; - } - if (notificationImageURL) { - notificationOptions.image = notificationImageURL; - notificationOptions.badge = notificationImageURL; - notificationOptions.icon = notificationImageURL; + if (spoilerNotification && !notificationFile) { + notificationImageURL = '/file/spoiler.png'; + } else { + if (notificationFile) { + if (notificationFile.hasThumb) { + notificationImageURL = `/file/thumb/${notificationFile.hash}${notificationFile.thumbextension}`; + } else { + notificationImageURL = `/file/${notificationFile.filename}`; + } } } + if (notificationImageURL) { + notificationOptions.image = notificationImageURL; + notificationOptions.badge = notificationImageURL; + notificationOptions.icon = notificationImageURL; + } } new Notification(`${quotesYou ? 'New quote in: ' : ''}${document.title}`, notificationOptions); } catch (e) {