mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	settings: Refactor notification settings frontend code.
This commit creates a new module user_notification_settings.js for user-level notification settings and the settings_notification.js will be used as a common module for both user-level and realm-level settings. We also add parameters to the functions in settings_notifications.js to pass container elem and settings object for the same purpose.
This commit is contained in:
		@@ -576,7 +576,7 @@ export function dispatch_normal_event(event) {
 | 
			
		||||
        case "user_settings": {
 | 
			
		||||
            if (settings_config.all_notification_settings.includes(event.property)) {
 | 
			
		||||
                notifications.handle_global_notification_updates(event.property, event.value);
 | 
			
		||||
                settings_notifications.update_page();
 | 
			
		||||
                settings_notifications.update_page($("#user-notification-settings"), user_settings);
 | 
			
		||||
                // 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
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,6 @@ import * as settings_ui from "./settings_ui";
 | 
			
		||||
import * as stream_edit from "./stream_edit";
 | 
			
		||||
import * as stream_settings_data from "./stream_settings_data";
 | 
			
		||||
import * as unread_ui from "./unread_ui";
 | 
			
		||||
import {user_settings} from "./user_settings";
 | 
			
		||||
 | 
			
		||||
function rerender_ui() {
 | 
			
		||||
    const unmatched_streams_table = $("#stream-specific-notify-table");
 | 
			
		||||
@@ -50,17 +49,14 @@ function change_notification_setting(setting, value, status_element, url) {
 | 
			
		||||
    settings_ui.do_settings_change(channel.patch, url, data, status_element);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function update_desktop_icon_count_display() {
 | 
			
		||||
    const container = $("#user-notification-settings");
 | 
			
		||||
    const settings_object = user_settings;
 | 
			
		||||
function update_desktop_icon_count_display(container, settings_object) {
 | 
			
		||||
    container
 | 
			
		||||
        .find(".setting_desktop_icon_count_display")
 | 
			
		||||
        .val(settings_object.desktop_icon_count_display);
 | 
			
		||||
    unread_ui.update_unread_counts();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function set_enable_digest_emails_visibility() {
 | 
			
		||||
    const container = $("#user-notification-settings");
 | 
			
		||||
export function set_enable_digest_emails_visibility(container) {
 | 
			
		||||
    if (page_params.realm_digest_emails_enabled) {
 | 
			
		||||
        container.find(".enable_digest_emails_label").parent().show();
 | 
			
		||||
    } else {
 | 
			
		||||
@@ -77,10 +73,8 @@ export function set_enable_marketing_emails_visibility() {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function set_up() {
 | 
			
		||||
    const container = $("#user-notification-settings");
 | 
			
		||||
export function set_up(container, settings_object) {
 | 
			
		||||
    const patch_url = "/json/settings";
 | 
			
		||||
    const settings_object = user_settings;
 | 
			
		||||
    container.find(".notification-settings-form").on("change", "input, select", function (e) {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        e.stopPropagation();
 | 
			
		||||
@@ -98,7 +92,7 @@ export function set_up() {
 | 
			
		||||
        );
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    update_desktop_icon_count_display();
 | 
			
		||||
    update_desktop_icon_count_display(container, settings_object);
 | 
			
		||||
 | 
			
		||||
    container.find(".send_test_notification").on("click", () => {
 | 
			
		||||
        notifications.send_test_notification(
 | 
			
		||||
@@ -135,14 +129,12 @@ export function set_up() {
 | 
			
		||||
        settings_object.email_notifications_batching_period_seconds,
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    set_enable_digest_emails_visibility();
 | 
			
		||||
    set_enable_digest_emails_visibility(container);
 | 
			
		||||
    set_enable_marketing_emails_visibility();
 | 
			
		||||
    rerender_ui();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function update_page() {
 | 
			
		||||
    const container = $("#user-notification-settings");
 | 
			
		||||
    const settings_object = user_settings;
 | 
			
		||||
export function update_page(container, settings_object) {
 | 
			
		||||
    for (const setting of settings_config.all_notification_settings) {
 | 
			
		||||
        if (
 | 
			
		||||
            setting === "enable_offline_push_notifications" &&
 | 
			
		||||
@@ -152,7 +144,7 @@ export function update_page() {
 | 
			
		||||
            // we should just leave the checkbox always off.
 | 
			
		||||
            continue;
 | 
			
		||||
        } else if (setting === "desktop_icon_count_display") {
 | 
			
		||||
            update_desktop_icon_count_display();
 | 
			
		||||
            update_desktop_icon_count_display(container, settings_object);
 | 
			
		||||
            continue;
 | 
			
		||||
        } else if (
 | 
			
		||||
            setting === "notification_sound" ||
 | 
			
		||||
 
 | 
			
		||||
@@ -381,7 +381,9 @@ function update_dependent_subsettings(property_name) {
 | 
			
		||||
            set_message_content_in_email_notifications_visiblity();
 | 
			
		||||
            break;
 | 
			
		||||
        case "realm_digest_emails_enabled":
 | 
			
		||||
            settings_notifications.set_enable_digest_emails_visibility();
 | 
			
		||||
            settings_notifications.set_enable_digest_emails_visibility(
 | 
			
		||||
                $("#user-notification-settings"),
 | 
			
		||||
            );
 | 
			
		||||
            set_digest_emails_weekday_visibility();
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -57,7 +57,9 @@ export function initialize() {
 | 
			
		||||
    load_func_dict.set("display-settings", () => {
 | 
			
		||||
        settings_display.set_up($("#user-display-settings"), user_settings, false);
 | 
			
		||||
    });
 | 
			
		||||
    load_func_dict.set("notifications", settings_notifications.set_up);
 | 
			
		||||
    load_func_dict.set("notifications", () => {
 | 
			
		||||
        settings_notifications.set_up($("#user-notification-settings"), user_settings);
 | 
			
		||||
    });
 | 
			
		||||
    load_func_dict.set("your-bots", settings_bots.set_up);
 | 
			
		||||
    load_func_dict.set("alert-words", alert_words_ui.set_up_alert_words);
 | 
			
		||||
    load_func_dict.set("uploaded-files", attachments_ui.set_up_attachments);
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,7 @@ import * as stream_list from "./stream_list";
 | 
			
		||||
import * as stream_muting from "./stream_muting";
 | 
			
		||||
import * as stream_settings_ui from "./stream_settings_ui";
 | 
			
		||||
import * as sub_store from "./sub_store";
 | 
			
		||||
import {user_settings} from "./user_settings";
 | 
			
		||||
 | 
			
		||||
// In theory, this function should apply the account-level defaults,
 | 
			
		||||
// however, they are only called after a manual override, so
 | 
			
		||||
@@ -54,7 +55,7 @@ export function update_property(stream_id, property, value, other_values) {
 | 
			
		||||
        case "email_notifications":
 | 
			
		||||
        case "wildcard_mentions_notify":
 | 
			
		||||
            update_stream_setting(sub, value, property);
 | 
			
		||||
            settings_notifications.update_page();
 | 
			
		||||
            settings_notifications.update_page($("#user-notification-settings"), user_settings);
 | 
			
		||||
            break;
 | 
			
		||||
        case "name":
 | 
			
		||||
            stream_settings_ui.update_stream_name(sub, value);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user