settings: Move the user-privacy settings related code at one place.

This commit makes small refactoring to place all the user-privacy
settings code in 'server_events_dispatch.js' at one place and use
a common function 'settings_account.update_privacy_settings_box' to
update the UI.

This also helps in early return instead of executing a lot
of `if` statements related to user-preferences settings.
This commit is contained in:
Prakhar Pratyush
2024-09-09 20:14:55 +05:30
committed by Tim Abbott
parent 75f6ae6d20
commit 00fb8f3014
2 changed files with 6 additions and 11 deletions

View File

@@ -710,11 +710,16 @@ export function dispatch_normal_event(event) {
"send_stream_typing_notifications",
"send_private_typing_notifications",
"send_read_receipts",
"presence_enabled",
"email_address_visibility",
];
if (privacy_settings.includes(event.property)) {
user_settings[event.property] = event.value;
settings_account.update_privacy_settings_box(event.property);
if (event.property === "presence_enabled") {
activity_ui.redraw_user(current_user.user_id);
}
break;
}
@@ -861,17 +866,6 @@ export function dispatch_normal_event(event) {
if (event.property === "web_escape_navigates_to_home_view") {
$("#go-to-home-view-hotkey-help").toggleClass("notdisplayed", !event.value);
}
if (event.property === "presence_enabled") {
user_settings.presence_enabled = event.value;
$("#user_presence_enabled").prop("checked", user_settings.presence_enabled);
activity_ui.redraw_user(current_user.user_id);
break;
}
if (event.property === "email_address_visibility") {
user_settings.email_address_visibility = event.value;
$("#user_email_address_visibility").val(event.value);
break;
}
settings_preferences.update_page(event.property);
break;
}

View File

@@ -1117,6 +1117,7 @@ run_test("user_settings", ({override}) => {
event = event_fixtures.user_settings__presence_disabled;
user_settings.presence_enabled = true;
override(activity_ui, "redraw_user", noop);
override(settings_account, "update_privacy_settings_box", noop);
dispatch(event);
assert_same(user_settings.presence_enabled, false);