mirror of https://github.com/zulip/zulip.git
notifications: Enable audible notifications for the FOLLOWED topic.
This commit adds support for triggering audible desktop notifications when: * A message is sent to a followed topic with the global user setting 'enable_followed_topic_audible_notifications' enabled. * A message with wildcard mentions is sent to a followed topic with the global user setting 'enable_followed_topic_wildcard_mentions_notify' enabled.
This commit is contained in:
parent
67d4334bf1
commit
1a2831059d
|
@ -453,6 +453,16 @@ export function should_send_audible_notification(message) {
|
||||||
return true;
|
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,
|
// enable_sounds determines whether we ding for direct messages,
|
||||||
// mentions, and/or alerts.
|
// mentions, and/or alerts.
|
||||||
if (!user_settings.enable_sounds) {
|
if (!user_settings.enable_sounds) {
|
||||||
|
@ -473,6 +483,10 @@ export function should_send_audible_notification(message) {
|
||||||
return true;
|
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 mentions
|
// wildcard mentions
|
||||||
if (
|
if (
|
||||||
message.mentioned &&
|
message.mentioned &&
|
||||||
|
@ -481,6 +495,15 @@ export function should_send_audible_notification(message) {
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ function test(label, f) {
|
||||||
page_params.is_admin = false;
|
page_params.is_admin = false;
|
||||||
page_params.realm_users = [];
|
page_params.realm_users = [];
|
||||||
user_settings.enable_followed_topic_desktop_notifications = true;
|
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_desktop_notifications = true;
|
||||||
user_settings.enable_sounds = true;
|
user_settings.enable_sounds = true;
|
||||||
user_settings.enable_followed_topic_wildcard_mentions_notify = 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);
|
assert.equal(notifications.message_is_notifiable(message), true);
|
||||||
|
|
||||||
// Case 4: If the message has been sent to a followed topic,
|
// Case 4: If the message has been sent to a followed topic,
|
||||||
// DO visually notify the user if 'enable_followed_topic_desktop_notifications'
|
// DO visually and audibly notify the user if 'enable_followed_topic_desktop_notifications'
|
||||||
// is enabled.
|
// and 'enable_followed_topic_audible_notifications' are enabled, respectively.
|
||||||
// Messages to followed topics trumps muting
|
// Messages to followed topics trumps muting
|
||||||
message = {
|
message = {
|
||||||
id: 30,
|
id: 30,
|
||||||
|
@ -144,11 +145,15 @@ test("message_is_notifiable", () => {
|
||||||
topic: "followed topic",
|
topic: "followed topic",
|
||||||
};
|
};
|
||||||
assert.equal(notifications.should_send_desktop_notification(message), true);
|
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);
|
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_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_desktop_notification(message), false);
|
||||||
|
assert.equal(notifications.should_send_audible_notification(message), false);
|
||||||
assert.equal(notifications.message_is_notifiable(message), true);
|
assert.equal(notifications.message_is_notifiable(message), true);
|
||||||
|
|
||||||
// Reset state
|
// Reset state
|
||||||
|
@ -266,11 +271,13 @@ test("message_is_notifiable", () => {
|
||||||
|
|
||||||
// Case 10:
|
// Case 10:
|
||||||
// Wildcard mentions in a followed topic with 'wildcard_mentions_notify',
|
// 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;
|
// 'enable_followed_topic_wildcard_mentions_notify' enabled;
|
||||||
// DO visually notify the user
|
// DO visually and audibly notify the user
|
||||||
user_settings.wildcard_mentions_notify = false;
|
user_settings.wildcard_mentions_notify = false;
|
||||||
user_settings.enable_followed_topic_desktop_notifications = false;
|
user_settings.enable_followed_topic_desktop_notifications = false;
|
||||||
|
user_settings.enable_followed_topic_audible_notifications = false;
|
||||||
message = {
|
message = {
|
||||||
id: 50,
|
id: 50,
|
||||||
content: "message number 5",
|
content: "message number 5",
|
||||||
|
@ -284,16 +291,19 @@ test("message_is_notifiable", () => {
|
||||||
topic: "followed topic",
|
topic: "followed topic",
|
||||||
};
|
};
|
||||||
assert.equal(notifications.should_send_desktop_notification(message), true);
|
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);
|
assert.equal(notifications.message_is_notifiable(message), true);
|
||||||
|
|
||||||
// But not if 'enable_followed_topic_wildcard_mentions_notify' is disabled
|
// But not if 'enable_followed_topic_wildcard_mentions_notify' is disabled
|
||||||
user_settings.enable_followed_topic_wildcard_mentions_notify = false;
|
user_settings.enable_followed_topic_wildcard_mentions_notify = false;
|
||||||
assert.equal(notifications.should_send_desktop_notification(message), 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);
|
assert.equal(notifications.message_is_notifiable(message), true);
|
||||||
|
|
||||||
// Reset state
|
// Reset state
|
||||||
user_settings.wildcard_mentions_notify = true;
|
user_settings.wildcard_mentions_notify = true;
|
||||||
user_settings.enable_followed_topic_desktop_notifications = 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;
|
user_settings.enable_followed_topic_wildcard_mentions_notify = true;
|
||||||
|
|
||||||
// Case 11: If `None` is selected as the notification sound, send no
|
// Case 11: If `None` is selected as the notification sound, send no
|
||||||
|
|
Loading…
Reference in New Issue