Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
notifications: Enable audible notifications for the FOLLOWED topic.
Prakhar Pratyush1a2831059dd2
diff --git a/web/src/notifications.js b/web/src/notifications.jsindex 304af20297a..73e9c238e57 100644--- a/web/src/notifications.js+++ b/web/src/notifications.js@@ -453,6 +453,16 @@ export function should_send_audible_notification(message) {return true;}+ // enable_followed_topic_audible_notifications determines whether we ding+ // for messages in followed topics.+ if (+ message.type === "stream" &&+ user_topics.is_topic_followed(message.stream_id, message.topic) &&+ user_settings.enable_followed_topic_audible_notifications+ ) {+ return true;+ }+// enable_sounds determines whether we ding for direct messages,// mentions, and/or alerts.if (!user_settings.enable_sounds) {@@ -473,6 +483,10 @@ export function should_send_audible_notification(message) {return true;}+ // The following blocks for 'wildcard mentions' and 'Followed topic wildcard mentions'+ // should be placed below (as they are right now) the 'user_settings.enable_sounds'+ // block because the global, stream-specific, and followed topic wildcard mention+ // settings are wrappers around the personal-mention setting.// wildcard mentionsif (message.mentioned &&@@ -481,6 +495,15 @@ export function should_send_audible_notification(message) {return true;}+ // Followed topic wildcard mentions+ if (+ message.mentioned &&+ user_topics.is_topic_followed(message.stream_id, message.topic) &&+ user_settings.enable_followed_topic_wildcard_mentions_notify+ ) {+ return true;+ }+return false;}diff --git a/web/tests/notifications.test.js b/web/tests/notifications.test.jsindex 8a78fb454e9..578cc9e1c9e 100644--- a/web/tests/notifications.test.js+++ b/web/tests/notifications.test.js@@ -52,6 +52,7 @@ function test(label, f) {page_params.is_admin = false;page_params.realm_users = [];user_settings.enable_followed_topic_desktop_notifications = true;+ user_settings.enable_followed_topic_audible_notifications = true;user_settings.enable_desktop_notifications = true;user_settings.enable_sounds = true;user_settings.enable_followed_topic_wildcard_mentions_notify = true;@@ -128,8 +129,8 @@ test("message_is_notifiable", () => {assert.equal(notifications.message_is_notifiable(message), true);// Case 4: If the message has been sent to a followed topic,- // DO visually notify the user if 'enable_followed_topic_desktop_notifications'- // is enabled.+ // DO visually and audibly notify the user if 'enable_followed_topic_desktop_notifications'+ // and 'enable_followed_topic_audible_notifications' are enabled, respectively.// Messages to followed topics trumps mutingmessage = {id: 30,@@ -144,11 +145,15 @@ test("message_is_notifiable", () => {topic: "followed topic",};assert.equal(notifications.should_send_desktop_notification(message), true);+ assert.equal(notifications.should_send_audible_notification(message), true);assert.equal(notifications.message_is_notifiable(message), true);- // But not if 'enable_followed_topic_desktop_notifications' is disabled+ // But not if 'enable_followed_topic_desktop_notifications'+ // and 'enable_followed_topic_audible_notifications' are disabled.user_settings.enable_followed_topic_desktop_notifications = false;+ user_settings.enable_followed_topic_audible_notifications = false;assert.equal(notifications.should_send_desktop_notification(message), false);+ assert.equal(notifications.should_send_audible_notification(message), false);assert.equal(notifications.message_is_notifiable(message), true);// Reset state@@ -266,11 +271,13 @@ test("message_is_notifiable", () => {// Case 10:// Wildcard mentions in a followed topic with 'wildcard_mentions_notify',- // 'enable_followed_topic_desktop_notifications' disabled and+ // 'enable_followed_topic_desktop_notifications',+ // 'enable_followed_topic_audible_notifications' disabled and// 'enable_followed_topic_wildcard_mentions_notify' enabled;- // DO visually notify the user+ // DO visually and audibly notify the useruser_settings.wildcard_mentions_notify = false;user_settings.enable_followed_topic_desktop_notifications = false;+ user_settings.enable_followed_topic_audible_notifications = false;message = {id: 50,content: "message number 5",@@ -284,16 +291,19 @@ test("message_is_notifiable", () => {topic: "followed topic",};assert.equal(notifications.should_send_desktop_notification(message), true);+ assert.equal(notifications.should_send_audible_notification(message), true);assert.equal(notifications.message_is_notifiable(message), true);// But not if 'enable_followed_topic_wildcard_mentions_notify' is disableduser_settings.enable_followed_topic_wildcard_mentions_notify = false;assert.equal(notifications.should_send_desktop_notification(message), false);+ assert.equal(notifications.should_send_audible_notification(message), false);assert.equal(notifications.message_is_notifiable(message), true);// Reset stateuser_settings.wildcard_mentions_notify = true;user_settings.enable_followed_topic_desktop_notifications = true;+ user_settings.enable_followed_topic_audible_notifications = true;user_settings.enable_followed_topic_wildcard_mentions_notify = true;// Case 11: If `None` is selected as the notification sound, send no