diff --git a/static/js/notifications.js b/static/js/notifications.js index 4b468e8f8e..a202b0e8db 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -331,7 +331,7 @@ function process_notification(notification) { content = message.sender_full_name + content.slice(3); } - if (message.type === "private") { + if (message.type === "private" || message.type === "test-notification") { if (page_params.pm_content_in_desktop_notifications !== undefined && !page_params.pm_content_in_desktop_notifications) { content = "New private message from " + message.sender_full_name; @@ -411,7 +411,9 @@ function process_notification(notification) { }); notification_object.onclick = function () { notification_object.cancel(); - narrow.by_topic(message.id, {trigger: 'notification'}); + if (message.type !== "test-notification") { + narrow.by_topic(message.id, {trigger: 'notification'}); + } window.focus(); }; notification_object.onclose = function () { @@ -427,6 +429,10 @@ function process_notification(notification) { tag: message.id, }); notification_object.onclick = function () { + if (message.type === "test-notification") { + return; + } + // We don't need to bring the browser window into focus explicitly // by calling `window.focus()` as well as don't need to clear the // notification since it is the default behavior in Firefox. @@ -491,6 +497,11 @@ exports.message_is_notifiable = function (message) { }; exports.should_send_desktop_notification = function (message) { + // Always notify for testing notifications. + if (message.type === "test-notification") { + return true; + } + // For streams, send if desktop notifications are enabled for all // message on this stream. if (message.type === "stream" && @@ -542,7 +553,7 @@ exports.should_send_audible_notification = function (message) { // And then we need to check if the message is a PM, mention, // wildcard mention with wildcard_mentions_notify, or alert. - if (message.type === "private") { + if (message.type === "private" || message.type === "test-notification") { return true; } @@ -600,6 +611,18 @@ exports.received_messages = function (messages) { } }; +exports.send_test_notification = function (content) { + notifications.received_messages([{ + id: Math.random(), + type: "test-notification", + sender_email: "notification-bot@zulip.com", + sender_full_name: "Notification Bot", + display_reply_to: "Notification Bot", + content, + unread: true, + }]); +}; + function get_message_header(message) { if (message.type === "stream") { return message.stream + " > " + message.topic; diff --git a/static/js/settings_notifications.js b/static/js/settings_notifications.js index 6006b13b78..0bfc30143f 100644 --- a/static/js/settings_notifications.js +++ b/static/js/settings_notifications.js @@ -103,6 +103,12 @@ exports.set_up = function () { update_desktop_icon_count_display(); + $("#send_test_notification").click(() => { + notifications.send_test_notification( + i18n.t("This is what a Zulip notification looks like.") + ); + }); + $("#play_notification_sound").click(function () { $("#notifications-area").find("audio")[0].play(); }); diff --git a/static/templates/settings/notification_settings.hbs b/static/templates/settings/notification_settings.hbs index 6776459ba0..e8837a98e2 100644 --- a/static/templates/settings/notification_settings.hbs +++ b/static/templates/settings/notification_settings.hbs @@ -53,6 +53,8 @@
{{t "Desktop" }}
+

{{t "Send test notification" }}

+ {{#each notification_settings.desktop_notification_settings}} {{> settings_checkbox setting_name=this