Fix mute notification links on unread notifications

This commit is contained in:
Noah Petherbridge 2024-08-07 23:30:19 -07:00
parent 147a9162ba
commit a6bd33fdf8

View File

@ -666,19 +666,21 @@
<!-- Contextual "Unsubscribe" buttons --> <!-- Contextual "Unsubscribe" buttons -->
{{if or (eq .Type "also_posted") (eq .Type "also_comment")}} {{if or (eq .Type "also_posted") (eq .Type "also_comment")}}
<small> <small>
<a href="/comments/subscription?table_name={{.TableName}}&table_id={{.TableID}}&next={{UrlEncode $Root.Request.URL.String}}&subscribe=false" <a href="#"
class="has-text-warning is-small" data-link="/comments/subscription?table_name={{.TableName}}&table_id={{.TableID}}&next={{UrlEncode $Root.Request.URL.String}}&subscribe=false"
title="Turn off notifications about this thread" data-confirm="Do you want to TURN OFF notifications about this comment thread?"
onclick="return confirm('Do you want to TURN OFF notifications about this comment thread?')"> class="has-text-warning is-small nonshy-mute-notification-link"
title="Turn off notifications about this thread">
<i class="fa fa-microphone-slash mr-1"></i> Mute this thread <i class="fa fa-microphone-slash mr-1"></i> Mute this thread
</a> </a>
</small> </small>
{{else if eq .Type "new_photo"}} {{else if eq .Type "new_photo"}}
<small> <small>
<a href="/comments/subscription?table_name=friend.photos&table_id={{.AboutUser.Username}}&next={{UrlEncode $Root.Request.URL.String}}&subscribe=false" <a href="#"
class="has-text-warning is-small" data-link="/comments/subscription?table_name=friend.photos&table_id={{.AboutUser.Username}}&next={{UrlEncode $Root.Request.URL.String}}&subscribe=false"
title="Turn off notifications about @{{.AboutUser.Username}}'s new photo uploads" data-confirm="Do you want to TURN OFF notifications about @{{.AboutUser.Username}}\'s new photo uploads?\n\nNote: to re-subscribe to their new photo notifications, see the link at the top of @{{.AboutUser.Username}}\'s Photo Gallery page."
onclick="return confirm('Do you want to TURN OFF notifications about @{{.AboutUser.Username}}\'s new photo uploads?\n\nNote: to re-subscribe to their new photo notifications, see the link at the top of @{{.AboutUser.Username}}\'s Photo Gallery page.')"> class="has-text-warning is-small nonshy-mute-notification-link"
title="Turn off notifications about @{{.AboutUser.Username}}'s new photo uploads">
<i class="fa fa-microphone-slash mr-1"></i> Mute these notifications <i class="fa fa-microphone-slash mr-1"></i> Mute these notifications
</a> </a>
</small> </small>
@ -854,13 +856,30 @@ document.addEventListener('DOMContentLoaded', () => {
window.alert(resp); window.alert(resp);
}).finally(() => { }).finally(() => {
busy = false; busy = false;
if (href !== undefined) { if (href !== undefined && href !== "#") {
window.location.href = href; window.location.href = href;
} }
}); });
}) })
}); });
}); });
// "Mute notification" links.
// NOTE: to avoid conflict with the "mark notification as read, then follow href" code
// above, the mute buttons href is made safer and this function will get its follow-thru
// URL from a data attribute.
(document.querySelectorAll(".nonshy-mute-notification-link") || []).forEach(node => {
node.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
const link = node.dataset.link,
prompt = node.dataset.confirm;
if (!window.confirm(prompt)) return;
window.location = link;
});
});
}); });
</script> </script>
{{end}} {{end}}