mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
ui_init: Use Zod to split state_data.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
be9369541a
commit
fd253539e0
@@ -14,11 +14,10 @@ import {$t_html} from "./i18n";
|
|||||||
import * as ListWidget from "./list_widget";
|
import * as ListWidget from "./list_widget";
|
||||||
import * as scroll_util from "./scroll_util";
|
import * as scroll_util from "./scroll_util";
|
||||||
import * as settings_ui from "./settings_ui";
|
import * as settings_ui from "./settings_ui";
|
||||||
import type {realm_schema} from "./state_data";
|
|
||||||
import {current_user, realm} from "./state_data";
|
import {current_user, realm} from "./state_data";
|
||||||
import * as ui_report from "./ui_report";
|
import * as ui_report from "./ui_report";
|
||||||
|
|
||||||
type RealmLinkifiers = z.infer<typeof realm_schema>["realm_linkifiers"];
|
type RealmLinkifiers = typeof realm.realm_linkifiers;
|
||||||
|
|
||||||
const configure_linkifier_api_response_schema = z.object({
|
const configure_linkifier_api_response_schema = z.object({
|
||||||
id: z.number(),
|
id: z.number(),
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import {z} from "zod";
|
import {z} from "zod";
|
||||||
|
|
||||||
|
const NOT_TYPED_YET = z.unknown();
|
||||||
|
|
||||||
const group_permission_setting_schema = z.object({
|
const group_permission_setting_schema = z.object({
|
||||||
require_system_group: z.boolean(),
|
require_system_group: z.boolean(),
|
||||||
allow_internet_group: z.boolean(),
|
allow_internet_group: z.boolean(),
|
||||||
@@ -34,9 +36,19 @@ export const custom_profile_field_schema = z.object({
|
|||||||
export type CustomProfileField = z.output<typeof custom_profile_field_schema>;
|
export type CustomProfileField = z.output<typeof custom_profile_field_schema>;
|
||||||
|
|
||||||
// Sync this with zerver.lib.events.do_events_register.
|
// Sync this with zerver.lib.events.do_events_register.
|
||||||
export const current_user_schema = z.object({
|
const current_user_schema = z.object({
|
||||||
avatar_source: z.string(),
|
avatar_source: z.string(),
|
||||||
|
avatar_url: NOT_TYPED_YET,
|
||||||
|
avatar_url_medium: NOT_TYPED_YET,
|
||||||
|
can_create_private_streams: NOT_TYPED_YET,
|
||||||
|
can_create_public_streams: NOT_TYPED_YET,
|
||||||
|
can_create_streams: NOT_TYPED_YET,
|
||||||
|
can_create_web_public_streams: NOT_TYPED_YET,
|
||||||
|
can_invite_others_to_realm: NOT_TYPED_YET,
|
||||||
|
can_subscribe_other_users: NOT_TYPED_YET,
|
||||||
delivery_email: z.string(),
|
delivery_email: z.string(),
|
||||||
|
email: NOT_TYPED_YET,
|
||||||
|
full_name: NOT_TYPED_YET,
|
||||||
has_zoom_token: z.boolean(),
|
has_zoom_token: z.boolean(),
|
||||||
is_admin: z.boolean(),
|
is_admin: z.boolean(),
|
||||||
is_billing_admin: z.boolean(),
|
is_billing_admin: z.boolean(),
|
||||||
@@ -47,7 +59,7 @@ export const current_user_schema = z.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Sync this with zerver.lib.events.do_events_register.
|
// Sync this with zerver.lib.events.do_events_register.
|
||||||
export const realm_schema = z.object({
|
const realm_schema = z.object({
|
||||||
custom_profile_fields: z.array(custom_profile_field_schema),
|
custom_profile_fields: z.array(custom_profile_field_schema),
|
||||||
custom_profile_field_types: z.object({
|
custom_profile_field_types: z.object({
|
||||||
SHORT_TEXT: z.object({id: z.number(), name: z.string()}),
|
SHORT_TEXT: z.object({id: z.number(), name: z.string()}),
|
||||||
@@ -60,14 +72,21 @@ export const realm_schema = z.object({
|
|||||||
PRONOUNS: z.object({id: z.number(), name: z.string()}),
|
PRONOUNS: z.object({id: z.number(), name: z.string()}),
|
||||||
}),
|
}),
|
||||||
demo_organization_scheduled_deletion_date: z.optional(z.number()),
|
demo_organization_scheduled_deletion_date: z.optional(z.number()),
|
||||||
|
giphy_api_key: NOT_TYPED_YET,
|
||||||
|
giphy_rating_options: NOT_TYPED_YET,
|
||||||
max_avatar_file_size_mib: z.number(),
|
max_avatar_file_size_mib: z.number(),
|
||||||
max_file_upload_size_mib: z.number(),
|
max_file_upload_size_mib: z.number(),
|
||||||
max_icon_file_size_mib: z.number(),
|
max_icon_file_size_mib: z.number(),
|
||||||
max_logo_file_size_mib: z.number(),
|
max_logo_file_size_mib: z.number(),
|
||||||
max_message_length: z.number(),
|
max_message_length: z.number(),
|
||||||
|
max_stream_description_length: NOT_TYPED_YET,
|
||||||
|
max_stream_name_length: NOT_TYPED_YET,
|
||||||
max_topic_length: z.number(),
|
max_topic_length: z.number(),
|
||||||
|
password_min_guesses: NOT_TYPED_YET,
|
||||||
|
password_min_length: NOT_TYPED_YET,
|
||||||
realm_add_custom_emoji_policy: z.number(),
|
realm_add_custom_emoji_policy: z.number(),
|
||||||
realm_allow_edit_history: z.boolean(),
|
realm_allow_edit_history: z.boolean(),
|
||||||
|
realm_allow_message_editing: NOT_TYPED_YET,
|
||||||
realm_authentication_methods: z.record(
|
realm_authentication_methods: z.record(
|
||||||
z.object({
|
z.object({
|
||||||
enabled: z.boolean(),
|
enabled: z.boolean(),
|
||||||
@@ -82,6 +101,7 @@ export const realm_schema = z.object({
|
|||||||
big_blue_button: z.optional(z.object({name: z.string(), id: z.number()})),
|
big_blue_button: z.optional(z.object({name: z.string(), id: z.number()})),
|
||||||
}),
|
}),
|
||||||
realm_avatar_changes_disabled: z.boolean(),
|
realm_avatar_changes_disabled: z.boolean(),
|
||||||
|
realm_bot_creation_policy: NOT_TYPED_YET,
|
||||||
realm_bot_domain: z.string(),
|
realm_bot_domain: z.string(),
|
||||||
realm_can_access_all_users_group: z.number(),
|
realm_can_access_all_users_group: z.number(),
|
||||||
realm_can_create_public_channel_group: z.number(),
|
realm_can_create_public_channel_group: z.number(),
|
||||||
@@ -103,6 +123,8 @@ export const realm_schema = z.object({
|
|||||||
realm_default_language: z.string(),
|
realm_default_language: z.string(),
|
||||||
realm_delete_own_message_policy: z.number(),
|
realm_delete_own_message_policy: z.number(),
|
||||||
realm_description: z.string(),
|
realm_description: z.string(),
|
||||||
|
realm_digest_emails_enabled: NOT_TYPED_YET,
|
||||||
|
realm_digest_weekday: NOT_TYPED_YET,
|
||||||
realm_disallow_disposable_email_addresses: z.boolean(),
|
realm_disallow_disposable_email_addresses: z.boolean(),
|
||||||
realm_domains: z.array(
|
realm_domains: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
@@ -111,10 +133,14 @@ export const realm_schema = z.object({
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
realm_edit_topic_policy: z.number(),
|
realm_edit_topic_policy: z.number(),
|
||||||
|
realm_email_auth_enabled: NOT_TYPED_YET,
|
||||||
realm_email_changes_disabled: z.boolean(),
|
realm_email_changes_disabled: z.boolean(),
|
||||||
realm_emails_restricted_to_domains: z.boolean(),
|
realm_emails_restricted_to_domains: z.boolean(),
|
||||||
|
realm_embedded_bots: NOT_TYPED_YET,
|
||||||
realm_enable_guest_user_indicator: z.boolean(),
|
realm_enable_guest_user_indicator: z.boolean(),
|
||||||
|
realm_enable_read_receipts: NOT_TYPED_YET,
|
||||||
realm_enable_spectator_access: z.boolean(),
|
realm_enable_spectator_access: z.boolean(),
|
||||||
|
realm_giphy_rating: NOT_TYPED_YET,
|
||||||
realm_icon_source: z.string(),
|
realm_icon_source: z.string(),
|
||||||
realm_icon_url: z.string(),
|
realm_icon_url: z.string(),
|
||||||
realm_incoming_webhook_bots: z.array(
|
realm_incoming_webhook_bots: z.array(
|
||||||
@@ -125,6 +151,9 @@ export const realm_schema = z.object({
|
|||||||
// We currently ignore the `config` field in these objects.
|
// We currently ignore the `config` field in these objects.
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
realm_inline_image_preview: NOT_TYPED_YET,
|
||||||
|
realm_inline_url_embed_preview: NOT_TYPED_YET,
|
||||||
|
realm_invite_required: NOT_TYPED_YET,
|
||||||
realm_invite_to_realm_policy: z.number(),
|
realm_invite_to_realm_policy: z.number(),
|
||||||
realm_invite_to_stream_policy: z.number(),
|
realm_invite_to_stream_policy: z.number(),
|
||||||
realm_is_zephyr_mirror_realm: z.boolean(),
|
realm_is_zephyr_mirror_realm: z.boolean(),
|
||||||
@@ -139,6 +168,7 @@ export const realm_schema = z.object({
|
|||||||
realm_logo_source: z.string(),
|
realm_logo_source: z.string(),
|
||||||
realm_logo_url: z.string(),
|
realm_logo_url: z.string(),
|
||||||
realm_mandatory_topics: z.boolean(),
|
realm_mandatory_topics: z.boolean(),
|
||||||
|
realm_message_content_allowed_in_email_notifications: NOT_TYPED_YET,
|
||||||
realm_message_content_edit_limit_seconds: z.number().nullable(),
|
realm_message_content_edit_limit_seconds: z.number().nullable(),
|
||||||
realm_message_content_delete_limit_seconds: z.number().nullable(),
|
realm_message_content_delete_limit_seconds: z.number().nullable(),
|
||||||
realm_message_retention_days: z.number(),
|
realm_message_retention_days: z.number(),
|
||||||
@@ -151,6 +181,7 @@ export const realm_schema = z.object({
|
|||||||
realm_night_logo_source: z.string(),
|
realm_night_logo_source: z.string(),
|
||||||
realm_night_logo_url: z.string(),
|
realm_night_logo_url: z.string(),
|
||||||
realm_org_type: z.number(),
|
realm_org_type: z.number(),
|
||||||
|
realm_password_auth_enabled: NOT_TYPED_YET,
|
||||||
realm_plan_type: z.number(),
|
realm_plan_type: z.number(),
|
||||||
realm_playgrounds: z.array(
|
realm_playgrounds: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
@@ -163,16 +194,22 @@ export const realm_schema = z.object({
|
|||||||
realm_presence_disabled: z.boolean(),
|
realm_presence_disabled: z.boolean(),
|
||||||
realm_private_message_policy: z.number(),
|
realm_private_message_policy: z.number(),
|
||||||
realm_push_notifications_enabled: z.boolean(),
|
realm_push_notifications_enabled: z.boolean(),
|
||||||
|
realm_push_notifications_enabled_end_timestamp: NOT_TYPED_YET,
|
||||||
realm_require_unique_names: z.boolean(),
|
realm_require_unique_names: z.boolean(),
|
||||||
|
realm_send_welcome_emails: NOT_TYPED_YET,
|
||||||
realm_signup_announcements_stream_id: z.number(),
|
realm_signup_announcements_stream_id: z.number(),
|
||||||
realm_upload_quota_mib: z.nullable(z.number()),
|
realm_upload_quota_mib: z.nullable(z.number()),
|
||||||
realm_url: z.string(),
|
realm_url: z.string(),
|
||||||
realm_user_group_edit_policy: z.number(),
|
realm_user_group_edit_policy: z.number(),
|
||||||
realm_video_chat_provider: z.number(),
|
realm_video_chat_provider: z.number(),
|
||||||
realm_waiting_period_threshold: z.number(),
|
realm_waiting_period_threshold: z.number(),
|
||||||
|
realm_want_advertise_in_communities_directory: NOT_TYPED_YET,
|
||||||
realm_wildcard_mention_policy: z.number(),
|
realm_wildcard_mention_policy: z.number(),
|
||||||
realm_zulip_update_announcements_stream_id: z.number(),
|
realm_zulip_update_announcements_stream_id: z.number(),
|
||||||
server_avatar_changes_disabled: z.boolean(),
|
server_avatar_changes_disabled: z.boolean(),
|
||||||
|
server_emoji_data_url: NOT_TYPED_YET,
|
||||||
|
server_inline_image_preview: NOT_TYPED_YET,
|
||||||
|
server_inline_url_embed_preview: NOT_TYPED_YET,
|
||||||
server_jitsi_server_url: z.nullable(z.string()),
|
server_jitsi_server_url: z.nullable(z.string()),
|
||||||
server_name_changes_disabled: z.boolean(),
|
server_name_changes_disabled: z.boolean(),
|
||||||
server_needs_upgrade: z.boolean(),
|
server_needs_upgrade: z.boolean(),
|
||||||
@@ -187,25 +224,105 @@ export const realm_schema = z.object({
|
|||||||
server_typing_started_wait_period_milliseconds: z.number(),
|
server_typing_started_wait_period_milliseconds: z.number(),
|
||||||
server_typing_stopped_wait_period_milliseconds: z.number(),
|
server_typing_stopped_wait_period_milliseconds: z.number(),
|
||||||
server_web_public_streams_enabled: z.boolean(),
|
server_web_public_streams_enabled: z.boolean(),
|
||||||
|
settings_send_digest_emails: NOT_TYPED_YET,
|
||||||
stop_words: z.array(z.string()),
|
stop_words: z.array(z.string()),
|
||||||
|
upgrade_text_for_wide_organization_logo: NOT_TYPED_YET,
|
||||||
|
zulip_feature_level: NOT_TYPED_YET,
|
||||||
zulip_merge_base: z.string(),
|
zulip_merge_base: z.string(),
|
||||||
zulip_plan_is_not_limited: z.boolean(),
|
zulip_plan_is_not_limited: z.boolean(),
|
||||||
zulip_version: z.string(),
|
zulip_version: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const state_data_schema = current_user_schema
|
export const state_data_schema = z
|
||||||
.merge(realm_schema)
|
.object({alert_words: NOT_TYPED_YET})
|
||||||
// TODO/typescript: Remove .passthrough() when all consumers have been
|
.transform((alert_words) => ({alert_words}))
|
||||||
// converted to TypeScript and the schema is complete.
|
.and(z.object({realm_emoji: NOT_TYPED_YET}).transform((emoji) => ({emoji})))
|
||||||
.passthrough();
|
.and(z.object({realm_bots: NOT_TYPED_YET}).transform((bot) => ({bot})))
|
||||||
|
.and(
|
||||||
|
z
|
||||||
|
.object({
|
||||||
|
realm_users: NOT_TYPED_YET,
|
||||||
|
realm_non_active_users: NOT_TYPED_YET,
|
||||||
|
cross_realm_bots: NOT_TYPED_YET,
|
||||||
|
})
|
||||||
|
.transform((people) => ({people})),
|
||||||
|
)
|
||||||
|
.and(
|
||||||
|
z
|
||||||
|
.object({recent_private_conversations: NOT_TYPED_YET})
|
||||||
|
.transform((pm_conversations) => ({pm_conversations})),
|
||||||
|
)
|
||||||
|
.and(
|
||||||
|
z
|
||||||
|
.object({
|
||||||
|
presences: NOT_TYPED_YET,
|
||||||
|
server_timestamp: NOT_TYPED_YET,
|
||||||
|
presence_last_update_id: NOT_TYPED_YET,
|
||||||
|
})
|
||||||
|
.transform((presence) => ({presence})),
|
||||||
|
)
|
||||||
|
.and(
|
||||||
|
z
|
||||||
|
.object({starred_messages: NOT_TYPED_YET})
|
||||||
|
.transform((starred_messages) => ({starred_messages})),
|
||||||
|
)
|
||||||
|
.and(
|
||||||
|
z
|
||||||
|
.object({
|
||||||
|
subscriptions: NOT_TYPED_YET,
|
||||||
|
unsubscribed: NOT_TYPED_YET,
|
||||||
|
never_subscribed: NOT_TYPED_YET,
|
||||||
|
realm_default_streams: NOT_TYPED_YET,
|
||||||
|
})
|
||||||
|
.transform((stream_data) => ({stream_data})),
|
||||||
|
)
|
||||||
|
.and(z.object({realm_user_groups: NOT_TYPED_YET}).transform((user_groups) => ({user_groups})))
|
||||||
|
.and(z.object({unread_msgs: NOT_TYPED_YET}).transform((unread) => ({unread})))
|
||||||
|
.and(z.object({muted_users: NOT_TYPED_YET}).transform((muted_users) => ({muted_users})))
|
||||||
|
.and(z.object({user_topics: NOT_TYPED_YET}).transform((user_topics) => ({user_topics})))
|
||||||
|
.and(z.object({user_status: NOT_TYPED_YET}).transform((user_status) => ({user_status})))
|
||||||
|
.and(z.object({user_settings: NOT_TYPED_YET}).transform((user_settings) => ({user_settings})))
|
||||||
|
.and(
|
||||||
|
z
|
||||||
|
.object({realm_user_settings_defaults: NOT_TYPED_YET})
|
||||||
|
.transform((realm_settings_defaults) => ({realm_settings_defaults})),
|
||||||
|
)
|
||||||
|
.and(
|
||||||
|
z
|
||||||
|
.object({scheduled_messages: NOT_TYPED_YET})
|
||||||
|
.transform((scheduled_messages) => ({scheduled_messages})),
|
||||||
|
)
|
||||||
|
.and(
|
||||||
|
z
|
||||||
|
.object({
|
||||||
|
queue_id: NOT_TYPED_YET,
|
||||||
|
server_generation: NOT_TYPED_YET,
|
||||||
|
event_queue_longpoll_timeout_seconds: NOT_TYPED_YET,
|
||||||
|
last_event_id: NOT_TYPED_YET,
|
||||||
|
})
|
||||||
|
.transform((server_events) => ({server_events})),
|
||||||
|
)
|
||||||
|
.and(z.object({max_message_id: NOT_TYPED_YET}).transform((local_message) => ({local_message})))
|
||||||
|
.and(
|
||||||
|
z
|
||||||
|
.object({onboarding_steps: NOT_TYPED_YET})
|
||||||
|
.transform((onboarding_steps) => ({onboarding_steps})),
|
||||||
|
)
|
||||||
|
.and(current_user_schema.transform((current_user) => ({current_user})))
|
||||||
|
.and(realm_schema.transform((realm) => ({realm})));
|
||||||
|
|
||||||
export let current_user: z.infer<typeof current_user_schema>;
|
export type StateData = z.infer<typeof state_data_schema>;
|
||||||
export let realm: z.infer<typeof realm_schema>;
|
|
||||||
|
|
||||||
export function set_current_user(initial_current_user: z.infer<typeof current_user_schema>): void {
|
export type CurrentUser = StateData["current_user"];
|
||||||
|
export type Realm = StateData["realm"];
|
||||||
|
|
||||||
|
export let current_user: CurrentUser;
|
||||||
|
export let realm: Realm;
|
||||||
|
|
||||||
|
export function set_current_user(initial_current_user: CurrentUser): void {
|
||||||
current_user = initial_current_user;
|
current_user = initial_current_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function set_realm(initial_realm: z.infer<typeof realm_schema>): void {
|
export function set_realm(initial_realm: Realm): void {
|
||||||
realm = initial_realm;
|
realm = initial_realm;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -405,260 +405,20 @@ export function initialize_everything(state_data) {
|
|||||||
any data that you see in the app soon after page
|
any data that you see in the app soon after page
|
||||||
load comes from `state_data`.
|
load comes from `state_data`.
|
||||||
|
|
||||||
## Mostly static data
|
The version of `state_data` that we've been passed has already been
|
||||||
|
split using Zod `.transform` invocations into a number of parts; see
|
||||||
Now, we mostly leave `state_data` intact through
|
`state_data_schema` in `state_data.ts`. Below we pass each part to the
|
||||||
the duration of the app. Most of the data in
|
initialization function for the corresponding module.
|
||||||
`state_data` is fairly static in nature, and we
|
|
||||||
will simply update it for basic changes like
|
|
||||||
the following (meant as examples, not gospel):
|
|
||||||
|
|
||||||
- I changed my 24-hour time preference.
|
|
||||||
- The realm admin changed who can edit topics.
|
|
||||||
- The team's realm icon has changed.
|
|
||||||
- I switched from light theme to dark theme.
|
|
||||||
|
|
||||||
Especially for things that are settings-related,
|
|
||||||
we rarely abstract away the data from `state_data`.
|
|
||||||
As of this writing, over 90 modules refer directly
|
|
||||||
to `state_data` for some reason or another.
|
|
||||||
|
|
||||||
## Dynamic data
|
|
||||||
|
|
||||||
Some of the data in `state_data` is either
|
|
||||||
more highly dynamic than settings data, or
|
|
||||||
has more performance requirements than
|
|
||||||
simple settings data, or both. Examples
|
|
||||||
include:
|
|
||||||
|
|
||||||
- tracking all users (we want to have
|
|
||||||
multiple Maps to find users, for example)
|
|
||||||
- tracking all streams
|
|
||||||
- tracking presence data
|
|
||||||
- tracking user groups and bots
|
|
||||||
- tracking recent direct messages
|
|
||||||
|
|
||||||
Using stream data as an example, we use a
|
|
||||||
module called `stream_data` to actually track
|
|
||||||
all the info about the streams that a user
|
|
||||||
can know about. We populate this module
|
|
||||||
with data from `state_data`, but thereafter
|
|
||||||
`stream_data.js` "owns" the stream data:
|
|
||||||
|
|
||||||
- other modules should ask `stream_data`
|
|
||||||
for stuff (and not go to `state_data`)
|
|
||||||
- when server events come in, they should
|
|
||||||
be processed by stream_data to update
|
|
||||||
its own data structures
|
|
||||||
|
|
||||||
To help enforce this paradigm, we do the
|
|
||||||
following:
|
|
||||||
|
|
||||||
- only pass `stream_data` what it needs
|
|
||||||
from `state_data`
|
|
||||||
- delete the reference to data owned by
|
|
||||||
`stream_data` in `state_data` itself
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function pop_fields(...fields) {
|
set_current_user(state_data.current_user);
|
||||||
const result = {};
|
set_realm(state_data.realm);
|
||||||
|
|
||||||
for (const field of fields) {
|
|
||||||
result[field] = state_data[field];
|
|
||||||
delete state_data[field];
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
const alert_words_params = pop_fields("alert_words");
|
|
||||||
|
|
||||||
const emoji_params = pop_fields("realm_emoji");
|
|
||||||
|
|
||||||
const bot_params = pop_fields("realm_bots");
|
|
||||||
|
|
||||||
const people_params = pop_fields("realm_users", "realm_non_active_users", "cross_realm_bots");
|
|
||||||
|
|
||||||
const pm_conversations_params = pop_fields("recent_private_conversations");
|
|
||||||
|
|
||||||
const presence_params = pop_fields("presences", "server_timestamp", "presence_last_update_id");
|
|
||||||
|
|
||||||
const starred_messages_params = pop_fields("starred_messages");
|
|
||||||
const stream_data_params = pop_fields(
|
|
||||||
"subscriptions",
|
|
||||||
"unsubscribed",
|
|
||||||
"never_subscribed",
|
|
||||||
"realm_default_streams",
|
|
||||||
);
|
|
||||||
|
|
||||||
const user_groups_params = pop_fields("realm_user_groups");
|
|
||||||
|
|
||||||
const unread_params = pop_fields("unread_msgs");
|
|
||||||
|
|
||||||
const muted_users_params = pop_fields("muted_users");
|
|
||||||
|
|
||||||
const user_topics_params = pop_fields("user_topics");
|
|
||||||
|
|
||||||
const user_status_params = pop_fields("user_status");
|
|
||||||
const user_settings_params = pop_fields("user_settings");
|
|
||||||
const realm_settings_defaults_params = pop_fields("realm_user_settings_defaults");
|
|
||||||
const scheduled_messages_params = pop_fields("scheduled_messages");
|
|
||||||
const server_events_params = pop_fields(
|
|
||||||
"queue_id",
|
|
||||||
"server_generation",
|
|
||||||
"event_queue_longpoll_timeout_seconds",
|
|
||||||
"last_event_id",
|
|
||||||
);
|
|
||||||
const local_message_params = pop_fields("max_message_id");
|
|
||||||
|
|
||||||
const onboarding_steps_params = pop_fields("onboarding_steps");
|
|
||||||
|
|
||||||
const current_user_params = pop_fields(
|
|
||||||
"avatar_source",
|
|
||||||
"avatar_url",
|
|
||||||
"avatar_url_medium",
|
|
||||||
"can_create_private_streams",
|
|
||||||
"can_create_public_streams",
|
|
||||||
"can_create_streams",
|
|
||||||
"can_create_web_public_streams",
|
|
||||||
"can_invite_others_to_realm",
|
|
||||||
"can_subscribe_other_users",
|
|
||||||
"delivery_email",
|
|
||||||
"email",
|
|
||||||
"full_name",
|
|
||||||
"has_zoom_token",
|
|
||||||
"is_admin",
|
|
||||||
"is_billing_admin",
|
|
||||||
"is_guest",
|
|
||||||
"is_moderator",
|
|
||||||
"is_owner",
|
|
||||||
"user_id",
|
|
||||||
);
|
|
||||||
|
|
||||||
const realm_params = pop_fields(
|
|
||||||
"custom_profile_field_types",
|
|
||||||
"custom_profile_fields",
|
|
||||||
"demo_organization_scheduled_deletion_date",
|
|
||||||
"giphy_api_key",
|
|
||||||
"giphy_rating_options",
|
|
||||||
"max_avatar_file_size_mib",
|
|
||||||
"max_file_upload_size_mib",
|
|
||||||
"max_icon_file_size_mib",
|
|
||||||
"max_logo_file_size_mib",
|
|
||||||
"max_message_length",
|
|
||||||
"max_stream_description_length",
|
|
||||||
"max_stream_name_length",
|
|
||||||
"max_topic_length",
|
|
||||||
"password_min_guesses",
|
|
||||||
"password_min_length",
|
|
||||||
"realm_add_custom_emoji_policy",
|
|
||||||
"realm_allow_edit_history",
|
|
||||||
"realm_allow_message_editing",
|
|
||||||
"realm_authentication_methods",
|
|
||||||
"realm_available_video_chat_providers",
|
|
||||||
"realm_avatar_changes_disabled",
|
|
||||||
"realm_bot_creation_policy",
|
|
||||||
"realm_bot_domain",
|
|
||||||
"realm_can_access_all_users_group",
|
|
||||||
"realm_can_create_private_channel_group",
|
|
||||||
"realm_can_create_public_channel_group",
|
|
||||||
"realm_create_multiuse_invite_group",
|
|
||||||
"realm_create_web_public_stream_policy",
|
|
||||||
"realm_date_created",
|
|
||||||
"realm_default_code_block_language",
|
|
||||||
"realm_default_external_accounts",
|
|
||||||
"realm_default_language",
|
|
||||||
"realm_delete_own_message_policy",
|
|
||||||
"realm_description",
|
|
||||||
"realm_digest_emails_enabled",
|
|
||||||
"realm_digest_weekday",
|
|
||||||
"realm_disallow_disposable_email_addresses",
|
|
||||||
"realm_domains",
|
|
||||||
"realm_edit_topic_policy",
|
|
||||||
"realm_email_auth_enabled",
|
|
||||||
"realm_email_changes_disabled",
|
|
||||||
"realm_emails_restricted_to_domains",
|
|
||||||
"realm_embedded_bots",
|
|
||||||
"realm_enable_guest_user_indicator",
|
|
||||||
"realm_enable_read_receipts",
|
|
||||||
"realm_enable_spectator_access",
|
|
||||||
"realm_giphy_rating",
|
|
||||||
"realm_icon_source",
|
|
||||||
"realm_icon_url",
|
|
||||||
"realm_incoming_webhook_bots",
|
|
||||||
"realm_inline_image_preview",
|
|
||||||
"realm_inline_url_embed_preview",
|
|
||||||
"realm_invite_required",
|
|
||||||
"realm_invite_to_realm_policy",
|
|
||||||
"realm_invite_to_stream_policy",
|
|
||||||
"realm_is_zephyr_mirror_realm",
|
|
||||||
"realm_jitsi_server_url",
|
|
||||||
"realm_linkifiers",
|
|
||||||
"realm_logo_source",
|
|
||||||
"realm_logo_url",
|
|
||||||
"realm_mandatory_topics",
|
|
||||||
"realm_message_content_allowed_in_email_notifications",
|
|
||||||
"realm_message_content_delete_limit_seconds",
|
|
||||||
"realm_message_content_edit_limit_seconds",
|
|
||||||
"realm_message_retention_days",
|
|
||||||
"realm_move_messages_between_streams_limit_seconds",
|
|
||||||
"realm_move_messages_between_streams_policy",
|
|
||||||
"realm_move_messages_within_stream_limit_seconds",
|
|
||||||
"realm_name",
|
|
||||||
"realm_name_changes_disabled",
|
|
||||||
"realm_new_stream_announcements_stream_id",
|
|
||||||
"realm_night_logo_source",
|
|
||||||
"realm_night_logo_url",
|
|
||||||
"realm_org_type",
|
|
||||||
"realm_password_auth_enabled",
|
|
||||||
"realm_plan_type",
|
|
||||||
"realm_playgrounds",
|
|
||||||
"realm_presence_disabled",
|
|
||||||
"realm_private_message_policy",
|
|
||||||
"realm_push_notifications_enabled",
|
|
||||||
"realm_push_notifications_enabled_end_timestamp",
|
|
||||||
"realm_require_unique_names",
|
|
||||||
"realm_send_welcome_emails",
|
|
||||||
"realm_signup_announcements_stream_id",
|
|
||||||
"realm_upload_quota_mib",
|
|
||||||
"realm_url",
|
|
||||||
"realm_user_group_edit_policy",
|
|
||||||
"realm_video_chat_provider",
|
|
||||||
"realm_waiting_period_threshold",
|
|
||||||
"realm_want_advertise_in_communities_directory",
|
|
||||||
"realm_wildcard_mention_policy",
|
|
||||||
"realm_zulip_update_announcements_stream_id",
|
|
||||||
"server_avatar_changes_disabled",
|
|
||||||
"server_emoji_data_url",
|
|
||||||
"server_inline_image_preview",
|
|
||||||
"server_inline_url_embed_preview",
|
|
||||||
"server_jitsi_server_url",
|
|
||||||
"server_name_changes_disabled",
|
|
||||||
"server_needs_upgrade",
|
|
||||||
"server_presence_offline_threshold_seconds",
|
|
||||||
"server_presence_ping_interval_seconds",
|
|
||||||
"server_supported_permission_settings",
|
|
||||||
"server_typing_started_expiry_period_milliseconds",
|
|
||||||
"server_typing_started_wait_period_milliseconds",
|
|
||||||
"server_typing_stopped_wait_period_milliseconds",
|
|
||||||
"server_web_public_streams_enabled",
|
|
||||||
"settings_send_digest_emails",
|
|
||||||
"stop_words",
|
|
||||||
"upgrade_text_for_wide_organization_logo",
|
|
||||||
"zulip_feature_level",
|
|
||||||
"zulip_merge_base",
|
|
||||||
"zulip_plan_is_not_limited",
|
|
||||||
"zulip_version",
|
|
||||||
);
|
|
||||||
|
|
||||||
set_current_user(current_user_params);
|
|
||||||
set_realm(realm_params);
|
|
||||||
sentry.initialize();
|
sentry.initialize();
|
||||||
|
|
||||||
/* To store theme data for spectators, we need to initialize
|
/* To store theme data for spectators, we need to initialize
|
||||||
user_settings before setting the theme. Because information
|
user_settings before setting the theme. Because information
|
||||||
density is so fundamental, we initialize that first, however. */
|
density is so fundamental, we initialize that first, however. */
|
||||||
initialize_user_settings(user_settings_params);
|
initialize_user_settings(state_data.user_settings);
|
||||||
sidebar_ui.restore_sidebar_toggle_status();
|
sidebar_ui.restore_sidebar_toggle_status();
|
||||||
information_density.initialize();
|
information_density.initialize();
|
||||||
if (page_params.is_spectator) {
|
if (page_params.is_spectator) {
|
||||||
@@ -678,7 +438,7 @@ export function initialize_everything(state_data) {
|
|||||||
compose_tooltips.initialize();
|
compose_tooltips.initialize();
|
||||||
message_list_tooltips.initialize();
|
message_list_tooltips.initialize();
|
||||||
// This populates data for scheduled messages.
|
// This populates data for scheduled messages.
|
||||||
scheduled_messages.initialize(scheduled_messages_params);
|
scheduled_messages.initialize(state_data.scheduled_messages);
|
||||||
scheduled_messages_ui.initialize();
|
scheduled_messages_ui.initialize();
|
||||||
popover_menus.initialize();
|
popover_menus.initialize();
|
||||||
compose_popovers.initialize();
|
compose_popovers.initialize();
|
||||||
@@ -688,9 +448,9 @@ export function initialize_everything(state_data) {
|
|||||||
message_actions_popover.initialize();
|
message_actions_popover.initialize();
|
||||||
compose_send_menu_popover.initialize();
|
compose_send_menu_popover.initialize();
|
||||||
|
|
||||||
realm_user_settings_defaults.initialize(realm_settings_defaults_params);
|
realm_user_settings_defaults.initialize(state_data.realm_settings_defaults);
|
||||||
people.initialize(current_user.user_id, people_params);
|
people.initialize(current_user.user_id, state_data.people);
|
||||||
starred_messages.initialize(starred_messages_params);
|
starred_messages.initialize(state_data.starred_messages);
|
||||||
|
|
||||||
let date_joined;
|
let date_joined;
|
||||||
if (!page_params.is_spectator) {
|
if (!page_params.is_spectator) {
|
||||||
@@ -707,14 +467,14 @@ export function initialize_everything(state_data) {
|
|||||||
// The emoji module must be initialized before the right sidebar
|
// The emoji module must be initialized before the right sidebar
|
||||||
// module, so that we can display custom emoji in statuses.
|
// module, so that we can display custom emoji in statuses.
|
||||||
emoji.initialize({
|
emoji.initialize({
|
||||||
realm_emoji: emoji_params.realm_emoji,
|
realm_emoji: state_data.emoji.realm_emoji,
|
||||||
emoji_codes: generated_emoji_codes,
|
emoji_codes: generated_emoji_codes,
|
||||||
});
|
});
|
||||||
|
|
||||||
// The user_group must be initialized before right sidebar
|
// The user_group must be initialized before right sidebar
|
||||||
// module, so that we can tell whether user is member of
|
// module, so that we can tell whether user is member of
|
||||||
// user_group whose members are allowed to create multiuse invite.
|
// user_group whose members are allowed to create multiuse invite.
|
||||||
user_groups.initialize(user_groups_params);
|
user_groups.initialize(state_data.user_groups);
|
||||||
|
|
||||||
// These components must be initialized early, because other
|
// These components must be initialized early, because other
|
||||||
// modules' initialization has not been audited for whether they
|
// modules' initialization has not been audited for whether they
|
||||||
@@ -749,14 +509,14 @@ export function initialize_everything(state_data) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
inbox_ui.initialize();
|
inbox_ui.initialize();
|
||||||
alert_words.initialize(alert_words_params);
|
alert_words.initialize(state_data.alert_words);
|
||||||
emojisets.initialize();
|
emojisets.initialize();
|
||||||
scroll_bar.initialize();
|
scroll_bar.initialize();
|
||||||
message_viewport.initialize();
|
message_viewport.initialize();
|
||||||
navbar_alerts.initialize();
|
navbar_alerts.initialize();
|
||||||
message_list_hover.initialize();
|
message_list_hover.initialize();
|
||||||
initialize_kitchen_sink_stuff();
|
initialize_kitchen_sink_stuff();
|
||||||
local_message.initialize(local_message_params);
|
local_message.initialize(state_data.local_message);
|
||||||
echo.initialize({
|
echo.initialize({
|
||||||
on_send_message_success: compose.send_message_success,
|
on_send_message_success: compose.send_message_success,
|
||||||
send_message: transmit.send_message,
|
send_message: transmit.send_message,
|
||||||
@@ -764,11 +524,11 @@ export function initialize_everything(state_data) {
|
|||||||
stream_edit.initialize();
|
stream_edit.initialize();
|
||||||
user_group_edit.initialize();
|
user_group_edit.initialize();
|
||||||
stream_edit_subscribers.initialize();
|
stream_edit_subscribers.initialize();
|
||||||
stream_data.initialize(stream_data_params);
|
stream_data.initialize(state_data.stream_data);
|
||||||
user_group_edit_members.initialize();
|
user_group_edit_members.initialize();
|
||||||
pm_conversations.recent.initialize(pm_conversations_params);
|
pm_conversations.recent.initialize(state_data.pm_conversations);
|
||||||
user_topics.initialize(user_topics_params);
|
user_topics.initialize(state_data.user_topics);
|
||||||
muted_users.initialize(muted_users_params);
|
muted_users.initialize(state_data.muted_users);
|
||||||
stream_settings_ui.initialize();
|
stream_settings_ui.initialize();
|
||||||
left_sidebar_navigation_area.initialize();
|
left_sidebar_navigation_area.initialize();
|
||||||
stream_list.initialize({
|
stream_list.initialize({
|
||||||
@@ -802,8 +562,8 @@ export function initialize_everything(state_data) {
|
|||||||
overlays.initialize();
|
overlays.initialize();
|
||||||
invite.initialize();
|
invite.initialize();
|
||||||
message_view_header.initialize();
|
message_view_header.initialize();
|
||||||
server_events.initialize(server_events_params);
|
server_events.initialize(state_data.server_events);
|
||||||
user_status.initialize(user_status_params);
|
user_status.initialize(state_data.user_status);
|
||||||
compose_recipient.initialize();
|
compose_recipient.initialize();
|
||||||
compose_pm_pill.initialize({
|
compose_pm_pill.initialize({
|
||||||
on_pill_create_or_remove: compose_recipient.update_placeholder_text,
|
on_pill_create_or_remove: compose_recipient.update_placeholder_text,
|
||||||
@@ -812,8 +572,8 @@ export function initialize_everything(state_data) {
|
|||||||
compose_reply.initialize();
|
compose_reply.initialize();
|
||||||
drafts.initialize(); // Must happen before reload_setup.initialize()
|
drafts.initialize(); // Must happen before reload_setup.initialize()
|
||||||
reload_setup.initialize();
|
reload_setup.initialize();
|
||||||
unread.initialize(unread_params);
|
unread.initialize(state_data.unread);
|
||||||
bot_data.initialize(bot_params); // Must happen after people.initialize()
|
bot_data.initialize(state_data.bot); // Must happen after people.initialize()
|
||||||
message_fetch.initialize(() => {
|
message_fetch.initialize(() => {
|
||||||
recent_view_ui.set_initial_message_fetch_status(false);
|
recent_view_ui.set_initial_message_fetch_status(false);
|
||||||
recent_view_ui.revive_current_focus();
|
recent_view_ui.revive_current_focus();
|
||||||
@@ -848,7 +608,7 @@ export function initialize_everything(state_data) {
|
|||||||
gear_menu.initialize();
|
gear_menu.initialize();
|
||||||
navbar_help_menu.initialize();
|
navbar_help_menu.initialize();
|
||||||
giphy.initialize();
|
giphy.initialize();
|
||||||
presence.initialize(presence_params);
|
presence.initialize(state_data.presence);
|
||||||
settings_preferences.initialize();
|
settings_preferences.initialize();
|
||||||
settings_notifications.initialize();
|
settings_notifications.initialize();
|
||||||
settings_realm_user_settings_defaults.initialize();
|
settings_realm_user_settings_defaults.initialize();
|
||||||
@@ -899,7 +659,7 @@ export function initialize_everything(state_data) {
|
|||||||
});
|
});
|
||||||
drafts.initialize_ui();
|
drafts.initialize_ui();
|
||||||
drafts_overlay_ui.initialize();
|
drafts_overlay_ui.initialize();
|
||||||
onboarding_steps.initialize(onboarding_steps_params);
|
onboarding_steps.initialize(state_data.onboarding_steps);
|
||||||
typing.initialize();
|
typing.initialize();
|
||||||
starred_messages_ui.initialize();
|
starred_messages_ui.initialize();
|
||||||
user_status_ui.initialize();
|
user_status_ui.initialize();
|
||||||
|
|||||||
Reference in New Issue
Block a user