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 -->
{{if or (eq .Type "also_posted") (eq .Type "also_comment")}}
<small>
<a href="/comments/subscription?table_name={{.TableName}}&table_id={{.TableID}}&next={{UrlEncode $Root.Request.URL.String}}&subscribe=false"
class="has-text-warning is-small"
title="Turn off notifications about this thread"
onclick="return confirm('Do you want to TURN OFF notifications about this comment thread?')">
<a href="#"
data-link="/comments/subscription?table_name={{.TableName}}&table_id={{.TableID}}&next={{UrlEncode $Root.Request.URL.String}}&subscribe=false"
data-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
</a>
</small>
{{else if eq .Type "new_photo"}}
<small>
<a href="/comments/subscription?table_name=friend.photos&table_id={{.AboutUser.Username}}&next={{UrlEncode $Root.Request.URL.String}}&subscribe=false"
class="has-text-warning is-small"
title="Turn off notifications about @{{.AboutUser.Username}}'s new photo uploads"
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.')">
<a href="#"
data-link="/comments/subscription?table_name=friend.photos&table_id={{.AboutUser.Username}}&next={{UrlEncode $Root.Request.URL.String}}&subscribe=false"
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."
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
</a>
</small>
@ -854,13 +856,30 @@ document.addEventListener('DOMContentLoaded', () => {
window.alert(resp);
}).finally(() => {
busy = false;
if (href !== undefined) {
if (href !== undefined && 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>
{{end}}