notifications: Add link for sending a test notification.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2020-04-26 15:02:36 -07:00 committed by Tim Abbott
parent e701f20861
commit 8138e06935
3 changed files with 34 additions and 3 deletions

View File

@ -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();
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;

View File

@ -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();
});

View File

@ -53,6 +53,8 @@
<h5>{{t "Desktop" }}</h5>
<p><a id="send_test_notification">{{t "Send test notification" }}</a></p>
{{#each notification_settings.desktop_notification_settings}}
{{> settings_checkbox
setting_name=this