mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 18:36:36 +00:00
notifications: Inline handle_global_notification_updates.
This commit is contained in:
@@ -19,10 +19,8 @@ import * as navigate from "./navigate";
|
|||||||
import {page_params} from "./page_params";
|
import {page_params} from "./page_params";
|
||||||
import * as people from "./people";
|
import * as people from "./people";
|
||||||
import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
|
import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
|
||||||
import * as settings_config from "./settings_config";
|
|
||||||
import * as spoilers from "./spoilers";
|
import * as spoilers from "./spoilers";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
import * as stream_ui_updates from "./stream_ui_updates";
|
|
||||||
import * as ui_util from "./ui_util";
|
import * as ui_util from "./ui_util";
|
||||||
import * as unread from "./unread";
|
import * as unread from "./unread";
|
||||||
import * as unread_ops from "./unread_ops";
|
import * as unread_ops from "./unread_ops";
|
||||||
@@ -773,23 +771,3 @@ export function register_click_handlers() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handle_global_notification_updates(notification_name, setting) {
|
|
||||||
// Update the global settings checked when determining if we should notify
|
|
||||||
// for a given message. These settings do not affect whether or not a
|
|
||||||
// particular stream should receive notifications.
|
|
||||||
if (settings_config.all_notification_settings.includes(notification_name)) {
|
|
||||||
user_settings[notification_name] = setting;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings_config.stream_notification_settings.includes(notification_name)) {
|
|
||||||
stream_ui_updates.update_notification_setting_checkbox(
|
|
||||||
settings_config.specialize_stream_notification_setting[notification_name],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notification_name === "notification_sound") {
|
|
||||||
// Change the sound source with the new page `notification_sound`.
|
|
||||||
update_notification_sound_source($("#user-notification-sound-audio"), user_settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -646,13 +646,27 @@ export function dispatch_normal_event(event) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "user_settings": {
|
case "user_settings": {
|
||||||
if (settings_config.all_notification_settings.includes(event.property)) {
|
const notification_name = event.property;
|
||||||
notifications.handle_global_notification_updates(event.property, event.value);
|
if (settings_config.all_notification_settings.includes(notification_name)) {
|
||||||
|
// Update the global settings checked when determining if we should notify
|
||||||
|
// for a given message. These settings do not affect whether or not a
|
||||||
|
// particular stream should receive notifications.
|
||||||
|
user_settings[notification_name] = event.value;
|
||||||
|
|
||||||
|
if (settings_config.stream_notification_settings.includes(notification_name)) {
|
||||||
|
stream_ui_updates.update_notification_setting_checkbox(
|
||||||
|
settings_config.specialize_stream_notification_setting[notification_name],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (notification_name === "notification_sound") {
|
||||||
|
// Change the sound source with the new page `notification_sound`.
|
||||||
|
notifications.update_notification_sound_source(
|
||||||
|
$("#user-notification-sound-audio"),
|
||||||
|
user_settings,
|
||||||
|
);
|
||||||
|
}
|
||||||
settings_notifications.update_page(settings_notifications.user_settings_panel);
|
settings_notifications.update_page(settings_notifications.user_settings_panel);
|
||||||
// TODO: This should also do a refresh of the stream_edit UI
|
|
||||||
// if it's currently displayed, possibly reusing some code
|
|
||||||
// from stream_events.js
|
|
||||||
// (E.g. update_stream_push_notifications).
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ const stream_list = mock_esm("../src/stream_list");
|
|||||||
const stream_settings_ui = mock_esm("../src/stream_settings_ui");
|
const stream_settings_ui = mock_esm("../src/stream_settings_ui");
|
||||||
const stream_list_sort = mock_esm("../src/stream_list_sort");
|
const stream_list_sort = mock_esm("../src/stream_list_sort");
|
||||||
const stream_topic_history = mock_esm("../src/stream_topic_history");
|
const stream_topic_history = mock_esm("../src/stream_topic_history");
|
||||||
|
const stream_ui_updates = mock_esm("../src/stream_ui_updates", {
|
||||||
|
update_announce_stream_option() {},
|
||||||
|
});
|
||||||
const submessage = mock_esm("../src/submessage");
|
const submessage = mock_esm("../src/submessage");
|
||||||
mock_esm("../src/top_left_corner", {
|
mock_esm("../src/top_left_corner", {
|
||||||
update_starred_count() {},
|
update_starred_count() {},
|
||||||
@@ -986,15 +989,18 @@ run_test("user_settings", ({override}) => {
|
|||||||
{
|
{
|
||||||
event = event_fixtures.user_settings__enable_stream_audible_notifications;
|
event = event_fixtures.user_settings__enable_stream_audible_notifications;
|
||||||
const stub = make_stub();
|
const stub = make_stub();
|
||||||
override(notifications, "handle_global_notification_updates", stub.f);
|
override(stream_ui_updates, "update_notification_setting_checkbox", stub.f);
|
||||||
override(settings_notifications, "update_page", noop);
|
override(settings_notifications, "update_page", noop);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
assert.equal(stub.num_calls, 1);
|
assert.equal(stub.num_calls, 1);
|
||||||
const args = stub.get_args("name", "setting");
|
const args = stub.get_args("notification_name");
|
||||||
assert_same(args.name, event.property);
|
assert_same(args.notification_name, "audible_notifications");
|
||||||
assert_same(args.setting, event.value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event = event_fixtures.user_settings__notification_sound;
|
||||||
|
override(notifications, "update_notification_sound_source", noop);
|
||||||
|
dispatch(event);
|
||||||
|
|
||||||
event = event_fixtures.user_settings__email_address_visibility;
|
event = event_fixtures.user_settings__email_address_visibility;
|
||||||
user_settings.email_address_visibility = 3;
|
user_settings.email_address_visibility = 3;
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
|||||||
@@ -955,6 +955,13 @@ exports.fixtures = {
|
|||||||
value: true,
|
value: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
user_settings__notification_sound: {
|
||||||
|
type: "user_settings",
|
||||||
|
op: "update",
|
||||||
|
property: "notification_sound",
|
||||||
|
value: "ding",
|
||||||
|
},
|
||||||
|
|
||||||
user_settings__presence_disabled: {
|
user_settings__presence_disabled: {
|
||||||
type: "user_settings",
|
type: "user_settings",
|
||||||
op: "update",
|
op: "update",
|
||||||
|
|||||||
Reference in New Issue
Block a user