frontend: Add new user_settings module for user's settings.

We add a new user_settings module similar to page_params
module in frontend and use it to access user's personal
settings instead of page_params.
This commit is contained in:
Sahil Batra 2021-07-28 19:30:58 +05:30 committed by Tim Abbott
parent ea44b6bcc1
commit 998d710275
61 changed files with 305 additions and 298 deletions

View File

@ -7,7 +7,7 @@ const _ = require("lodash");
const {mock_esm, with_field, zrequire} = require("../zjsunit/namespace"); const {mock_esm, with_field, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip"); const blueslip = require("../zjsunit/zblueslip");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
const timerender = mock_esm("../../static/js/timerender"); const timerender = mock_esm("../../static/js/timerender");
@ -551,7 +551,7 @@ test("get_items_for_users", ({override}) => {
people.add_active_user(alice); people.add_active_user(alice);
people.add_active_user(fred); people.add_active_user(fred);
user_status.set_away(alice.user_id); user_status.set_away(alice.user_id);
page_params.emojiset = "google"; user_settings.emojiset = "google";
const status_emoji_info = { const status_emoji_info = {
emoji_name: "car", emoji_name: "car",
emoji_code: "1f697", emoji_code: "1f697",

View File

@ -9,7 +9,7 @@ const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip"); const blueslip = require("../zjsunit/zblueslip");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
const noop = () => {}; const noop = () => {};
@ -308,7 +308,7 @@ test_ui("enter_with_preview_open", ({override}) => {
$("#compose .undo_markdown_preview").show(); $("#compose .undo_markdown_preview").show();
$("#compose .preview_message_area").show(); $("#compose .preview_message_area").show();
$("#compose .markdown_preview").hide(); $("#compose .markdown_preview").hide();
page_params.enter_sends = true; user_settings.enter_sends = true;
let send_message_called = false; let send_message_called = false;
override(compose, "send_message", () => { override(compose, "send_message", () => {
send_message_called = true; send_message_called = true;
@ -320,7 +320,7 @@ test_ui("enter_with_preview_open", ({override}) => {
assert.ok($("#compose .markdown_preview").visible()); assert.ok($("#compose .markdown_preview").visible());
assert.ok(send_message_called); assert.ok(send_message_called);
page_params.enter_sends = false; user_settings.enter_sends = false;
$("#compose-textarea").trigger("blur"); $("#compose-textarea").trigger("blur");
compose.enter_with_preview_open(); compose.enter_with_preview_open();
assert.ok($("#compose-textarea").is_focused()); assert.ok($("#compose-textarea").is_focused());
@ -329,7 +329,7 @@ test_ui("enter_with_preview_open", ({override}) => {
$("#compose-textarea").val(""); $("#compose-textarea").val("");
$("#compose .preview_message_area").show(); $("#compose .preview_message_area").show();
$("#enter_sends").prop("checked", true); $("#enter_sends").prop("checked", true);
page_params.enter_sends = true; user_settings.enter_sends = true;
compose.enter_with_preview_open(); compose.enter_with_preview_open();

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {mock_esm, set_global, with_field, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
const noop = () => {}; const noop = () => {};
@ -992,7 +992,7 @@ test("initialize", ({override, mock_template}) => {
compose_textarea_typeahead_called = true; compose_textarea_typeahead_called = true;
}; };
page_params.enter_sends = false; user_settings.enter_sends = false;
ct.initialize(); ct.initialize();
@ -1044,7 +1044,7 @@ test("initialize", ({override, mock_template}) => {
event.target.id = "stream_message_recipient_topic"; event.target.id = "stream_message_recipient_topic";
$("form#send_message_form").trigger(event); $("form#send_message_form").trigger(event);
event.target.id = "compose-textarea"; event.target.id = "compose-textarea";
page_params.enter_sends = false; user_settings.enter_sends = false;
event.metaKey = true; event.metaKey = true;
let compose_finish_called = false; let compose_finish_called = false;
override(compose, "finish", () => { override(compose, "finish", () => {
@ -1056,7 +1056,7 @@ test("initialize", ({override, mock_template}) => {
event.metaKey = false; event.metaKey = false;
event.ctrlKey = true; event.ctrlKey = true;
$("form#send_message_form").trigger(event); $("form#send_message_form").trigger(event);
page_params.enter_sends = true; user_settings.enter_sends = true;
event.ctrlKey = false; event.ctrlKey = false;
event.altKey = true; event.altKey = true;
$("form#send_message_form").trigger(event); $("form#send_message_form").trigger(event);
@ -1102,7 +1102,7 @@ test("initialize", ({override, mock_template}) => {
override(channel, "patch", (params) => { override(channel, "patch", (params) => {
assert.equal(params.url, "/json/settings"); assert.equal(params.url, "/json/settings");
assert.equal(params.idempotent, true); assert.equal(params.idempotent, true);
assert.deepEqual(params.data, {enter_sends: page_params.enter_sends}); assert.deepEqual(params.data, {enter_sends: user_settings.enter_sends});
channel_patch_called = true; channel_patch_called = true;
}); });
@ -1110,7 +1110,7 @@ test("initialize", ({override, mock_template}) => {
$("#enter_sends").trigger("click"); $("#enter_sends").trigger("click");
// Now we re-run both .initialize() and the click handler, this time // Now we re-run both .initialize() and the click handler, this time
// with enter_sends: page_params.enter_sends being true // with enter_sends: user_settings.enter_sends being true
$("#enter_sends").is = () => true; $("#enter_sends").is = () => true;
$("#enter_sends").trigger("click"); $("#enter_sends").trigger("click");

View File

@ -7,7 +7,7 @@ const {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip"); const blueslip = require("../zjsunit/zblueslip");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
const noop = () => {}; const noop = () => {};
@ -649,15 +649,15 @@ run_test("typing", ({override}) => {
run_test("user_settings", ({override}) => { run_test("user_settings", ({override}) => {
settings_display.set_default_language_name = () => {}; settings_display.set_default_language_name = () => {};
let event = event_fixtures.user_settings__default_language; let event = event_fixtures.user_settings__default_language;
page_params.default_language = "en"; user_settings.default_language = "en";
override(settings_display, "update_page", noop); override(settings_display, "update_page", noop);
dispatch(event); dispatch(event);
assert_same(page_params.default_language, "fr"); assert_same(user_settings.default_language, "fr");
event = event_fixtures.user_settings__left_side_userlist; event = event_fixtures.user_settings__left_side_userlist;
page_params.left_side_userlist = false; user_settings.left_side_userlist = false;
dispatch(event); dispatch(event);
assert_same(page_params.left_side_userlist, true); assert_same(user_settings.left_side_userlist, true);
// We alias message_list.narrowed to message_lists.current // We alias message_list.narrowed to message_lists.current
// to make sure we get line coverage on re-rendering // to make sure we get line coverage on re-rendering
@ -674,31 +674,31 @@ run_test("user_settings", ({override}) => {
override(message_lists.home, "rerender", noop); override(message_lists.home, "rerender", noop);
event = event_fixtures.user_settings__twenty_four_hour_time; event = event_fixtures.user_settings__twenty_four_hour_time;
page_params.twenty_four_hour_time = false; user_settings.twenty_four_hour_time = false;
dispatch(event); dispatch(event);
assert_same(page_params.twenty_four_hour_time, true); assert_same(user_settings.twenty_four_hour_time, true);
assert_same(called, true); assert_same(called, true);
event = event_fixtures.user_settings__translate_emoticons; event = event_fixtures.user_settings__translate_emoticons;
page_params.translate_emoticons = false; user_settings.translate_emoticons = false;
dispatch(event); dispatch(event);
assert_same(page_params.translate_emoticons, true); assert_same(user_settings.translate_emoticons, true);
event = event_fixtures.user_settings__high_contrast_mode; event = event_fixtures.user_settings__high_contrast_mode;
page_params.high_contrast_mode = false; user_settings.high_contrast_mode = false;
let toggled = []; let toggled = [];
$("body").toggleClass = (cls) => { $("body").toggleClass = (cls) => {
toggled.push(cls); toggled.push(cls);
}; };
dispatch(event); dispatch(event);
assert_same(page_params.high_contrast_mode, true); assert_same(user_settings.high_contrast_mode, true);
assert_same(toggled, ["high-contrast"]); assert_same(toggled, ["high-contrast"]);
event = event_fixtures.user_settings__dense_mode; event = event_fixtures.user_settings__dense_mode;
page_params.dense_mode = false; user_settings.dense_mode = false;
toggled = []; toggled = [];
dispatch(event); dispatch(event);
assert_same(page_params.dense_mode, true); assert_same(user_settings.dense_mode, true);
assert_same(toggled, ["less_dense_mode", "more_dense_mode"]); assert_same(toggled, ["less_dense_mode", "more_dense_mode"]);
$("body").fadeOut = (secs) => { $("body").fadeOut = (secs) => {
@ -713,45 +713,45 @@ run_test("user_settings", ({override}) => {
{ {
const stub = make_stub(); const stub = make_stub();
event = event_fixtures.user_settings__color_scheme_dark; event = event_fixtures.user_settings__color_scheme_dark;
page_params.color_scheme = 1; user_settings.color_scheme = 1;
override(night_mode, "enable", stub.f); // automatically checks if called override(night_mode, "enable", stub.f); // automatically checks if called
dispatch(event); dispatch(event);
assert.equal(stub.num_calls, 1); assert.equal(stub.num_calls, 1);
assert.equal(page_params.color_scheme, 2); assert.equal(user_settings.color_scheme, 2);
} }
{ {
const stub = make_stub(); const stub = make_stub();
event = event_fixtures.user_settings__color_scheme_light; event = event_fixtures.user_settings__color_scheme_light;
page_params.color_scheme = 1; user_settings.color_scheme = 1;
override(night_mode, "disable", stub.f); // automatically checks if called override(night_mode, "disable", stub.f); // automatically checks if called
dispatch(event); dispatch(event);
assert.equal(stub.num_calls, 1); assert.equal(stub.num_calls, 1);
assert.equal(page_params.color_scheme, 3); assert.equal(user_settings.color_scheme, 3);
} }
{ {
event = event_fixtures.user_settings__default_view_recent_topics; event = event_fixtures.user_settings__default_view_recent_topics;
page_params.default_view = "all_messages"; user_settings.default_view = "all_messages";
dispatch(event); dispatch(event);
assert.equal(page_params.default_view, "recent_topics"); assert.equal(user_settings.default_view, "recent_topics");
} }
{ {
event = event_fixtures.user_settings__default_view_all_messages; event = event_fixtures.user_settings__default_view_all_messages;
page_params.default_view = "recent_topics"; user_settings.default_view = "recent_topics";
dispatch(event); dispatch(event);
assert.equal(page_params.default_view, "all_messages"); assert.equal(user_settings.default_view, "all_messages");
} }
{ {
const stub = make_stub(); const stub = make_stub();
event = event_fixtures.user_settings__color_scheme_automatic; event = event_fixtures.user_settings__color_scheme_automatic;
page_params.color_scheme = 2; user_settings.color_scheme = 2;
override(night_mode, "default_preference_checker", stub.f); // automatically checks if called override(night_mode, "default_preference_checker", stub.f); // automatically checks if called
dispatch(event); dispatch(event);
assert.equal(stub.num_calls, 1); assert.equal(stub.num_calls, 1);
assert.equal(page_params.color_scheme, 1); assert.equal(user_settings.color_scheme, 1);
} }
{ {
@ -760,42 +760,42 @@ run_test("user_settings", ({override}) => {
called = false; called = false;
override(settings_display, "report_emojiset_change", stub.f); override(settings_display, "report_emojiset_change", stub.f);
override(activity, "build_user_sidebar", noop); override(activity, "build_user_sidebar", noop);
page_params.emojiset = "text"; user_settings.emojiset = "text";
dispatch(event); dispatch(event);
assert.equal(stub.num_calls, 1); assert.equal(stub.num_calls, 1);
assert_same(called, true); assert_same(called, true);
assert_same(page_params.emojiset, "google"); assert_same(user_settings.emojiset, "google");
} }
override(starred_messages, "rerender_ui", noop); override(starred_messages, "rerender_ui", noop);
event = event_fixtures.user_settings__starred_message_counts; event = event_fixtures.user_settings__starred_message_counts;
page_params.starred_message_counts = false; user_settings.starred_message_counts = false;
dispatch(event); dispatch(event);
assert_same(page_params.starred_message_counts, true); assert_same(user_settings.starred_message_counts, true);
override(scroll_bar, "set_layout_width", noop); override(scroll_bar, "set_layout_width", noop);
event = event_fixtures.user_settings__fluid_layout_width; event = event_fixtures.user_settings__fluid_layout_width;
page_params.fluid_layout_width = false; user_settings.fluid_layout_width = false;
dispatch(event); dispatch(event);
assert_same(page_params.fluid_layout_width, true); assert_same(user_settings.fluid_layout_width, true);
{ {
const stub = make_stub(); const stub = make_stub();
event = event_fixtures.user_settings__demote_inactive_streams; event = event_fixtures.user_settings__demote_inactive_streams;
override(stream_data, "set_filter_out_inactives", noop); override(stream_data, "set_filter_out_inactives", noop);
override(stream_list, "update_streams_sidebar", stub.f); override(stream_list, "update_streams_sidebar", stub.f);
page_params.demote_inactive_streams = 1; user_settings.demote_inactive_streams = 1;
dispatch(event); dispatch(event);
assert.equal(stub.num_calls, 1); assert.equal(stub.num_calls, 1);
assert_same(page_params.demote_inactive_streams, 2); assert_same(user_settings.demote_inactive_streams, 2);
} }
override(compose, "toggle_enter_sends_ui", noop); override(compose, "toggle_enter_sends_ui", noop);
event = event_fixtures.user_settings__enter_sends; event = event_fixtures.user_settings__enter_sends;
page_params.enter_sends = false; user_settings.enter_sends = false;
dispatch(event); dispatch(event);
assert_same(page_params.enter_sends, true); assert_same(user_settings.enter_sends, true);
{ {
event = event_fixtures.user_settings__enable_stream_audible_notifications; event = event_fixtures.user_settings__enable_stream_audible_notifications;

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {mock_esm, set_global, zrequire, with_overrides} = require("../zjsunit/namespace"); const {mock_esm, set_global, zrequire, with_overrides} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const {page_params} = require("../zjsunit/zpage_params"); const {user_settings} = require("../zjsunit/zpage_params");
const ls_container = new Map(); const ls_container = new Map();
const noop = () => {}; const noop = () => {};
@ -33,7 +33,7 @@ mock_esm("../../static/js/stream_data", {
return "#FFFFFF"; return "#FFFFFF";
}, },
}); });
page_params.twenty_four_hour_time = false; user_settings.twenty_four_hour_time = false;
const {localstorage} = zrequire("localstorage"); const {localstorage} = zrequire("localstorage");
const drafts = zrequire("drafts"); const drafts = zrequire("drafts");

View File

@ -6,7 +6,7 @@ const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip"); const blueslip = require("../zjsunit/zblueslip");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const {page_params} = require("../zjsunit/zpage_params"); const {user_settings} = require("../zjsunit/zpage_params");
let window_stub; let window_stub;
set_global("location", { set_global("location", {
@ -168,7 +168,7 @@ function test_helper({override, change_tab}) {
run_test("hash_interactions", ({override}) => { run_test("hash_interactions", ({override}) => {
window_stub = $.create("window-stub"); window_stub = $.create("window-stub");
page_params.default_view = "recent_topics"; user_settings.default_view = "recent_topics";
override(recent_topics_util, "is_visible", () => false); override(recent_topics_util, "is_visible", () => false);
const helper = test_helper({override, change_tab: true}); const helper = test_helper({override, change_tab: true});

View File

@ -94,6 +94,8 @@ run_test("tr_tag", ({mock_template}) => {
full_name: "John Doe", full_name: "John Doe",
password_auth_enabled: false, password_auth_enabled: false,
avatar_url: "http://example.com", avatar_url: "http://example.com",
},
user_settings: {
left_side_userlist: false, left_side_userlist: false,
twenty_four_hour_time: false, twenty_four_hour_time: false,
enable_stream_desktop_notifications: false, enable_stream_desktop_notifications: false,

View File

@ -7,7 +7,7 @@ const markdown_assert = require("../zjsunit/markdown_assert");
const {set_global, with_field, zrequire} = require("../zjsunit/namespace"); const {set_global, with_field, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip"); const blueslip = require("../zjsunit/zblueslip");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
set_global("location", { set_global("location", {
origin: "http://zulip.zulipdev.com", origin: "http://zulip.zulipdev.com",
@ -30,7 +30,7 @@ const example_realm_linkifiers = [
id: 3, id: 3,
}, },
]; ];
page_params.translate_emoticons = false; user_settings.translate_emoticons = false;
function Image() { function Image() {
return {}; return {};
@ -254,7 +254,7 @@ test("marked_shared", () => {
} }
const message = {raw_content: test.input}; const message = {raw_content: test.input};
page_params.translate_emoticons = test.translate_emoticons || false; user_settings.translate_emoticons = test.translate_emoticons || false;
markdown.apply_markdown(message); markdown.apply_markdown(message);
const output = message.content; const output = message.content;
const error_message = `Failure in test: ${test.name}`; const error_message = `Failure in test: ${test.name}`;
@ -571,7 +571,7 @@ test("marked", () => {
for (const test_case of test_cases) { for (const test_case of test_cases) {
// Disable emoji conversion by default. // Disable emoji conversion by default.
page_params.translate_emoticons = test_case.translate_emoticons || false; user_settings.translate_emoticons = test_case.translate_emoticons || false;
const input = test_case.input; const input = test_case.input;
const expected = test_case.expected; const expected = test_case.expected;

View File

@ -6,13 +6,13 @@ const _ = require("lodash");
const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const {page_params} = require("../zjsunit/zpage_params"); const {user_settings} = require("../zjsunit/zpage_params");
set_global("document", "document-stub"); set_global("document", "document-stub");
const noop = () => {}; const noop = () => {};
page_params.twenty_four_hour_time = false; user_settings.twenty_four_hour_time = false;
mock_esm("../../static/js/message_lists", {home: "stub"}); mock_esm("../../static/js/message_lists", {home: "stub"});
@ -25,7 +25,7 @@ mock_esm("../../static/js/timerender", {
return [{outerHTML: String(time1.getTime()) + " - " + String(time2.getTime())}]; return [{outerHTML: String(time1.getTime()) + " - " + String(time2.getTime())}];
}, },
stringify_time(time) { stringify_time(time) {
if (page_params.twenty_four_hour_time) { if (user_settings.twenty_four_hour_time) {
return time.toString("HH:mm"); return time.toString("HH:mm");
} }
return time.toString("h:mm TT"); return time.toString("h:mm TT");

View File

@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
const {set_global, zrequire} = require("../zjsunit/namespace"); const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
// Dependencies // Dependencies
@ -53,10 +53,10 @@ function test(label, f) {
run_test(label, ({override}) => { run_test(label, ({override}) => {
page_params.is_admin = false; page_params.is_admin = false;
page_params.realm_users = []; page_params.realm_users = [];
page_params.enable_desktop_notifications = true; user_settings.enable_desktop_notifications = true;
page_params.enable_sounds = true; user_settings.enable_sounds = true;
page_params.wildcard_mentions_notify = true; user_settings.wildcard_mentions_notify = true;
page_params.notification_sound = "ding"; user_settings.notification_sound = "ding";
f({override}); f({override});
}); });
} }
@ -165,7 +165,7 @@ test("message_is_notifiable", () => {
assert.equal(notifications.message_is_notifiable(message), true); assert.equal(notifications.message_is_notifiable(message), true);
// But not if it's disabled // But not if it's disabled
page_params.wildcard_mentions_notify = false; user_settings.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.should_send_audible_notification(message), false);
assert.equal(notifications.message_is_notifiable(message), true); assert.equal(notifications.message_is_notifiable(message), true);
@ -177,7 +177,7 @@ test("message_is_notifiable", () => {
assert.equal(notifications.message_is_notifiable(message), true); assert.equal(notifications.message_is_notifiable(message), true);
// Reset state // Reset state
page_params.wildcard_mentions_notify = true; user_settings.wildcard_mentions_notify = true;
general.wildcard_mentions_notify = null; general.wildcard_mentions_notify = null;
// Case 6: If a message is in a muted stream // Case 6: If a message is in a muted stream
@ -251,13 +251,13 @@ test("message_is_notifiable", () => {
stream_id: general.stream_id, stream_id: general.stream_id,
topic: "whatever", topic: "whatever",
}; };
page_params.notification_sound = "none"; user_settings.notification_sound = "none";
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), 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
page_params.notification_sound = "ding"; user_settings.notification_sound = "ding";
// If none of the above cases apply // If none of the above cases apply
// (ie: topic is not muted, message does not mention user, // (ie: topic is not muted, message does not mention user,

View File

@ -10,7 +10,7 @@ const {$t} = require("../zjsunit/i18n");
const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {mock_esm, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip"); const blueslip = require("../zjsunit/zblueslip");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
const message_user_ids = mock_esm("../../static/js/message_user_ids"); const message_user_ids = mock_esm("../../static/js/message_user_ids");
@ -473,17 +473,17 @@ test_people("user_timezone", () => {
format: "H:mm", format: "H:mm",
}; };
page_params.twenty_four_hour_time = true; user_settings.twenty_four_hour_time = true;
assert.deepEqual(people.get_user_time_preferences(me.user_id), expected_pref); assert.deepEqual(people.get_user_time_preferences(me.user_id), expected_pref);
expected_pref.format = "h:mm a"; expected_pref.format = "h:mm a";
page_params.twenty_four_hour_time = false; user_settings.twenty_four_hour_time = false;
assert.deepEqual(people.get_user_time_preferences(me.user_id), expected_pref); assert.deepEqual(people.get_user_time_preferences(me.user_id), expected_pref);
page_params.twenty_four_hour_time = true; user_settings.twenty_four_hour_time = true;
assert.equal(people.get_user_time(me.user_id), "0:09"); assert.equal(people.get_user_time(me.user_id), "0:09");
page_params.twenty_four_hour_time = false; user_settings.twenty_four_hour_time = false;
assert.equal(people.get_user_time(me.user_id), "12:09 AM"); assert.equal(people.get_user_time(me.user_id), "12:09 AM");
}); });

View File

@ -6,7 +6,7 @@ const {mock_cjs, mock_esm, with_field, zrequire} = require("../zjsunit/namespace
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip"); const blueslip = require("../zjsunit/zblueslip");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const {page_params} = require("../zjsunit/zpage_params"); const {user_settings} = require("../zjsunit/zpage_params");
let clipboard_args; let clipboard_args;
class Clipboard { class Clipboard {
@ -18,7 +18,7 @@ class Clipboard {
mock_cjs("clipboard", Clipboard); mock_cjs("clipboard", Clipboard);
const realm_playground = mock_esm("../../static/js/realm_playground"); const realm_playground = mock_esm("../../static/js/realm_playground");
page_params.emojiset = "apple"; user_settings.emojiset = "apple";
const rm = zrequire("rendered_markdown"); const rm = zrequire("rendered_markdown");
const people = zrequire("people"); const people = zrequire("people");
@ -300,12 +300,12 @@ run_test("timestamp-twenty-four-hour-time", ({mock_template}) => {
$content.set_find_results("time", $array([$timestamp])); $content.set_find_results("time", $array([$timestamp]));
// We will temporarily change the 24h setting for this test. // We will temporarily change the 24h setting for this test.
with_field(page_params, "twenty_four_hour_time", true, () => { with_field(user_settings, "twenty_four_hour_time", true, () => {
rm.update_elements($content); rm.update_elements($content);
assert.equal($timestamp.html(), '<i class="fa fa-clock-o"></i>\nWed, Jul 15 2020, 20:40\n'); assert.equal($timestamp.html(), '<i class="fa fa-clock-o"></i>\nWed, Jul 15 2020, 20:40\n');
}); });
with_field(page_params, "twenty_four_hour_time", false, () => { with_field(user_settings, "twenty_four_hour_time", false, () => {
rm.update_elements($content); rm.update_elements($content);
assert.equal( assert.equal(
$timestamp.html(), $timestamp.html(),
@ -342,14 +342,14 @@ run_test("emoji", () => {
called = true; called = true;
}; };
$content.set_find_results(".emoji", $emoji); $content.set_find_results(".emoji", $emoji);
page_params.emojiset = "text"; user_settings.emojiset = "text";
rm.update_elements($content); rm.update_elements($content);
assert.ok(called); assert.ok(called);
// Set page parameters back so that test run order is independent // Set page parameters back so that test run order is independent
page_params.emojiset = "apple"; user_settings.emojiset = "apple";
}); });
run_test("spoiler-header", () => { run_test("spoiler-header", () => {

View File

@ -4,19 +4,19 @@ const {strict: assert} = require("assert");
const {zrequire} = require("../zjsunit/namespace"); const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const {page_params} = require("../zjsunit/zpage_params"); const {user_settings} = require("../zjsunit/zpage_params");
const settings_config = zrequire("settings_config"); const settings_config = zrequire("settings_config");
run_test("all_notifications", () => { run_test("all_notifications", () => {
page_params.enable_stream_desktop_notifications = false; user_settings.enable_stream_desktop_notifications = false;
page_params.enable_stream_audible_notifications = true; user_settings.enable_stream_audible_notifications = true;
page_params.enable_stream_push_notifications = true; user_settings.enable_stream_push_notifications = true;
page_params.enable_stream_email_notifications = false; user_settings.enable_stream_email_notifications = false;
page_params.enable_desktop_notifications = false; user_settings.enable_desktop_notifications = false;
page_params.enable_sounds = true; user_settings.enable_sounds = true;
page_params.enable_offline_push_notifications = false; user_settings.enable_offline_push_notifications = false;
page_params.enable_offline_email_notifications = true; user_settings.enable_offline_email_notifications = true;
// Check that it throws error if incorrect settings name // Check that it throws error if incorrect settings name
// is passed. In this case, we articulate that with // is passed. In this case, we articulate that with
@ -24,7 +24,7 @@ run_test("all_notifications", () => {
// the case, if a wrong setting_name is passed. // the case, if a wrong setting_name is passed.
assert.throws(settings_config.all_notifications, "Incorrect setting_name passed"); assert.throws(settings_config.all_notifications, "Incorrect setting_name passed");
page_params.wildcard_mentions_notify = false; user_settings.wildcard_mentions_notify = false;
const notifications = settings_config.all_notifications(); const notifications = settings_config.all_notifications();
assert.deepEqual(notifications.general_settings, [ assert.deepEqual(notifications.general_settings, [

View File

@ -4,7 +4,7 @@ const {strict: assert} = require("assert");
const {zrequire} = require("../zjsunit/namespace"); const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
const settings_data = zrequire("settings_data"); const settings_data = zrequire("settings_data");
const settings_config = zrequire("settings_config"); const settings_config = zrequire("settings_config");
@ -244,10 +244,10 @@ test_message_policy(
); );
run_test("using_dark_theme", () => { run_test("using_dark_theme", () => {
page_params.color_scheme = settings_config.color_scheme_values.night.code; user_settings.color_scheme = settings_config.color_scheme_values.night.code;
assert.equal(settings_data.using_dark_theme(), true); assert.equal(settings_data.using_dark_theme(), true);
page_params.color_scheme = settings_config.color_scheme_values.automatic.code; user_settings.color_scheme = settings_config.color_scheme_values.automatic.code;
window.matchMedia = (query) => { window.matchMedia = (query) => {
assert.equal(query, "(prefers-color-scheme: dark)"); assert.equal(query, "(prefers-color-scheme: dark)");
@ -261,7 +261,7 @@ run_test("using_dark_theme", () => {
}; };
assert.equal(settings_data.using_dark_theme(), false); assert.equal(settings_data.using_dark_theme(), false);
page_params.color_scheme = settings_config.color_scheme_values.day.code; user_settings.color_scheme = settings_config.color_scheme_values.day.code;
assert.equal(settings_data.using_dark_theme(), false); assert.equal(settings_data.using_dark_theme(), false);
}); });

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {with_overrides, zrequire} = require("../zjsunit/namespace"); const {with_overrides, zrequire} = require("../zjsunit/namespace");
const {make_stub} = require("../zjsunit/stub"); const {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
const message_store = zrequire("message_store"); const message_store = zrequire("message_store");
const starred_messages = zrequire("starred_messages"); const starred_messages = zrequire("starred_messages");
@ -95,7 +95,7 @@ run_test("rerender_ui", () => {
starred_messages.starred_ids.add(id); starred_messages.starred_ids.add(id);
} }
page_params.starred_message_counts = true; user_settings.starred_message_counts = true;
with_overrides((override) => { with_overrides((override) => {
const stub = make_stub(); const stub = make_stub();
override(stream_popover, "hide_topic_popover", () => {}); override(stream_popover, "hide_topic_popover", () => {});
@ -106,7 +106,7 @@ run_test("rerender_ui", () => {
assert.equal(args.count, 3); assert.equal(args.count, 3);
}); });
page_params.starred_message_counts = false; user_settings.starred_message_counts = false;
with_overrides((override) => { with_overrides((override) => {
const stub = make_stub(); const stub = make_stub();
override(stream_popover, "hide_topic_popover", () => {}); override(stream_popover, "hide_topic_popover", () => {});

View File

@ -7,7 +7,7 @@ const _ = require("lodash");
const {zrequire} = require("../zjsunit/namespace"); const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const blueslip = require("../zjsunit/zblueslip"); const blueslip = require("../zjsunit/zblueslip");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
const color_data = zrequire("color_data"); const color_data = zrequire("color_data");
const stream_topic_history = zrequire("stream_topic_history"); const stream_topic_history = zrequire("stream_topic_history");
@ -215,7 +215,7 @@ test("renames", () => {
test("is_active", () => { test("is_active", () => {
let sub; let sub;
page_params.demote_inactive_streams = user_settings.demote_inactive_streams =
settings_config.demote_inactive_streams_values.automatic.code; settings_config.demote_inactive_streams_values.automatic.code;
stream_data.set_filter_out_inactives(); stream_data.set_filter_out_inactives();
@ -246,7 +246,7 @@ test("is_active", () => {
assert.ok(stream_data.is_active(sub)); assert.ok(stream_data.is_active(sub));
page_params.demote_inactive_streams = user_settings.demote_inactive_streams =
settings_config.demote_inactive_streams_values.always.code; settings_config.demote_inactive_streams_values.always.code;
stream_data.set_filter_out_inactives(); stream_data.set_filter_out_inactives();
@ -274,7 +274,8 @@ test("is_active", () => {
assert.ok(stream_data.is_active(sub)); assert.ok(stream_data.is_active(sub));
page_params.demote_inactive_streams = settings_config.demote_inactive_streams_values.never.code; user_settings.demote_inactive_streams =
settings_config.demote_inactive_streams_values.never.code;
stream_data.set_filter_out_inactives(); stream_data.set_filter_out_inactives();
sub = {name: "pets", subscribed: false, stream_id: 111}; sub = {name: "pets", subscribed: false, stream_id: 111};
@ -503,13 +504,13 @@ test("notifications", () => {
assert.ok(!stream_data.receives_notifications(india.stream_id, "desktop_notifications")); assert.ok(!stream_data.receives_notifications(india.stream_id, "desktop_notifications"));
assert.ok(!stream_data.receives_notifications(india.stream_id, "audible_notifications")); assert.ok(!stream_data.receives_notifications(india.stream_id, "audible_notifications"));
page_params.enable_stream_desktop_notifications = true; user_settings.enable_stream_desktop_notifications = true;
page_params.enable_stream_audible_notifications = true; user_settings.enable_stream_audible_notifications = true;
assert.ok(stream_data.receives_notifications(india.stream_id, "desktop_notifications")); assert.ok(stream_data.receives_notifications(india.stream_id, "desktop_notifications"));
assert.ok(stream_data.receives_notifications(india.stream_id, "audible_notifications")); assert.ok(stream_data.receives_notifications(india.stream_id, "audible_notifications"));
page_params.enable_stream_desktop_notifications = false; user_settings.enable_stream_desktop_notifications = false;
page_params.enable_stream_audible_notifications = false; user_settings.enable_stream_audible_notifications = false;
assert.ok(!stream_data.receives_notifications(india.stream_id, "desktop_notifications")); assert.ok(!stream_data.receives_notifications(india.stream_id, "desktop_notifications"));
assert.ok(!stream_data.receives_notifications(india.stream_id, "audible_notifications")); assert.ok(!stream_data.receives_notifications(india.stream_id, "audible_notifications"));
@ -520,38 +521,38 @@ test("notifications", () => {
india.desktop_notifications = false; india.desktop_notifications = false;
india.audible_notifications = false; india.audible_notifications = false;
page_params.enable_stream_desktop_notifications = true; user_settings.enable_stream_desktop_notifications = true;
page_params.enable_stream_audible_notifications = true; user_settings.enable_stream_audible_notifications = true;
assert.ok(!stream_data.receives_notifications(india.stream_id, "desktop_notifications")); assert.ok(!stream_data.receives_notifications(india.stream_id, "desktop_notifications"));
assert.ok(!stream_data.receives_notifications(india.stream_id, "audible_notifications")); assert.ok(!stream_data.receives_notifications(india.stream_id, "audible_notifications"));
page_params.wildcard_mentions_notify = true; user_settings.wildcard_mentions_notify = true;
assert.ok(stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify")); assert.ok(stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify"));
page_params.wildcard_mentions_notify = false; user_settings.wildcard_mentions_notify = false;
assert.ok(!stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify")); assert.ok(!stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify"));
india.wildcard_mentions_notify = true; india.wildcard_mentions_notify = true;
assert.ok(stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify")); assert.ok(stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify"));
page_params.wildcard_mentions_notify = true; user_settings.wildcard_mentions_notify = true;
india.wildcard_mentions_notify = false; india.wildcard_mentions_notify = false;
assert.ok(!stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify")); assert.ok(!stream_data.receives_notifications(india.stream_id, "wildcard_mentions_notify"));
page_params.enable_stream_push_notifications = true; user_settings.enable_stream_push_notifications = true;
assert.ok(stream_data.receives_notifications(india.stream_id, "push_notifications")); assert.ok(stream_data.receives_notifications(india.stream_id, "push_notifications"));
page_params.enable_stream_push_notifications = false; user_settings.enable_stream_push_notifications = false;
assert.ok(!stream_data.receives_notifications(india.stream_id, "push_notifications")); assert.ok(!stream_data.receives_notifications(india.stream_id, "push_notifications"));
india.push_notifications = true; india.push_notifications = true;
assert.ok(stream_data.receives_notifications(india.stream_id, "push_notifications")); assert.ok(stream_data.receives_notifications(india.stream_id, "push_notifications"));
page_params.enable_stream_push_notifications = true; user_settings.enable_stream_push_notifications = true;
india.push_notifications = false; india.push_notifications = false;
assert.ok(!stream_data.receives_notifications(india.stream_id, "push_notifications")); assert.ok(!stream_data.receives_notifications(india.stream_id, "push_notifications"));
page_params.enable_stream_email_notifications = true; user_settings.enable_stream_email_notifications = true;
assert.ok(stream_data.receives_notifications(india.stream_id, "email_notifications")); assert.ok(stream_data.receives_notifications(india.stream_id, "email_notifications"));
page_params.enable_stream_email_notifications = false; user_settings.enable_stream_email_notifications = false;
assert.ok(!stream_data.receives_notifications(india.stream_id, "email_notifications")); assert.ok(!stream_data.receives_notifications(india.stream_id, "email_notifications"));
india.email_notifications = true; india.email_notifications = true;
assert.ok(stream_data.receives_notifications(india.stream_id, "email_notifications")); assert.ok(stream_data.receives_notifications(india.stream_id, "email_notifications"));
page_params.enable_stream_email_notifications = true; user_settings.enable_stream_email_notifications = true;
india.email_notifications = false; india.email_notifications = false;
assert.ok(!stream_data.receives_notifications(india.stream_id, "email_notifications")); assert.ok(!stream_data.receives_notifications(india.stream_id, "email_notifications"));
@ -581,11 +582,11 @@ test("notifications", () => {
}; };
stream_data.add_sub(antarctica); stream_data.add_sub(antarctica);
page_params.enable_stream_desktop_notifications = true; user_settings.enable_stream_desktop_notifications = true;
page_params.enable_stream_audible_notifications = true; user_settings.enable_stream_audible_notifications = true;
page_params.enable_stream_email_notifications = false; user_settings.enable_stream_email_notifications = false;
page_params.enable_stream_push_notifications = false; user_settings.enable_stream_push_notifications = false;
page_params.wildcard_mentions_notify = true; user_settings.wildcard_mentions_notify = true;
india.desktop_notifications = null; india.desktop_notifications = null;
india.audible_notifications = true; india.audible_notifications = true;
@ -770,7 +771,7 @@ test("initialize", () => {
stream_data.initialize(get_params()); stream_data.initialize(get_params());
} }
page_params.demote_inactive_streams = 1; user_settings.demote_inactive_streams = 1;
page_params.realm_notifications_stream_id = -1; page_params.realm_notifications_stream_id = -1;
initialize(); initialize();
@ -800,7 +801,7 @@ test("initialize", () => {
}); });
test("filter inactives", () => { test("filter inactives", () => {
page_params.demote_inactive_streams = user_settings.demote_inactive_streams =
settings_config.demote_inactive_streams_values.automatic.code; settings_config.demote_inactive_streams_values.automatic.code;
const params = {}; const params = {};

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {mock_esm, zrequire} = require("../zjsunit/namespace"); const {mock_esm, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
const noop = () => {}; const noop = () => {};
@ -295,7 +295,7 @@ test_ui("subscriber_pills", ({override, mock_template}) => {
const {stream_notification_settings, pm_mention_notification_settings} = settings_config; const {stream_notification_settings, pm_mention_notification_settings} = settings_config;
for (const setting of [...stream_notification_settings, ...pm_mention_notification_settings]) { for (const setting of [...stream_notification_settings, ...pm_mention_notification_settings]) {
page_params[setting] = true; user_settings[setting] = true;
} }
stream_row_handler.call(fake_this, event); stream_row_handler.call(fake_this, event);

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace"); const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
set_global("document", "document-stub"); set_global("document", "document-stub");
@ -95,7 +95,7 @@ function test_ui(label, f) {
test_ui("create_sidebar_row", ({override, mock_template}) => { test_ui("create_sidebar_row", ({override, mock_template}) => {
// Make a couple calls to create_sidebar_row() and make sure they // Make a couple calls to create_sidebar_row() and make sure they
// generate the right markup as well as play nice with get_stream_li(). // generate the right markup as well as play nice with get_stream_li().
page_params.demote_inactive_streams = 1; user_settings.demote_inactive_streams = 1;
override(unread, "num_unread_for_stream", () => num_unread_for_stream); override(unread, "num_unread_for_stream", () => num_unread_for_stream);
stream_data.add_sub(devel); stream_data.add_sub(devel);

View File

@ -9,9 +9,9 @@ const {$t} = require("../zjsunit/i18n");
const {zrequire} = require("../zjsunit/namespace"); const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const {page_params} = require("../zjsunit/zpage_params"); const {user_settings} = require("../zjsunit/zpage_params");
page_params.twenty_four_hour_time = true; user_settings.twenty_four_hour_time = true;
const timerender = zrequire("timerender"); const timerender = zrequire("timerender");
@ -179,7 +179,7 @@ run_test("get_timestamp_for_flatpickr", () => {
}); });
run_test("absolute_time_12_hour", () => { run_test("absolute_time_12_hour", () => {
page_params.twenty_four_hour_time = false; user_settings.twenty_four_hour_time = false;
// timestamp with hour > 12, same year // timestamp with hour > 12, same year
let timestamp = 1555091573000; // 4/12/2019 5:52:53 PM (UTC+0) let timestamp = 1555091573000; // 4/12/2019 5:52:53 PM (UTC+0)
@ -209,7 +209,7 @@ run_test("absolute_time_12_hour", () => {
}); });
run_test("absolute_time_24_hour", () => { run_test("absolute_time_24_hour", () => {
page_params.twenty_four_hour_time = true; user_settings.twenty_four_hour_time = true;
// timestamp with hour > 12, same year // timestamp with hour > 12, same year
let timestamp = 1555091573000; // 4/12/2019 5:52:53 PM (UTC+0) let timestamp = 1555091573000; // 4/12/2019 5:52:53 PM (UTC+0)
@ -244,11 +244,11 @@ run_test("get_full_datetime", () => {
assert.equal(timerender.get_full_datetime(time), expected); assert.equal(timerender.get_full_datetime(time), expected);
// test 24 hour time setting. // test 24 hour time setting.
page_params.twenty_four_hour_time = true; user_settings.twenty_four_hour_time = true;
expected = "translated: 5/18/2017 at 21:12:53 UTC"; expected = "translated: 5/18/2017 at 21:12:53 UTC";
assert.equal(timerender.get_full_datetime(time), expected); assert.equal(timerender.get_full_datetime(time), expected);
page_params.twenty_four_hour_time = false; user_settings.twenty_four_hour_time = false;
// Test the GMT[+-]x:y logic. // Test the GMT[+-]x:y logic.
const previous_env_tz = process.env.TZ; const previous_env_tz = process.env.TZ;
@ -316,18 +316,18 @@ run_test("last_seen_status_from_date", () => {
run_test("set_full_datetime", () => { run_test("set_full_datetime", () => {
let time = new Date(1549958107000); // Tuesday 2/12/2019 07:55:07 AM (UTC+0) let time = new Date(1549958107000); // Tuesday 2/12/2019 07:55:07 AM (UTC+0)
page_params.twenty_four_hour_time = true; user_settings.twenty_four_hour_time = true;
let time_str = timerender.stringify_time(time); let time_str = timerender.stringify_time(time);
let expected = "07:55"; let expected = "07:55";
assert.equal(time_str, expected); assert.equal(time_str, expected);
page_params.twenty_four_hour_time = false; user_settings.twenty_four_hour_time = false;
time_str = timerender.stringify_time(time); time_str = timerender.stringify_time(time);
expected = "7:55 AM"; expected = "7:55 AM";
assert.equal(time_str, expected); assert.equal(time_str, expected);
time = new Date(1549979707000); // Tuesday 2/12/2019 13:55:07 PM (UTC+0) time = new Date(1549979707000); // Tuesday 2/12/2019 13:55:07 PM (UTC+0)
page_params.twenty_four_hour_time = false; user_settings.twenty_four_hour_time = false;
time_str = timerender.stringify_time(time); time_str = timerender.stringify_time(time);
expected = "1:55 PM"; expected = "1:55 PM";
assert.equal(time_str, expected); assert.equal(time_str, expected);

View File

@ -6,7 +6,7 @@ const _ = require("lodash");
const {zrequire} = require("../zjsunit/namespace"); const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const {page_params} = require("../zjsunit/zpage_params"); const {page_params, user_settings} = require("../zjsunit/zpage_params");
page_params.realm_push_notifications_enabled = false; page_params.realm_push_notifications_enabled = false;
@ -43,13 +43,13 @@ function assert_zero_counts(counts) {
} }
function test_notifiable_count(home_unread_messages, expected_notifiable_count) { function test_notifiable_count(home_unread_messages, expected_notifiable_count) {
page_params.desktop_icon_count_display = 1; user_settings.desktop_icon_count_display = 1;
let notifiable_counts = unread.get_notifiable_count(); let notifiable_counts = unread.get_notifiable_count();
assert.deepEqual(notifiable_counts, home_unread_messages); assert.deepEqual(notifiable_counts, home_unread_messages);
page_params.desktop_icon_count_display = 2; user_settings.desktop_icon_count_display = 2;
notifiable_counts = unread.get_notifiable_count(); notifiable_counts = unread.get_notifiable_count();
assert.deepEqual(notifiable_counts, expected_notifiable_count); assert.deepEqual(notifiable_counts, expected_notifiable_count);
page_params.desktop_icon_count_display = 3; user_settings.desktop_icon_count_display = 3;
notifiable_counts = unread.get_notifiable_count(); notifiable_counts = unread.get_notifiable_count();
assert.deepEqual(notifiable_counts, 0); assert.deepEqual(notifiable_counts, 0);
} }

View File

@ -100,6 +100,8 @@ try {
require("../../static/js/i18n"); require("../../static/js/i18n");
namespace.mock_esm("../../static/js/page_params", zpage_params); namespace.mock_esm("../../static/js/page_params", zpage_params);
require("../../static/js/page_params"); require("../../static/js/page_params");
namespace.mock_esm("../../static/js/user_settings", zpage_params);
require("../../static/js/user_settings");
run_one_module(file); run_one_module(file);

View File

@ -1,6 +1,7 @@
"use strict"; "use strict";
exports.page_params = {}; exports.page_params = {};
exports.user_settings = {};
exports.reset = () => { exports.reset = () => {
for (const field in exports.page_params) { for (const field in exports.page_params) {
@ -8,4 +9,9 @@ exports.reset = () => {
delete exports.page_params[field]; delete exports.page_params[field];
} }
} }
for (const field in exports.user_settings) {
if (Object.prototype.hasOwnProperty.call(exports.user_settings, field)) {
delete exports.user_settings[field];
}
}
}; };

View File

@ -33,6 +33,7 @@ import * as sub_store from "./sub_store";
import * as transmit from "./transmit"; import * as transmit from "./transmit";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as upload from "./upload"; import * as upload from "./upload";
import {user_settings} from "./user_settings";
import * as util from "./util"; import * as util from "./util";
import * as zcommand from "./zcommand"; import * as zcommand from "./zcommand";
@ -120,7 +121,7 @@ export function empty_topic_placeholder() {
export function toggle_enter_sends_ui() { export function toggle_enter_sends_ui() {
const send_button = $("#compose-send-button"); const send_button = $("#compose-send-button");
if (page_params.enter_sends) { if (user_settings.enter_sends) {
send_button.fadeOut(); send_button.fadeOut();
} else { } else {
send_button.fadeIn(); send_button.fadeIn();
@ -260,7 +261,7 @@ export function send_message(request = create_message_object()) {
} }
export function enter_with_preview_open() { export function enter_with_preview_open() {
if (page_params.enter_sends) { if (user_settings.enter_sends) {
// If enter_sends is enabled, we attempt to send the message // If enter_sends is enabled, we attempt to send the message
finish(); finish();
} else { } else {

View File

@ -17,6 +17,7 @@ import * as people from "./people";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import {user_settings} from "./user_settings";
import * as util from "./util"; import * as util from "./util";
let user_acknowledged_all_everyone = false; let user_acknowledged_all_everyone = false;
@ -650,7 +651,7 @@ export function validate() {
if (/^\s*$/.test(message_content)) { if (/^\s*$/.test(message_content)) {
// Avoid showing an error message when "enter sends" is enabled, // Avoid showing an error message when "enter sends" is enabled,
// as it is more likely that the user has hit "Enter" accidentally. // as it is more likely that the user has hit "Enter" accidentally.
if (!page_params.enter_sends) { if (!user_settings.enter_sends) {
compose_error.show( compose_error.show(
$t_html({defaultMessage: "You have nothing to send!"}), $t_html({defaultMessage: "You have nothing to send!"}),
$("#compose-textarea"), $("#compose-textarea"),

View File

@ -27,6 +27,7 @@ import * as timerender from "./timerender";
import * as typeahead_helper from "./typeahead_helper"; import * as typeahead_helper from "./typeahead_helper";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";
import * as user_pill from "./user_pill"; import * as user_pill from "./user_pill";
import {user_settings} from "./user_settings";
// ********************************** // **********************************
// AN IMPORTANT NOTE ABOUT TYPEAHEADS // AN IMPORTANT NOTE ABOUT TYPEAHEADS
@ -137,7 +138,7 @@ export function should_enter_send(e) {
const has_non_shift_modifier_key = e.ctrlKey || e.metaKey || e.altKey; const has_non_shift_modifier_key = e.ctrlKey || e.metaKey || e.altKey;
const has_modifier_key = e.shiftKey || has_non_shift_modifier_key; const has_modifier_key = e.shiftKey || has_non_shift_modifier_key;
let this_enter_sends; let this_enter_sends;
if (page_params.enter_sends) { if (user_settings.enter_sends) {
// With the enter_sends setting, we should send // With the enter_sends setting, we should send
// the message unless the user was holding a // the message unless the user was holding a
// modifier key. // modifier key.
@ -1092,7 +1093,7 @@ export function initialize() {
$("form#send_message_form").on("keyup", handle_keyup); $("form#send_message_form").on("keyup", handle_keyup);
$("#enter_sends").on("click", () => { $("#enter_sends").on("click", () => {
page_params.enter_sends = $("#enter_sends").is(":checked"); user_settings.enter_sends = $("#enter_sends").is(":checked");
compose.toggle_enter_sends_ui(); compose.toggle_enter_sends_ui();
// Refocus in the content box so you can continue typing or // Refocus in the content box so you can continue typing or
@ -1102,11 +1103,11 @@ export function initialize() {
return channel.patch({ return channel.patch({
url: "/json/settings", url: "/json/settings",
idempotent: true, idempotent: true,
data: {enter_sends: page_params.enter_sends}, data: {enter_sends: user_settings.enter_sends},
}); });
}); });
$("#enter_sends").prop("checked", page_params.enter_sends); $("#enter_sends").prop("checked", user_settings.enter_sends);
if (page_params.enter_sends) { if (user_settings.enter_sends) {
$("#compose-send-button").hide(); $("#compose-send-button").hide();
} }

View File

@ -12,11 +12,11 @@ import * as blueslip from "./blueslip";
import * as compose_ui from "./compose_ui"; import * as compose_ui from "./compose_ui";
import * as message_lists from "./message_lists"; import * as message_lists from "./message_lists";
import * as message_store from "./message_store"; import * as message_store from "./message_store";
import {page_params} from "./page_params";
import * as popovers from "./popovers"; import * as popovers from "./popovers";
import * as reactions from "./reactions"; import * as reactions from "./reactions";
import * as rows from "./rows"; import * as rows from "./rows";
import * as ui from "./ui"; import * as ui from "./ui";
import {user_settings} from "./user_settings";
import * as user_status_ui from "./user_status_ui"; import * as user_status_ui from "./user_status_ui";
// Emoji picker is of fixed width and height. Update these // Emoji picker is of fixed width and height. Update these
@ -785,7 +785,10 @@ export function register_click_handlers() {
e.stopPropagation(); e.stopPropagation();
hide_emoji_popover(); hide_emoji_popover();
const emoji_name = $(this).attr("data-emoji-name"); const emoji_name = $(this).attr("data-emoji-name");
let emoji_info = {emoji_name, emoji_alt_code: page_params.emojiset === "text"}; let emoji_info = {
emoji_name,
emoji_alt_code: user_settings.emojiset === "text",
};
if (!emoji_info.emoji_alt_code) { if (!emoji_info.emoji_alt_code) {
emoji_info = {...emoji_info, ...emoji.get_emoji_details_by_name(emoji_name)}; emoji_info = {...emoji_info, ...emoji.get_emoji_details_by_name(emoji_name)};
} }

View File

@ -4,7 +4,7 @@ import twitter_sheet from "emoji-datasource-twitter/img/twitter/sheets-256/64.pn
import octopus_url from "../generated/emoji/images-google-64/1f419.png"; import octopus_url from "../generated/emoji/images-google-64/1f419.png";
import {page_params} from "./page_params"; import {user_settings} from "./user_settings";
import google_blob_css from "!style-loader?injectType=lazyStyleTag!css-loader!../generated/emoji-styles/google-blob-sprite.css"; import google_blob_css from "!style-loader?injectType=lazyStyleTag!css-loader!../generated/emoji-styles/google-blob-sprite.css";
import google_css from "!style-loader?injectType=lazyStyleTag!css-loader!../generated/emoji-styles/google-sprite.css"; import google_css from "!style-loader?injectType=lazyStyleTag!css-loader!../generated/emoji-styles/google-sprite.css";
@ -41,7 +41,7 @@ export async function select(name) {
} }
export function initialize() { export function initialize() {
select(page_params.emojiset); select(user_settings.emojiset);
// Load the octopus image in the background, so that the browser // Load the octopus image in the background, so that the browser
// will cache it for later use. Note that we hardcode the octopus // will cache it for later use. Note that we hardcode the octopus

View File

@ -24,6 +24,7 @@ import * as settings_toggle from "./settings_toggle";
import * as stream_settings_ui from "./stream_settings_ui"; import * as stream_settings_ui from "./stream_settings_ui";
import * as top_left_corner from "./top_left_corner"; import * as top_left_corner from "./top_left_corner";
import * as ui_util from "./ui_util"; import * as ui_util from "./ui_util";
import {user_settings} from "./user_settings";
// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html // Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html
// or locally: docs/subsystems/hashchange-system.md // or locally: docs/subsystems/hashchange-system.md
@ -105,9 +106,9 @@ function show_default_view() {
// //
// We only allow all_messages and recent_topics // We only allow all_messages and recent_topics
// to be rendered without a hash. // to be rendered without a hash.
if (page_params.default_view === "recent_topics") { if (user_settings.default_view === "recent_topics") {
recent_topics_ui.show(); recent_topics_ui.show();
} else if (page_params.default_view === "all_messages") { } else if (user_settings.default_view === "all_messages") {
show_all_message_view(); show_all_message_view();
} else { } else {
// NOTE: Setting a hash which is not rendered on // NOTE: Setting a hash which is not rendered on
@ -116,7 +117,7 @@ function show_default_view() {
// go back in browser history. See // go back in browser history. See
// https://chat.zulip.org/#narrow/stream/9-issues/topic/Browser.20back.20button.20on.20RT // https://chat.zulip.org/#narrow/stream/9-issues/topic/Browser.20back.20button.20on.20RT
// for detailed description of the issue. // for detailed description of the issue.
window.location.hash = page_params.default_view; window.location.hash = user_settings.default_view;
} }
} }

View File

@ -1,8 +1,8 @@
import * as hash_util from "./hash_util"; import * as hash_util from "./hash_util";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";
import {user_settings} from "./user_settings";
/* /*
This config is in a separate file for partly This config is in a separate file for partly
@ -44,5 +44,5 @@ export const get_helpers = () => ({
stream_topic_hash: hash_util.by_stream_topic_uri, stream_topic_hash: hash_util.by_stream_topic_uri,
// settings // settings
should_translate_emoticons: () => page_params.translate_emoticons, should_translate_emoticons: () => user_settings.translate_emoticons,
}); });

View File

@ -23,6 +23,7 @@ import * as stream_ui_updates from "./stream_ui_updates";
import * as ui from "./ui"; import * as ui from "./ui";
import * as unread from "./unread"; import * as unread from "./unread";
import * as unread_ops from "./unread_ops"; import * as unread_ops from "./unread_ops";
import {user_settings} from "./user_settings";
const notice_memory = new Map(); const notice_memory = new Map();
@ -91,7 +92,7 @@ export function initialize() {
} }
function update_notification_sound_source() { function update_notification_sound_source() {
const notification_sound = page_params.notification_sound; const notification_sound = user_settings.notification_sound;
const audio_file_without_extension = "/static/audio/notification_sounds/" + notification_sound; const audio_file_without_extension = "/static/audio/notification_sounds/" + notification_sound;
$("#notification-sound-source-ogg").attr("src", `${audio_file_without_extension}.ogg`); $("#notification-sound-source-ogg").attr("src", `${audio_file_without_extension}.ogg`);
$("#notification-sound-source-mp3").attr("src", `${audio_file_without_extension}.mp3`); $("#notification-sound-source-mp3").attr("src", `${audio_file_without_extension}.mp3`);
@ -233,8 +234,8 @@ export function process_notification(notification) {
if (message.type === "private" || message.type === "test-notification") { if (message.type === "private" || message.type === "test-notification") {
if ( if (
page_params.pm_content_in_desktop_notifications !== undefined && user_settings.pm_content_in_desktop_notifications !== undefined &&
!page_params.pm_content_in_desktop_notifications !user_settings.pm_content_in_desktop_notifications
) { ) {
content = "New private message from " + message.sender_full_name; content = "New private message from " + message.sender_full_name;
} }
@ -390,7 +391,7 @@ export function should_send_desktop_notification(message) {
// enable_desktop_notifications determines whether we pop up a // enable_desktop_notifications determines whether we pop up a
// notification for PMs/mentions/alerts // notification for PMs/mentions/alerts
if (!page_params.enable_desktop_notifications) { if (!user_settings.enable_desktop_notifications) {
return false; return false;
} }
@ -422,7 +423,7 @@ export function should_send_desktop_notification(message) {
export function should_send_audible_notification(message) { export function should_send_audible_notification(message) {
// If `None` is selected as the notification sound, never send // If `None` is selected as the notification sound, never send
// audible notifications regardless of other configuration. // audible notifications regardless of other configuration.
if (page_params.notification_sound === "none") { if (user_settings.notification_sound === "none") {
return false; return false;
} }
@ -436,7 +437,7 @@ export function should_send_audible_notification(message) {
} }
// enable_sounds determines whether we ding for PMs/mentions/alerts // enable_sounds determines whether we ding for PMs/mentions/alerts
if (!page_params.enable_sounds) { if (!user_settings.enable_sounds) {
return false; return false;
} }
@ -692,7 +693,7 @@ export function handle_global_notification_updates(notification_name, setting) {
// for a given message. These settings do not affect whether or not a // for a given message. These settings do not affect whether or not a
// particular stream should receive notifications. // particular stream should receive notifications.
if (settings_config.all_notification_settings.includes(notification_name)) { if (settings_config.all_notification_settings.includes(notification_name)) {
page_params[notification_name] = setting; user_settings[notification_name] = setting;
} }
if (settings_config.stream_notification_settings.includes(notification_name)) { if (settings_config.stream_notification_settings.includes(notification_name)) {

View File

@ -2,15 +2,6 @@ import $ from "jquery";
const t1 = performance.now(); const t1 = performance.now();
export const page_params: { export const page_params: {
color_scheme: number;
enable_desktop_notifications: boolean;
enable_offline_email_notifications: boolean;
enable_offline_push_notifications: boolean;
enable_sounds: boolean;
enable_stream_audible_notifications: boolean;
enable_stream_desktop_notifications: boolean;
enable_stream_email_notifications: boolean;
enable_stream_push_notifications: boolean;
language_list: { language_list: {
code: string; code: string;
locale: string; locale: string;
@ -38,8 +29,6 @@ export const page_params: {
server_avatar_changes_disabled: boolean; server_avatar_changes_disabled: boolean;
server_name_changes_disabled: boolean; server_name_changes_disabled: boolean;
translation_data: Record<string, string>; translation_data: Record<string, string>;
twenty_four_hour_time: boolean;
wildcard_mentions_notify: boolean;
zulip_plan_is_not_limited: boolean; zulip_plan_is_not_limited: boolean;
} = $("#page-params").remove().data("params"); } = $("#page-params").remove().data("params");
const t2 = performance.now(); const t2 = performance.now();

View File

@ -12,6 +12,7 @@ import * as message_lists from "./message_lists";
import * as message_store from "./message_store"; import * as message_store from "./message_store";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import {user_settings} from "./user_settings";
export const view = {}; // function namespace export const view = {}; // function namespace
@ -325,7 +326,7 @@ view.insert_new_reaction = function (opts) {
context.count = 1; context.count = 1;
context.label = new_label; context.label = new_label;
context.local_id = get_local_reaction_id(opts); context.local_id = get_local_reaction_id(opts);
context.emoji_alt_code = page_params.emojiset === "text"; context.emoji_alt_code = user_settings.emojiset === "text";
if (opts.user_id === page_params.user_id) { if (opts.user_id === page_params.user_id) {
context.class = "message_reaction reacted"; context.class = "message_reaction reacted";
@ -519,7 +520,7 @@ export function add_clean_reaction(opts) {
r.user_ids = opts.user_ids; r.user_ids = opts.user_ids;
update_user_fields(r); update_user_fields(r);
r.emoji_alt_code = page_params.emojiset === "text"; r.emoji_alt_code = user_settings.emojiset === "text";
if (r.reaction_type !== "unicode_emoji") { if (r.reaction_type !== "unicode_emoji") {
r.is_realm_emoji = true; r.is_realm_emoji = true;

View File

@ -8,13 +8,13 @@ import view_code_in_playground from "../templates/view_code_in_playground.hbs";
import * as blueslip from "./blueslip"; import * as blueslip from "./blueslip";
import {$t, $t_html} from "./i18n"; import {$t, $t_html} from "./i18n";
import {page_params} from "./page_params";
import * as people from "./people"; import * as people from "./people";
import * as realm_playground from "./realm_playground"; import * as realm_playground from "./realm_playground";
import * as rtl from "./rtl"; import * as rtl from "./rtl";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as timerender from "./timerender"; import * as timerender from "./timerender";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";
import {user_settings} from "./user_settings";
/* /*
rendered_markdown rendered_markdown
@ -236,8 +236,8 @@ export const update_elements = (content) => {
}); });
// Display emoji (including realm emoji) as text if // Display emoji (including realm emoji) as text if
// page_params.emojiset is 'text'. // user_settings.emojiset is 'text'.
if (page_params.emojiset === "text") { if (user_settings.emojiset === "text") {
content.find(".emoji").replaceWith(function () { content.find(".emoji").replaceWith(function () {
const text = $(this).attr("title"); const text = $(this).attr("title");
return ":" + text + ":"; return ":" + text + ":";

View File

@ -7,9 +7,9 @@ import * as message_lists from "./message_lists";
import * as message_viewport from "./message_viewport"; import * as message_viewport from "./message_viewport";
import * as navbar_alerts from "./navbar_alerts"; import * as navbar_alerts from "./navbar_alerts";
import * as navigate from "./navigate"; import * as navigate from "./navigate";
import {page_params} from "./page_params";
import * as popovers from "./popovers"; import * as popovers from "./popovers";
import * as ui from "./ui"; import * as ui from "./ui";
import {user_settings} from "./user_settings";
import * as util from "./util"; import * as util from "./util";
let narrow_window = false; let narrow_window = false;
@ -206,7 +206,7 @@ export function resize_stream_filters_container(h) {
export function resize_sidebars() { export function resize_sidebars() {
let sidebar; let sidebar;
if (page_params.left_side_userlist) { if (user_settings.left_side_userlist) {
const css_narrow_mode = message_viewport.is_narrow(); const css_narrow_mode = message_viewport.is_narrow();
$("#top_navbar").removeClass("rightside-userlist"); $("#top_navbar").removeClass("rightside-userlist");

View File

@ -1,7 +1,7 @@
import $ from "jquery"; import $ from "jquery";
import {media_breakpoints} from "./css_variables"; import {media_breakpoints} from "./css_variables";
import {page_params} from "./page_params"; import {user_settings} from "./user_settings";
// A few of our width properties in Zulip depend on the width of the // A few of our width properties in Zulip depend on the width of the
// browser scrollbar that is generated at the far right side of the // browser scrollbar that is generated at the far right side of the
@ -84,7 +84,7 @@ export function set_layout_width() {
// content when reloading a Zulip browser window. More details // content when reloading a Zulip browser window. More details
// are available in the comments on the max-width of 1400px in // are available in the comments on the max-width of 1400px in
// the .app-main CSS rules. // the .app-main CSS rules.
if (page_params.fluid_layout_width) { if (user_settings.fluid_layout_width) {
$(".header-main").css("max-width", "inherit"); $(".header-main").css("max-width", "inherit");
$(".app .app-main").css("max-width", "inherit"); $(".app .app-main").css("max-width", "inherit");
$(".fixed-app .app-main").css("max-width", "inherit"); $(".fixed-app .app-main").css("max-width", "inherit");

View File

@ -63,6 +63,7 @@ import * as typing_events from "./typing_events";
import * as unread_ops from "./unread_ops"; import * as unread_ops from "./unread_ops";
import * as user_events from "./user_events"; import * as user_events from "./user_events";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";
import {user_settings} from "./user_settings";
import * as user_status from "./user_status"; import * as user_status from "./user_status";
export function dispatch_normal_event(event) { export function dispatch_normal_event(event) {
@ -566,7 +567,7 @@ export function dispatch_normal_event(event) {
"starred_message_counts", "starred_message_counts",
]; ];
if (user_display_settings.includes(event.property)) { if (user_display_settings.includes(event.property)) {
page_params[event.property] = event.value; user_settings[event.property] = event.value;
} }
if (event.property === "default_language") { if (event.property === "default_language") {
// We additionally need to set the language name. // We additionally need to set the language name.
@ -640,8 +641,8 @@ export function dispatch_normal_event(event) {
activity.build_user_sidebar(); activity.build_user_sidebar();
} }
if (event.property === "enter_sends") { if (event.property === "enter_sends") {
page_params.enter_sends = event.value; user_settings.enter_sends = event.value;
$("#enter_sends").prop("checked", page_params.enter_sends); $("#enter_sends").prop("checked", user_settings.enter_sends);
compose.toggle_enter_sends_ui(); compose.toggle_enter_sends_ui();
break; break;
} }

View File

@ -20,6 +20,7 @@ import * as settings_display from "./settings_display";
import * as settings_panel_menu from "./settings_panel_menu"; import * as settings_panel_menu from "./settings_panel_menu";
import * as settings_sections from "./settings_sections"; import * as settings_sections from "./settings_sections";
import * as settings_toggle from "./settings_toggle"; import * as settings_toggle from "./settings_toggle";
import {user_settings} from "./user_settings";
export let settings_label; export let settings_label;
@ -102,7 +103,7 @@ export function build_page() {
date_joined_text: get_parsed_date_of_joining(), date_joined_text: get_parsed_date_of_joining(),
page_params, page_params,
enable_sound_select: enable_sound_select:
page_params.enable_sounds || page_params.enable_stream_audible_notifications, user_settings.enable_sounds || user_settings.enable_stream_audible_notifications,
zuliprc: "zuliprc", zuliprc: "zuliprc",
botserverrc: "botserverrc", botserverrc: "botserverrc",
timezones: timezones.timezones, timezones: timezones.timezones,
@ -122,7 +123,8 @@ export function build_page() {
user_can_change_avatar: settings_data.user_can_change_avatar(), user_can_change_avatar: settings_data.user_can_change_avatar(),
user_role_text: people.get_user_type(page_params.user_id), user_role_text: people.get_user_type(page_params.user_id),
default_language_name: settings_display.default_language_name, default_language_name: settings_display.default_language_name,
language_list_dbl_col: get_language_list_columns(page_params.default_language), language_list_dbl_col: get_language_list_columns(user_settings.default_language),
user_settings,
}); });
$(".settings-box").html(rendered_settings_tab); $(".settings-box").html(rendered_settings_tab);

View File

@ -25,6 +25,7 @@ import * as setup from "./setup";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as user_pill from "./user_pill"; import * as user_pill from "./user_pill";
import * as user_profile from "./user_profile"; import * as user_profile from "./user_profile";
import {user_settings} from "./user_settings";
let password_quality; // Loaded asynchronously let password_quality; // Loaded asynchronously
@ -666,7 +667,7 @@ export function set_up() {
avatar.build_user_avatar_widget(upload_avatar); avatar.build_user_avatar_widget(upload_avatar);
$("#user_timezone").val(page_params.timezone); $("#user_timezone").val(user_settings.timezone);
$("#user_timezone").on("change", function (e) { $("#user_timezone").on("change", function (e) {
e.preventDefault(); e.preventDefault();
@ -682,7 +683,7 @@ export function set_up() {
); );
}); });
$("#presence_enabled").val(page_params.presence_enabled); $("#presence_enabled").val(user_settings.presence_enabled);
$("#presence_enabled").on("change", (e) => { $("#presence_enabled").on("change", (e) => {
e.preventDefault(); e.preventDefault();

View File

@ -1,5 +1,6 @@
import {$t} from "./i18n"; import {$t} from "./i18n";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import {user_settings} from "./user_settings";
/* /*
This file contains translations between the integer values used in This file contains translations between the integer values used in
@ -385,7 +386,7 @@ export const stream_specific_notification_settings = [
"wildcard_mentions_notify", "wildcard_mentions_notify",
]; ];
type PageParamsItem = keyof typeof page_params; type PageParamsItem = keyof typeof user_settings;
export const stream_notification_settings: PageParamsItem[] = [ export const stream_notification_settings: PageParamsItem[] = [
"enable_stream_desktop_notifications", "enable_stream_desktop_notifications",
"enable_stream_audible_notifications", "enable_stream_audible_notifications",
@ -444,7 +445,7 @@ export function get_notifications_table_row_data(
}; };
} }
const checked = page_params[setting_name]; const checked = user_settings[setting_name];
if (typeof checked !== "boolean") { if (typeof checked !== "boolean") {
throw new TypeError(`Incorrect setting_name passed: ${setting_name}`); throw new TypeError(`Incorrect setting_name passed: ${setting_name}`);
} }

View File

@ -1,5 +1,6 @@
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import {user_settings} from "./user_settings";
let user_join_date: Date; let user_join_date: Date;
export function initialize(current_user_join_date: Date): void { export function initialize(current_user_join_date: Date): void {
@ -75,7 +76,7 @@ export function get_time_preferences(user_timezone: string): {
timezone: string; timezone: string;
format: string; format: string;
} { } {
if (page_params.twenty_four_hour_time) { if (user_settings.twenty_four_hour_time) {
return { return {
timezone: user_timezone, timezone: user_timezone,
format: "H:mm", format: "H:mm",
@ -192,12 +193,12 @@ export function user_can_edit_topic_of_any_message(): boolean {
} }
export function using_dark_theme(): boolean { export function using_dark_theme(): boolean {
if (page_params.color_scheme === settings_config.color_scheme_values.night.code) { if (user_settings.color_scheme === settings_config.color_scheme_values.night.code) {
return true; return true;
} }
if ( if (
page_params.color_scheme === settings_config.color_scheme_values.automatic.code && user_settings.color_scheme === settings_config.color_scheme_values.automatic.code &&
window.matchMedia && window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches window.matchMedia("(prefers-color-scheme: dark)").matches
) { ) {

View File

@ -5,10 +5,10 @@ import * as emojisets from "./emojisets";
import {$t_html, get_language_name} from "./i18n"; import {$t_html, get_language_name} from "./i18n";
import * as loading from "./loading"; import * as loading from "./loading";
import * as overlays from "./overlays"; import * as overlays from "./overlays";
import {page_params} from "./page_params";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_ui from "./settings_ui"; import * as settings_ui from "./settings_ui";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import {user_settings} from "./user_settings";
const meta = { const meta = {
loaded: false, loaded: false,
@ -42,15 +42,15 @@ export function set_up() {
meta.loaded = true; meta.loaded = true;
$("#display-settings-status").hide(); $("#display-settings-status").hide();
$("#demote_inactive_streams").val(page_params.demote_inactive_streams); $("#demote_inactive_streams").val(user_settings.demote_inactive_streams);
$("#color_scheme").val(page_params.color_scheme); $("#color_scheme").val(user_settings.color_scheme);
$("#default_view").val(page_params.default_view); $("#default_view").val(user_settings.default_view);
$("#twenty_four_hour_time").val(JSON.stringify(page_params.twenty_four_hour_time)); $("#twenty_four_hour_time").val(JSON.stringify(user_settings.twenty_four_hour_time));
$(`.emojiset_choice[value="${CSS.escape(page_params.emojiset)}"]`).prop("checked", true); $(`.emojiset_choice[value="${CSS.escape(user_settings.emojiset)}"]`).prop("checked", true);
$("#default_language_modal [data-dismiss]").on("click", () => { $("#default_language_modal [data-dismiss]").on("click", () => {
overlays.close_modal("#default_language_modal"); overlays.close_modal("#default_language_modal");
@ -139,7 +139,7 @@ export function set_up() {
$(".emojiset_choice").on("click", function () { $(".emojiset_choice").on("click", function () {
const data = {emojiset: $(this).val()}; const data = {emojiset: $(this).val()};
const current_emojiset = page_params.emojiset; const current_emojiset = user_settings.emojiset;
if (current_emojiset === data.emojiset) { if (current_emojiset === data.emojiset) {
return; return;
} }
@ -174,11 +174,11 @@ export async function report_emojiset_change() {
// implementation is wrong, though, in that it displays the UI // implementation is wrong, though, in that it displays the UI
// update in all active browser windows. // update in all active browser windows.
await emojisets.select(page_params.emojiset); await emojisets.select(user_settings.emojiset);
if ($("#emoji-settings-status").length) { if ($("#emoji-settings-status").length) {
loading.destroy_indicator($("#emojiset_spinner")); loading.destroy_indicator($("#emojiset_spinner"));
$("#emojiset_select").val(page_params.emojiset); $("#emojiset_select").val(user_settings.emojiset);
ui_report.success( ui_report.success(
$t_html({defaultMessage: "Emojiset changed successfully!"}), $t_html({defaultMessage: "Emojiset changed successfully!"}),
$("#emoji-settings-status").expectOne(), $("#emoji-settings-status").expectOne(),
@ -189,18 +189,18 @@ export async function report_emojiset_change() {
} }
export function update_page() { export function update_page() {
$("#left_side_userlist").prop("checked", page_params.left_side_userlist); $("#left_side_userlist").prop("checked", user_settings.left_side_userlist);
$("#default_language_name").text(default_language_name); $("#default_language_name").text(default_language_name);
$("#translate_emoticons").prop("checked", page_params.translate_emoticons); $("#translate_emoticons").prop("checked", user_settings.translate_emoticons);
$("#twenty_four_hour_time").val(JSON.stringify(page_params.twenty_four_hour_time)); $("#twenty_four_hour_time").val(JSON.stringify(user_settings.twenty_four_hour_time));
$("#color_scheme").val(JSON.stringify(page_params.color_scheme)); $("#color_scheme").val(JSON.stringify(user_settings.color_scheme));
$("#default_view").val(page_params.default_view); $("#default_view").val(user_settings.default_view);
// TODO: Set emojiset selector here. // TODO: Set emojiset selector here.
// Longer term, we'll want to automate this function // Longer term, we'll want to automate this function
} }
export function initialize() { export function initialize() {
const language_name = get_language_name(page_params.default_language); const language_name = get_language_name(user_settings.default_language);
set_default_language_name(language_name); set_default_language_name(language_name);
} }

View File

@ -5,13 +5,13 @@ import render_stream_specific_notification_row from "../templates/settings/strea
import * as channel from "./channel"; import * as channel from "./channel";
import {$t} from "./i18n"; import {$t} from "./i18n";
import * as notifications from "./notifications"; import * as notifications from "./notifications";
import {page_params} from "./page_params";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as settings_org from "./settings_org"; import * as settings_org from "./settings_org";
import * as settings_ui from "./settings_ui"; import * as settings_ui from "./settings_ui";
import * as stream_edit from "./stream_edit"; import * as stream_edit from "./stream_edit";
import * as stream_settings_data from "./stream_settings_data"; import * as stream_settings_data from "./stream_settings_data";
import * as unread_ui from "./unread_ui"; import * as unread_ui from "./unread_ui";
import {user_settings} from "./user_settings";
function rerender_ui() { function rerender_ui() {
const unmatched_streams_table = $("#stream-specific-notify-table"); const unmatched_streams_table = $("#stream-specific-notify-table");
@ -50,12 +50,12 @@ function change_notification_setting(setting, value, status_element) {
} }
function update_desktop_icon_count_display() { function update_desktop_icon_count_display() {
$("#desktop_icon_count_display").val(page_params.desktop_icon_count_display); $("#desktop_icon_count_display").val(user_settings.desktop_icon_count_display);
unread_ui.update_unread_counts(); unread_ui.update_unread_counts();
} }
export function set_enable_digest_emails_visibility() { export function set_enable_digest_emails_visibility() {
if (page_params.realm_digest_emails_enabled) { if (user_settings.realm_digest_emails_enabled) {
$("#enable_digest_emails_label").parent().show(); $("#enable_digest_emails_label").parent().show();
} else { } else {
$("#enable_digest_emails_label").parent().hide(); $("#enable_digest_emails_label").parent().hide();
@ -63,7 +63,7 @@ export function set_enable_digest_emails_visibility() {
} }
export function set_enable_marketing_emails_visibility() { export function set_enable_marketing_emails_visibility() {
if (page_params.corporate_enabled) { if (user_settings.corporate_enabled) {
$("#enable_marketing_emails_label").parent().show(); $("#enable_marketing_emails_label").parent().show();
} else { } else {
$("#enable_marketing_emails_label").parent().hide(); $("#enable_marketing_emails_label").parent().hide();
@ -96,13 +96,13 @@ export function set_up() {
}); });
$("#play_notification_sound").on("click", () => { $("#play_notification_sound").on("click", () => {
if (page_params.notification_sound !== "none") { if (user_settings.notification_sound !== "none") {
$("#notification-sound-audio")[0].play(); $("#notification-sound-audio")[0].play();
} }
}); });
const notification_sound_dropdown = $("#notification_sound"); const notification_sound_dropdown = $("#notification_sound");
notification_sound_dropdown.val(page_params.notification_sound); notification_sound_dropdown.val(user_settings.notification_sound);
$("#enable_sounds, #enable_stream_audible_notifications").on("change", () => { $("#enable_sounds, #enable_stream_audible_notifications").on("change", () => {
if ( if (
@ -125,7 +125,7 @@ export function update_page() {
for (const setting of settings_config.all_notification_settings) { for (const setting of settings_config.all_notification_settings) {
if ( if (
setting === "enable_offline_push_notifications" && setting === "enable_offline_push_notifications" &&
!page_params.realm_push_notifications_enabled !user_settings.realm_push_notifications_enabled
) { ) {
// If push notifications are disabled at the realm level, // If push notifications are disabled at the realm level,
// we should just leave the checkbox always off. // we should just leave the checkbox always off.
@ -135,7 +135,7 @@ export function update_page() {
continue; continue;
} }
$(`#${CSS.escape(setting)}`).prop("checked", page_params[setting]); $(`#${CSS.escape(setting)}`).prop("checked", user_settings[setting]);
} }
rerender_ui(); rerender_ui();
} }

View File

@ -2,6 +2,7 @@ import * as message_store from "./message_store";
import {page_params} from "./page_params"; import {page_params} from "./page_params";
import * as stream_popover from "./stream_popover"; import * as stream_popover from "./stream_popover";
import * as top_left_corner from "./top_left_corner"; import * as top_left_corner from "./top_left_corner";
import {user_settings} from "./user_settings";
export const starred_ids = new Set(); export const starred_ids = new Set();
@ -74,7 +75,7 @@ export function get_count_in_topic(stream_id, topic) {
export function rerender_ui() { export function rerender_ui() {
let count = get_count(); let count = get_count();
if (!page_params.starred_message_counts) { if (!user_settings.starred_message_counts) {
// This essentially hides the count // This essentially hides the count
count = 0; count = 0;
} }

View File

@ -8,6 +8,7 @@ import * as people from "./people";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as stream_topic_history from "./stream_topic_history"; import * as stream_topic_history from "./stream_topic_history";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
import {user_settings} from "./user_settings";
import * as util from "./util"; import * as util from "./util";
const DEFAULT_COLOR = "#c2c2c2"; const DEFAULT_COLOR = "#c2c2c2";
@ -160,12 +161,12 @@ clear_subscriptions();
export function set_filter_out_inactives() { export function set_filter_out_inactives() {
if ( if (
page_params.demote_inactive_streams === user_settings.demote_inactive_streams ===
settings_config.demote_inactive_streams_values.automatic.code settings_config.demote_inactive_streams_values.automatic.code
) { ) {
filter_out_inactives = num_subscribed_subs() >= 30; filter_out_inactives = num_subscribed_subs() >= 30;
} else if ( } else if (
page_params.demote_inactive_streams === user_settings.demote_inactive_streams ===
settings_config.demote_inactive_streams_values.always.code settings_config.demote_inactive_streams_values.always.code
) { ) {
filter_out_inactives = true; filter_out_inactives = true;
@ -457,9 +458,9 @@ export function receives_notifications(stream_id, notification_name) {
return sub[notification_name]; return sub[notification_name];
} }
if (notification_name === "wildcard_mentions_notify") { if (notification_name === "wildcard_mentions_notify") {
return page_params[notification_name]; return user_settings[notification_name];
} }
return page_params["enable_stream_" + notification_name]; return user_settings["enable_stream_" + notification_name];
} }
export function all_subscribed_streams_are_in_home_view() { export function all_subscribed_streams_are_in_home_view() {
@ -672,11 +673,11 @@ export function create_sub_from_server_data(attrs) {
newly_subscribed: false, newly_subscribed: false,
is_muted: false, is_muted: false,
invite_only: false, invite_only: false,
desktop_notifications: page_params.enable_stream_desktop_notifications, desktop_notifications: user_settings.enable_stream_desktop_notifications,
audible_notifications: page_params.enable_stream_audible_notifications, audible_notifications: user_settings.enable_stream_audible_notifications,
push_notifications: page_params.enable_stream_push_notifications, push_notifications: user_settings.enable_stream_push_notifications,
email_notifications: page_params.enable_stream_email_notifications, email_notifications: user_settings.enable_stream_email_notifications,
wildcard_mentions_notify: page_params.wildcard_mentions_notify, wildcard_mentions_notify: user_settings.wildcard_mentions_notify,
description: "", description: "",
rendered_description: "", rendered_description: "",
first_message_id: attrs.first_message_id, first_message_id: attrs.first_message_id,

View File

@ -38,6 +38,7 @@ import * as ui from "./ui";
import * as ui_report from "./ui_report"; import * as ui_report from "./ui_report";
import * as user_group_pill from "./user_group_pill"; import * as user_group_pill from "./user_group_pill";
import * as user_pill from "./user_pill"; import * as user_pill from "./user_pill";
import {user_settings} from "./user_settings";
import * as util from "./util"; import * as util from "./util";
export let pill_widget; export let pill_widget;
@ -592,9 +593,9 @@ export function stream_setting_changed(e, from_notification_settings) {
} }
if (is_notification_setting(setting) && sub[setting] === null) { if (is_notification_setting(setting) && sub[setting] === null) {
if (setting === "wildcard_mentions_notify") { if (setting === "wildcard_mentions_notify") {
sub[setting] = page_params[setting]; sub[setting] = user_settings[setting];
} else { } else {
sub[setting] = page_params["enable_stream_" + setting]; sub[setting] = user_settings["enable_stream_" + setting];
} }
} }
set_stream_property(sub, setting, e.target.checked, status_element); set_stream_property(sub, setting, e.target.checked, status_element);

View File

@ -32,6 +32,7 @@ import * as stream_data from "./stream_data";
import * as stream_settings_ui from "./stream_settings_ui"; import * as stream_settings_ui from "./stream_settings_ui";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
import * as unread_ops from "./unread_ops"; import * as unread_ops from "./unread_ops";
import {user_settings} from "./user_settings";
// We handle stream popovers and topic popovers in this // We handle stream popovers and topic popovers in this
// module. Both are popped up from the left sidebar. // module. Both are popped up from the left sidebar.
@ -332,7 +333,7 @@ function build_starred_messages_popover(e) {
const show_unstar_all_button = starred_messages.get_count() > 0; const show_unstar_all_button = starred_messages.get_count() > 0;
const content = render_starred_messages_sidebar_actions({ const content = render_starred_messages_sidebar_actions({
show_unstar_all_button, show_unstar_all_button,
starred_message_counts: page_params.starred_message_counts, starred_message_counts: user_settings.starred_message_counts,
}); });
$(elt).popover({ $(elt).popover({
@ -506,7 +507,7 @@ export function register_stream_handlers() {
hide_starred_messages_popover(); hide_starred_messages_popover();
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
const starred_msg_counts = page_params.starred_message_counts; const starred_msg_counts = user_settings.starred_message_counts;
const data = {}; const data = {};
data.starred_message_counts = JSON.stringify(!starred_msg_counts); data.starred_message_counts = JSON.stringify(!starred_msg_counts);
channel.patch({ channel.patch({

View File

@ -4,6 +4,7 @@ import * as peer_data from "./peer_data";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
import {user_settings} from "./user_settings";
import * as util from "./util"; import * as util from "./util";
export function get_sub_for_settings(sub) { export function get_sub_for_settings(sub) {
@ -61,7 +62,7 @@ export function get_unmatched_streams_for_notification_settings() {
for (const notification_name of settings_config.stream_specific_notification_settings) { for (const notification_name of settings_config.stream_specific_notification_settings) {
const prepend = const prepend =
notification_name === "wildcard_mentions_notify" ? "" : "enable_stream_"; notification_name === "wildcard_mentions_notify" ? "" : "enable_stream_";
const default_setting = page_params[prepend + notification_name]; const default_setting = user_settings[prepend + notification_name];
const stream_setting = stream_data.receives_notifications( const stream_setting = stream_data.receives_notifications(
row.stream_id, row.stream_id,
notification_name, notification_name,

View File

@ -14,7 +14,7 @@ import _ from "lodash";
import render_markdown_time_tooltip from "../templates/markdown_time_tooltip.hbs"; import render_markdown_time_tooltip from "../templates/markdown_time_tooltip.hbs";
import {$t} from "./i18n"; import {$t} from "./i18n";
import {page_params} from "./page_params"; import {user_settings} from "./user_settings";
let next_timerender_id = 0; let next_timerender_id = 0;
@ -206,7 +206,7 @@ export function render_date(time, time_above, today) {
// Renders the timestamp returned by the <time:> Markdown syntax. // Renders the timestamp returned by the <time:> Markdown syntax.
export function render_markdown_timestamp(time) { export function render_markdown_timestamp(time) {
const hourformat = page_params.twenty_four_hour_time ? "HH:mm" : "h:mm a"; const hourformat = user_settings.twenty_four_hour_time ? "HH:mm" : "h:mm a";
const timestring = format(time, "E, MMM d yyyy, " + hourformat); const timestring = format(time, "E, MMM d yyyy, " + hourformat);
const tz_offset_str = get_tz_with_UTC_offset(time); const tz_offset_str = get_tz_with_UTC_offset(time);
@ -277,7 +277,7 @@ export function get_timestamp_for_flatpickr(timestring) {
} }
export function stringify_time(time) { export function stringify_time(time) {
if (page_params.twenty_four_hour_time) { if (user_settings.twenty_four_hour_time) {
return format(time, "HH:mm"); return format(time, "HH:mm");
} }
return format(time, "h:mm a"); return format(time, "h:mm a");
@ -324,7 +324,7 @@ export const absolute_time = (function () {
return function (timestamp, today = new Date()) { return function (timestamp, today = new Date()) {
const date = new Date(timestamp); const date = new Date(timestamp);
const is_older_year = today.getFullYear() - date.getFullYear() > 0; const is_older_year = today.getFullYear() - date.getFullYear() > 0;
const H_24 = page_params.twenty_four_hour_time; const H_24 = user_settings.twenty_four_hour_time;
let str = MONTHS[date.getMonth()] + " " + date.getDate(); let str = MONTHS[date.getMonth()] + " " + date.getDate();
// include year if message date is from a previous year // include year if message date is from a previous year
if (is_older_year) { if (is_older_year) {
@ -338,7 +338,7 @@ export const absolute_time = (function () {
export function get_full_datetime(time) { export function get_full_datetime(time) {
const time_options = {timeStyle: "medium"}; const time_options = {timeStyle: "medium"};
if (page_params.twenty_four_hour_time) { if (user_settings.twenty_four_hour_time) {
time_options.hourCycle = "h24"; time_options.hourCycle = "h24";
} }

View File

@ -88,6 +88,7 @@ import * as ui from "./ui";
import * as unread from "./unread"; import * as unread from "./unread";
import * as unread_ui from "./unread_ui"; import * as unread_ui from "./unread_ui";
import * as user_groups from "./user_groups"; import * as user_groups from "./user_groups";
import {initialize_user_settings, user_settings} from "./user_settings";
import * as user_status from "./user_status"; import * as user_status from "./user_status";
import * as user_status_ui from "./user_status_ui"; import * as user_status_ui from "./user_status_ui";
@ -228,15 +229,15 @@ export function initialize_kitchen_sink_stuff() {
$("body").addClass("spectator-view"); $("body").addClass("spectator-view");
} }
if (!page_params.left_side_userlist) { if (!user_settings.left_side_userlist) {
$("#navbar-buttons").addClass("right-userlist"); $("#navbar-buttons").addClass("right-userlist");
} }
if (page_params.high_contrast_mode) { if (user_settings.high_contrast_mode) {
$("body").addClass("high-contrast"); $("body").addClass("high-contrast");
} }
if (!page_params.dense_mode) { if (!user_settings.dense_mode) {
$("body").addClass("less_dense_mode"); $("body").addClass("less_dense_mode");
} else { } else {
$("body").addClass("more_dense_mode"); $("body").addClass("more_dense_mode");
@ -493,11 +494,13 @@ export function initialize_everything() {
const user_status_params = pop_fields("user_status"); const user_status_params = pop_fields("user_status");
const i18n_params = pop_fields("language_list"); const i18n_params = pop_fields("language_list");
const user_settings_params = pop_fields("user_settings");
i18n.initialize(i18n_params); i18n.initialize(i18n_params);
tippyjs.initialize(); tippyjs.initialize();
popover_menus.initialize(); popover_menus.initialize();
initialize_user_settings(user_settings_params);
people.initialize(page_params.user_id, people_params); people.initialize(page_params.user_id, people_params);
let date_joined; let date_joined;

View File

@ -6,6 +6,7 @@ import * as people from "./people";
import * as settings_config from "./settings_config"; import * as settings_config from "./settings_config";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as sub_store from "./sub_store"; import * as sub_store from "./sub_store";
import {user_settings} from "./user_settings";
import * as util from "./util"; import * as util from "./util";
// The unread module tracks the message IDs and locations of the // The unread module tracks the message IDs and locations of the
@ -509,10 +510,10 @@ export function calculate_notifiable_count(res) {
let new_message_count = 0; let new_message_count = 0;
const only_show_notifiable = const only_show_notifiable =
page_params.desktop_icon_count_display === user_settings.desktop_icon_count_display ===
settings_config.desktop_icon_count_display_values.notifiable.code; settings_config.desktop_icon_count_display_values.notifiable.code;
const no_notifications = const no_notifications =
page_params.desktop_icon_count_display === user_settings.desktop_icon_count_display ===
settings_config.desktop_icon_count_display_values.none.code; settings_config.desktop_icon_count_display_values.none.code;
if (only_show_notifiable) { if (only_show_notifiable) {
// DESKTOP_ICON_COUNT_DISPLAY_NOTIFIABLE // DESKTOP_ICON_COUNT_DISPLAY_NOTIFIABLE

View File

@ -0,0 +1,19 @@
type UserSettingsType = {
color_scheme: number;
enable_desktop_notifications: boolean;
enable_offline_push_notifications: boolean;
enable_offline_email_notifications: boolean;
enable_sounds: boolean;
enable_stream_audible_notifications: boolean;
enable_stream_desktop_notifications: boolean;
enable_stream_email_notifications: boolean;
enable_stream_push_notifications: boolean;
twenty_four_hour_time: boolean;
wildcard_mentions_notify: boolean;
};
export let user_settings = {} as UserSettingsType;
export function initialize_user_settings(params: Record<string, UserSettingsType>): void {
user_settings = params.user_settings;
}

View File

@ -2,7 +2,7 @@ import * as emoji from "../shared/js/emoji";
import * as blueslip from "./blueslip"; import * as blueslip from "./blueslip";
import * as channel from "./channel"; import * as channel from "./channel";
import {page_params} from "./page_params"; import {user_settings} from "./user_settings";
const away_user_ids = new Set(); const away_user_ids = new Set();
const user_info = new Map(); const user_info = new Map();
@ -80,7 +80,7 @@ export function set_status_emoji(opts) {
emoji_name: opts.emoji_name, emoji_name: opts.emoji_name,
emoji_code: opts.emoji_code, emoji_code: opts.emoji_code,
reaction_type: opts.reaction_type, reaction_type: opts.reaction_type,
emoji_alt_code: page_params.emojiset === "text", emoji_alt_code: user_settings.emojiset === "text",
...emoji.get_emoji_details_by_name(opts.emoji_name), ...emoji.get_emoji_details_by_name(opts.emoji_name),
}); });
} }

View File

@ -43,8 +43,8 @@ function build_emoticon_translations() {
.... ....
] ]
We build up this list of ~12 emoticon translations We build up this list of ~12 emoticon translations even
even if page_params.translate_emoticons is false, since if user_settings.translate_emoticons is false, since
that setting can be flipped via live update events. that setting can be flipped via live update events.
On the other hand, we assume that emoticon_conversions On the other hand, we assume that emoticon_conversions
won't change until the next reload, which is fine for won't change until the next reload, which is fine for

View File

@ -101,7 +101,7 @@
<div class="input-group"> <div class="input-group">
{{> settings_checkbox {{> settings_checkbox
setting_name="presence_enabled" setting_name="presence_enabled"
is_checked=page_params.presence_enabled is_checked=user_settings.presence_enabled
label=settings_label.presence_enabled label=settings_label.presence_enabled
help_link="/help/status-and-availability"}} help_link="/help/status-and-availability"}}
</div> </div>

View File

@ -41,7 +41,7 @@
{{#each display_settings.settings.user_display_settings}} {{#each display_settings.settings.user_display_settings}}
{{> settings_checkbox {{> settings_checkbox
setting_name=this setting_name=this
is_checked=(lookup ../page_params this) is_checked=(lookup ../user_settings this)
label=(lookup ../settings_label this) label=(lookup ../settings_label this)
render_only=(lookup ../display_settings.render_only this)}} render_only=(lookup ../display_settings.render_only this)}}
{{/each}} {{/each}}
@ -76,7 +76,7 @@
<div class="input-group"> <div class="input-group">
<div class="emojiset_choices grey-box"> <div class="emojiset_choices grey-box">
{{#each page_params.emojiset_choices}} {{#each user_settings.emojiset_choices}}
<label> <label>
<input type="radio" class="emojiset_choice" name="emojiset_group" value="{{this.key}}" /> <input type="radio" class="emojiset_choice" name="emojiset_group" value="{{this.key}}" />
<span>{{this.text}}</span> <span>{{this.text}}</span>
@ -97,7 +97,7 @@
{{> settings_checkbox {{> settings_checkbox
setting_name="translate_emoticons" setting_name="translate_emoticons"
is_checked=page_params.translate_emoticons is_checked=user_settings.translate_emoticons
label=settings_label.translate_emoticons}} label=settings_label.translate_emoticons}}
</div> </div>
</form> </form>

View File

@ -56,7 +56,7 @@
{{#each notification_settings.desktop_notification_settings}} {{#each notification_settings.desktop_notification_settings}}
{{> settings_checkbox {{> settings_checkbox
setting_name=this setting_name=this
is_checked=(lookup ../page_params this) is_checked=(lookup ../user_settings this)
label=(lookup ../settings_label this)}} label=(lookup ../settings_label this)}}
{{/each}} {{/each}}
@ -70,7 +70,7 @@
disabled disabled
{{/unless}}> {{/unless}}>
<option value="none">{{t "None" }}</option> <option value="none">{{t "None" }}</option>
{{#each page_params.available_notification_sounds}} {{#each user_settings.available_notification_sounds}}
<option value="{{ this }}">{{ this }}</option> <option value="{{ this }}">{{ this }}</option>
{{/each}} {{/each}}
</select> </select>
@ -92,7 +92,7 @@
{{#each notification_settings.mobile_notification_settings}} {{#each notification_settings.mobile_notification_settings}}
{{> settings_checkbox {{> settings_checkbox
setting_name=this setting_name=this
is_checked=(lookup ../page_params this) is_checked=(lookup ../user_settings this)
label=(lookup ../settings_label this) label=(lookup ../settings_label this)
show_push_notifications_tooltip=(lookup ../show_push_notifications_tooltip this)}} show_push_notifications_tooltip=(lookup ../show_push_notifications_tooltip this)}}
{{/each}} {{/each}}
@ -102,7 +102,7 @@
{{#each notification_settings.email_notification_settings}} {{#each notification_settings.email_notification_settings}}
{{> settings_checkbox {{> settings_checkbox
setting_name=this setting_name=this
is_checked=(lookup ../page_params this) is_checked=(lookup ../user_settings this)
label=(lookup ../settings_label this)}} label=(lookup ../settings_label this)}}
{{/each}} {{/each}}

View File

@ -33,7 +33,7 @@
<div class="alert-notification timezone-setting-status"></div> <div class="alert-notification timezone-setting-status"></div>
<div class="timezone-input"> <div class="timezone-input">
<select name="timezone" id="user_timezone" class> <select name="timezone" id="user_timezone" class>
{{#unless page_params.timezone}} {{#unless user_settings.timezone}}
<option></option> <option></option>
{{/unless}} {{/unless}}

View File

@ -175,6 +175,7 @@ EXEMPT_FILES = {
"static/js/unread_ui.js", "static/js/unread_ui.js",
"static/js/upload_widget.ts", "static/js/upload_widget.ts",
"static/js/user_profile.js", "static/js/user_profile.js",
"static/js/user_settings.ts",
"static/js/user_status_ui.js", "static/js/user_status_ui.js",
"static/js/webpack_public_path.js", "static/js/webpack_public_path.js",
"static/js/zcommand.js", "static/js/zcommand.js",

View File

@ -424,7 +424,7 @@ BAD_HTML16 = """
<div> <div>
{{> settings_checkbox {{> settings_checkbox
setting_name="realm_name_in_notifications" setting_name="realm_name_in_notifications"
is_checked=page_params.realm_name_in_notifications is_checked=user_settings.realm_name_in_notifications
label=settings_label.realm_name_in_notifications}} label=settings_label.realm_name_in_notifications}}
</div> </div>
""" """
@ -433,7 +433,7 @@ GOOD_HTML16 = """
<div> <div>
{{> settings_checkbox {{> settings_checkbox
setting_name="realm_name_in_notifications" setting_name="realm_name_in_notifications"
is_checked=page_params.realm_name_in_notifications is_checked=user_settings.realm_name_in_notifications
label=settings_label.realm_name_in_notifications}} label=settings_label.realm_name_in_notifications}}
</div> </div>
""" """

View File

@ -135,7 +135,7 @@ def build_page_params_for_home_page_load(
"bulk_message_deletion": True, "bulk_message_deletion": True,
"user_avatar_url_field_optional": True, "user_avatar_url_field_optional": True,
"stream_typing_notifications": False, # Set this to True when frontend support is implemented. "stream_typing_notifications": False, # Set this to True when frontend support is implemented.
"user_settings_object": False, # Set this to True when frontend support is implemented. "user_settings_object": True,
} }
if user_profile is not None: if user_profile is not None:
@ -176,7 +176,7 @@ def build_page_params_for_home_page_load(
request_language = get_and_set_request_language( request_language = get_and_set_request_language(
request, request,
register_ret["default_language"], register_ret["user_settings"]["default_language"],
translation.get_language_from_path(request.path_info), translation.get_language_from_path(request.path_info),
) )
@ -234,7 +234,7 @@ def build_page_params_for_home_page_load(
page_params["narrow_topic"] = narrow_topic page_params["narrow_topic"] = narrow_topic
page_params["narrow"] = [dict(operator=term[0], operand=term[1]) for term in narrow] page_params["narrow"] = [dict(operator=term[0], operand=term[1]) for term in narrow]
page_params["max_message_id"] = max_message_id page_params["max_message_id"] = max_message_id
page_params["enable_desktop_notifications"] = False page_params["user_settings"]["enable_desktop_notifications"] = False
page_params["translation_data"] = get_language_translation_data(request_language) page_params["translation_data"] = get_language_translation_data(request_language)

View File

@ -45,7 +45,6 @@ class HomeTest(ZulipTestCase):
expected_page_params_keys = [ expected_page_params_keys = [
"alert_words", "alert_words",
"apps_page_url", "apps_page_url",
"available_notification_sounds",
"avatar_source", "avatar_source",
"avatar_url", "avatar_url",
"avatar_url_medium", "avatar_url_medium",
@ -53,46 +52,21 @@ class HomeTest(ZulipTestCase):
"can_create_streams", "can_create_streams",
"can_invite_others_to_realm", "can_invite_others_to_realm",
"can_subscribe_other_users", "can_subscribe_other_users",
"color_scheme",
"corporate_enabled", "corporate_enabled",
"cross_realm_bots", "cross_realm_bots",
"custom_profile_field_types", "custom_profile_field_types",
"custom_profile_fields", "custom_profile_fields",
"default_language",
"default_view",
"delivery_email", "delivery_email",
"demote_inactive_streams",
"dense_mode",
"desktop_icon_count_display",
"development_environment", "development_environment",
"drafts", "drafts",
"email", "email",
"email_notifications_batching_period_seconds",
"emojiset",
"emojiset_choices",
"enable_desktop_notifications",
"enable_digest_emails",
"enable_drafts_synchronization",
"enable_login_emails",
"enable_marketing_emails",
"enable_offline_email_notifications",
"enable_offline_push_notifications",
"enable_online_push_notifications",
"enable_sounds",
"enable_stream_audible_notifications",
"enable_stream_desktop_notifications",
"enable_stream_email_notifications",
"enable_stream_push_notifications",
"enter_sends",
"event_queue_longpoll_timeout_seconds", "event_queue_longpoll_timeout_seconds",
"first_in_realm", "first_in_realm",
"fluid_layout_width",
"full_name", "full_name",
"furthest_read_time", "furthest_read_time",
"giphy_api_key", "giphy_api_key",
"giphy_rating_options", "giphy_rating_options",
"has_zoom_token", "has_zoom_token",
"high_contrast_mode",
"hotspots", "hotspots",
"insecure_desktop_app", "insecure_desktop_app",
"is_admin", "is_admin",
@ -104,7 +78,6 @@ class HomeTest(ZulipTestCase):
"jitsi_server_url", "jitsi_server_url",
"language_list", "language_list",
"last_event_id", "last_event_id",
"left_side_userlist",
"login_page", "login_page",
"max_avatar_file_size_mib", "max_avatar_file_size_mib",
"max_file_upload_size_mib", "max_file_upload_size_mib",
@ -115,7 +88,6 @@ class HomeTest(ZulipTestCase):
"max_stream_description_length", "max_stream_description_length",
"max_stream_name_length", "max_stream_name_length",
"max_topic_length", "max_topic_length",
"message_content_in_email_notifications",
"muted_topics", "muted_topics",
"muted_users", "muted_users",
"narrow", "narrow",
@ -123,11 +95,8 @@ class HomeTest(ZulipTestCase):
"needs_tutorial", "needs_tutorial",
"never_subscribed", "never_subscribed",
"no_event_queue", "no_event_queue",
"notification_sound",
"password_min_guesses", "password_min_guesses",
"password_min_length", "password_min_length",
"pm_content_in_desktop_notifications",
"presence_enabled",
"presences", "presences",
"promote_sponsoring_zulip", "promote_sponsoring_zulip",
"prompt_for_invites", "prompt_for_invites",
@ -184,7 +153,6 @@ class HomeTest(ZulipTestCase):
"realm_move_messages_between_streams_policy", "realm_move_messages_between_streams_policy",
"realm_name", "realm_name",
"realm_name_changes_disabled", "realm_name_changes_disabled",
"realm_name_in_notifications",
"realm_night_logo_source", "realm_night_logo_source",
"realm_night_logo_url", "realm_night_logo_url",
"realm_non_active_users", "realm_non_active_users",
@ -219,15 +187,11 @@ class HomeTest(ZulipTestCase):
"show_billing", "show_billing",
"show_plans", "show_plans",
"show_webathena", "show_webathena",
"starred_message_counts",
"starred_messages", "starred_messages",
"stop_words", "stop_words",
"subscriptions", "subscriptions",
"test_suite", "test_suite",
"timezone",
"translate_emoticons",
"translation_data", "translation_data",
"twenty_four_hour_time",
"two_fa_enabled", "two_fa_enabled",
"two_fa_enabled_user", "two_fa_enabled_user",
"unread_msgs", "unread_msgs",
@ -238,7 +202,6 @@ class HomeTest(ZulipTestCase):
"user_status", "user_status",
"warn_no_email", "warn_no_email",
"webpack_public_path", "webpack_public_path",
"wildcard_mentions_notify",
"zulip_feature_level", "zulip_feature_level",
"zulip_merge_base", "zulip_merge_base",
"zulip_plan_is_not_limited", "zulip_plan_is_not_limited",
@ -1030,7 +993,7 @@ class HomeTest(ZulipTestCase):
): ):
result = self.client_get("/de/") result = self.client_get("/de/")
page_params = self._get_page_params(result) page_params = self._get_page_params(result)
self.assertEqual(page_params["default_language"], "es") self.assertEqual(page_params["user_settings"]["default_language"], "es")
# TODO: Verify that the actual language we're using in the # TODO: Verify that the actual language we're using in the
# translation data is German. # translation data is German.
@ -1043,7 +1006,7 @@ class HomeTest(ZulipTestCase):
self.check_rendered_logged_in_app(result) self.check_rendered_logged_in_app(result)
page_params = self._get_page_params(result) page_params = self._get_page_params(result)
self.assertEqual(page_params["default_language"], "es") self.assertEqual(page_params["user_settings"]["default_language"], "es")
# TODO: This test would likely be better written as a /register # TODO: This test would likely be better written as a /register
# API test with just the drafts event type, to avoid the # API test with just the drafts event type, to avoid the
@ -1076,7 +1039,7 @@ class HomeTest(ZulipTestCase):
# recently edited ones. # recently edited ones.
self.login("hamlet") self.login("hamlet")
page_params = self._get_page_params(self._get_home_page()) page_params = self._get_page_params(self._get_home_page())
self.assertEqual(page_params["enable_drafts_synchronization"], True) self.assertEqual(page_params["user_settings"]["enable_drafts_synchronization"], True)
self.assert_length(page_params["drafts"], settings.MAX_DRAFTS_IN_REGISTER_RESPONSE) self.assert_length(page_params["drafts"], settings.MAX_DRAFTS_IN_REGISTER_RESPONSE)
self.assertEqual( self.assertEqual(
Draft.objects.count(), settings.MAX_DRAFTS_IN_REGISTER_RESPONSE + 1 + initial_count Draft.objects.count(), settings.MAX_DRAFTS_IN_REGISTER_RESPONSE + 1 + initial_count