show spoiler image in some cases for notification, improve e24cdcb8

jschan
Thomas Lynch 3 years ago
parent fb6c0fa52f
commit 194dca8ed0
  1. 29
      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) {

Loading…
Cancel
Save