2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 01:13:42 +01:00
|
|
|
import * as activity from "./activity";
|
2021-02-10 17:02:31 +01:00
|
|
|
import * as alert_words from "./alert_words";
|
2021-02-28 01:08:54 +01:00
|
|
|
import * as alert_words_ui from "./alert_words_ui";
|
2021-02-28 01:09:13 +01:00
|
|
|
import * as attachments_ui from "./attachments_ui";
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-02-28 01:24:30 +01:00
|
|
|
import * as bot_data from "./bot_data";
|
2022-02-25 17:33:58 +01:00
|
|
|
import {buddy_list} from "./buddy_list";
|
2021-02-28 00:51:57 +01:00
|
|
|
import * as compose from "./compose";
|
2021-08-02 16:55:27 +02:00
|
|
|
import * as compose_actions from "./compose_actions";
|
2021-02-28 00:49:06 +01:00
|
|
|
import * as compose_fade from "./compose_fade";
|
2021-08-02 16:55:27 +02:00
|
|
|
import * as compose_pm_pill from "./compose_pm_pill";
|
2021-02-28 21:33:26 +01:00
|
|
|
import * as composebox_typeahead from "./composebox_typeahead";
|
2021-11-26 08:36:54 +01:00
|
|
|
import * as dark_theme from "./dark_theme";
|
2022-03-25 14:47:51 +01:00
|
|
|
import * as emoji from "./emoji";
|
2021-02-28 01:26:16 +01:00
|
|
|
import * as emoji_picker from "./emoji_picker";
|
2021-04-27 21:58:19 +02:00
|
|
|
import * as giphy from "./giphy";
|
2021-02-28 01:15:02 +01:00
|
|
|
import * as hotspots from "./hotspots";
|
2021-05-19 06:18:23 +02:00
|
|
|
import * as linkifiers from "./linkifiers";
|
2021-02-28 00:56:21 +01:00
|
|
|
import * as message_edit from "./message_edit";
|
2021-02-28 21:33:40 +01:00
|
|
|
import * as message_events from "./message_events";
|
2021-02-28 01:08:13 +01:00
|
|
|
import * as message_flags from "./message_flags";
|
2021-03-30 02:21:21 +02:00
|
|
|
import * as message_lists from "./message_lists";
|
2022-02-05 19:13:05 +01:00
|
|
|
import * as message_live_update from "./message_live_update";
|
2021-07-08 20:36:52 +02:00
|
|
|
import * as muted_topics_ui from "./muted_topics_ui";
|
2021-07-08 20:28:14 +02:00
|
|
|
import * as muted_users_ui from "./muted_users_ui";
|
2021-02-28 00:47:56 +01:00
|
|
|
import * as narrow_state from "./narrow_state";
|
2021-05-17 10:01:02 +02:00
|
|
|
import * as navbar_alerts from "./navbar_alerts";
|
2021-02-28 01:06:34 +01:00
|
|
|
import * as notifications from "./notifications";
|
2021-02-28 01:03:46 +01:00
|
|
|
import * as overlays from "./overlays";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-10 17:02:31 +01:00
|
|
|
import * as peer_data from "./peer_data";
|
|
|
|
import * as people from "./people";
|
2022-02-05 19:10:59 +01:00
|
|
|
import * as pm_list from "./pm_list";
|
2021-02-28 01:25:00 +01:00
|
|
|
import * as reactions from "./reactions";
|
2021-02-28 01:16:09 +01:00
|
|
|
import * as realm_icon from "./realm_icon";
|
2021-02-28 01:16:32 +01:00
|
|
|
import * as realm_logo from "./realm_logo";
|
2021-04-13 08:43:03 +02:00
|
|
|
import * as realm_playground from "./realm_playground";
|
2021-08-30 16:26:38 +02:00
|
|
|
import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
|
2021-02-28 00:48:40 +01:00
|
|
|
import * as reload from "./reload";
|
2021-02-28 01:01:53 +01:00
|
|
|
import * as scroll_bar from "./scroll_bar";
|
2021-02-28 01:18:00 +01:00
|
|
|
import * as settings_account from "./settings_account";
|
2021-02-28 01:19:16 +01:00
|
|
|
import * as settings_bots from "./settings_bots";
|
2021-02-10 17:02:31 +01:00
|
|
|
import * as settings_config from "./settings_config";
|
2021-02-28 01:18:22 +01:00
|
|
|
import * as settings_display from "./settings_display";
|
2021-02-28 01:19:58 +01:00
|
|
|
import * as settings_emoji from "./settings_emoji";
|
2021-02-28 01:20:19 +01:00
|
|
|
import * as settings_exports from "./settings_exports";
|
2021-02-28 01:22:20 +01:00
|
|
|
import * as settings_invites from "./settings_invites";
|
2021-02-28 01:21:57 +01:00
|
|
|
import * as settings_linkifiers from "./settings_linkifiers";
|
2021-02-28 01:18:48 +01:00
|
|
|
import * as settings_notifications from "./settings_notifications";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as settings_org from "./settings_org";
|
2021-04-16 04:04:18 +02:00
|
|
|
import * as settings_playgrounds from "./settings_playgrounds";
|
2021-02-28 21:34:05 +01:00
|
|
|
import * as settings_profile_fields from "./settings_profile_fields";
|
2021-07-20 14:51:48 +02:00
|
|
|
import * as settings_realm_domains from "./settings_realm_domains";
|
2021-09-20 13:38:38 +02:00
|
|
|
import * as settings_realm_user_settings_defaults from "./settings_realm_user_settings_defaults";
|
2021-02-28 01:21:35 +01:00
|
|
|
import * as settings_streams from "./settings_streams";
|
2022-06-20 15:25:04 +02:00
|
|
|
import * as settings_user_groups from "./settings_user_groups_legacy";
|
2021-02-28 01:21:11 +01:00
|
|
|
import * as settings_users from "./settings_users";
|
2021-02-28 01:08:33 +01:00
|
|
|
import * as starred_messages from "./starred_messages";
|
2021-02-28 00:53:59 +01:00
|
|
|
import * as stream_data from "./stream_data";
|
2021-02-28 00:55:11 +01:00
|
|
|
import * as stream_events from "./stream_events";
|
2021-02-28 21:31:02 +01:00
|
|
|
import * as stream_list from "./stream_list";
|
2021-07-09 15:51:31 +02:00
|
|
|
import * as stream_settings_ui from "./stream_settings_ui";
|
2021-02-28 00:54:32 +01:00
|
|
|
import * as stream_topic_history from "./stream_topic_history";
|
2021-04-15 17:02:54 +02:00
|
|
|
import * as sub_store from "./sub_store";
|
2021-02-28 00:46:27 +01:00
|
|
|
import * as submessage from "./submessage";
|
2021-02-28 01:25:24 +01:00
|
|
|
import * as typing_events from "./typing_events";
|
2021-02-28 21:30:08 +01:00
|
|
|
import * as unread_ops from "./unread_ops";
|
2021-02-28 01:14:05 +01:00
|
|
|
import * as user_events from "./user_events";
|
2021-02-28 00:42:57 +01:00
|
|
|
import * as user_groups from "./user_groups";
|
2021-07-28 16:00:58 +02:00
|
|
|
import {user_settings} from "./user_settings";
|
2021-02-10 17:03:21 +01:00
|
|
|
import * as user_status from "./user_status";
|
2020-07-25 00:12:17 +02:00
|
|
|
|
2021-02-10 17:02:31 +01:00
|
|
|
export function dispatch_normal_event(event) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const noop = function () {};
|
2017-05-31 08:53:09 +02:00
|
|
|
switch (event.type) {
|
2020-07-15 02:14:03 +02:00
|
|
|
case "alert_words":
|
|
|
|
alert_words.set_words(event.alert_words);
|
2022-02-26 01:58:57 +01:00
|
|
|
alert_words_ui.rerender_alert_words_ui();
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
2020-06-11 12:12:12 +02:00
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "attachment":
|
|
|
|
attachments_ui.update_attachments(event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "custom_profile_fields":
|
|
|
|
page_params.custom_profile_fields = event.fields;
|
|
|
|
settings_profile_fields.populate_profile_fields(page_params.custom_profile_fields);
|
|
|
|
settings_account.add_custom_profile_fields_to_settings();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "default_streams":
|
|
|
|
stream_data.set_realm_default_streams(event.default_streams);
|
|
|
|
settings_streams.update_default_streams_table();
|
|
|
|
break;
|
2018-08-25 13:08:24 +02:00
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "delete_message": {
|
|
|
|
const msg_ids = event.message_ids;
|
|
|
|
// message is passed to unread.get_unread_messages,
|
|
|
|
// which returns all the unread messages out of a given list.
|
|
|
|
// So double marking something as read would not occur
|
|
|
|
unread_ops.process_read_messages_event(msg_ids);
|
2020-08-04 11:12:42 +02:00
|
|
|
// This methods updates message_list too and since stream_topic_history relies on it
|
|
|
|
// this method should be called first.
|
2020-11-12 22:43:04 +01:00
|
|
|
message_events.remove_messages(msg_ids);
|
2020-07-15 02:14:03 +02:00
|
|
|
|
|
|
|
if (event.message_type === "stream") {
|
|
|
|
stream_topic_history.remove_messages({
|
|
|
|
stream_id: event.stream_id,
|
|
|
|
topic_name: event.topic,
|
|
|
|
num_messages: msg_ids.length,
|
2020-08-04 11:12:42 +02:00
|
|
|
max_removed_msg_id: Math.max(...msg_ids),
|
2020-07-15 02:14:03 +02:00
|
|
|
});
|
|
|
|
stream_list.update_streams_sidebar();
|
2019-11-16 09:26:28 +01:00
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
|
|
|
|
break;
|
2017-05-31 08:53:09 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "has_zoom_token":
|
|
|
|
page_params.has_zoom_token = event.value;
|
|
|
|
if (event.value) {
|
|
|
|
for (const callback of compose.zoom_token_callbacks.values()) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
compose.zoom_token_callbacks.clear();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "hotspots":
|
|
|
|
hotspots.load_new(event.hotspots);
|
2020-07-15 00:34:28 +02:00
|
|
|
page_params.hotspots = page_params.hotspots
|
|
|
|
? page_params.hotspots.concat(event.hotspots)
|
|
|
|
: event.hotspots;
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "invites_changed":
|
|
|
|
if ($("#admin-invites-list").length) {
|
|
|
|
settings_invites.set_up(false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-08-26 22:59:07 +02:00
|
|
|
case "user_topic":
|
|
|
|
muted_topics_ui.handle_topic_updates(event);
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
|
|
|
|
2021-03-27 12:42:16 +01:00
|
|
|
case "muted_users":
|
2021-07-08 20:28:14 +02:00
|
|
|
muted_users_ui.handle_user_updates(event.muted_users);
|
2021-03-27 12:42:16 +01:00
|
|
|
break;
|
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "presence":
|
|
|
|
activity.update_presence_info(event.user_id, event.presence, event.server_timestamp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "restart": {
|
|
|
|
const reload_options = {
|
|
|
|
save_pointer: true,
|
|
|
|
save_narrow: true,
|
|
|
|
save_compose: true,
|
2021-04-13 05:18:25 +02:00
|
|
|
message_html: "The application has been updated; reloading!",
|
2020-07-15 02:14:03 +02:00
|
|
|
};
|
|
|
|
if (event.immediate) {
|
|
|
|
reload_options.immediate = true;
|
|
|
|
}
|
|
|
|
reload.initiate(reload_options);
|
|
|
|
break;
|
2017-05-31 08:53:09 +02:00
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
|
|
|
|
case "reaction":
|
2020-06-20 21:24:47 +02:00
|
|
|
switch (event.op) {
|
|
|
|
case "add":
|
|
|
|
reactions.add_reaction(event);
|
|
|
|
break;
|
|
|
|
case "remove":
|
|
|
|
reactions.remove_reaction(event);
|
|
|
|
break;
|
2021-03-24 13:20:01 +01:00
|
|
|
default:
|
|
|
|
blueslip.error("Unexpected event type reaction/" + event.op);
|
|
|
|
break;
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "realm": {
|
|
|
|
const realm_settings = {
|
2021-05-04 19:02:24 +02:00
|
|
|
add_custom_emoji_policy: settings_emoji.update_custom_emoji_ui,
|
2020-07-15 02:14:03 +02:00
|
|
|
allow_edit_history: noop,
|
|
|
|
allow_message_editing: noop,
|
2021-05-26 12:21:37 +02:00
|
|
|
edit_topic_policy: noop,
|
2020-07-15 02:14:03 +02:00
|
|
|
user_group_edit_policy: noop,
|
|
|
|
avatar_changes_disabled: settings_account.update_avatar_change_display,
|
|
|
|
bot_creation_policy: settings_bots.update_bot_permissions_ui,
|
2021-03-27 05:48:37 +01:00
|
|
|
create_public_stream_policy: noop,
|
|
|
|
create_private_stream_policy: noop,
|
2021-11-24 15:02:14 +01:00
|
|
|
create_web_public_stream_policy: noop,
|
2020-07-15 02:14:03 +02:00
|
|
|
invite_to_stream_policy: noop,
|
|
|
|
default_code_block_language: noop,
|
|
|
|
default_language: noop,
|
2021-06-08 13:45:14 +02:00
|
|
|
delete_own_message_policy: noop,
|
2020-07-15 02:14:03 +02:00
|
|
|
description: noop,
|
|
|
|
digest_emails_enabled: noop,
|
|
|
|
digest_weekday: noop,
|
|
|
|
email_address_visibility: noop,
|
|
|
|
email_changes_disabled: settings_account.update_email_change_display,
|
|
|
|
disallow_disposable_email_addresses: noop,
|
|
|
|
inline_image_preview: noop,
|
|
|
|
inline_url_embed_preview: noop,
|
2021-04-02 18:47:08 +02:00
|
|
|
invite_to_realm_policy: noop,
|
2020-07-15 02:14:03 +02:00
|
|
|
invite_required: noop,
|
|
|
|
mandatory_topics: noop,
|
|
|
|
message_content_edit_limit_seconds: noop,
|
|
|
|
message_content_delete_limit_seconds: noop,
|
|
|
|
message_retention_days: noop,
|
|
|
|
name: notifications.redraw_title,
|
|
|
|
name_changes_disabled: settings_account.update_name_change_display,
|
|
|
|
notifications_stream_id: noop,
|
2022-04-12 17:41:07 +02:00
|
|
|
org_type: noop,
|
2020-07-15 02:14:03 +02:00
|
|
|
private_message_policy: noop,
|
|
|
|
send_welcome_emails: noop,
|
|
|
|
message_content_allowed_in_email_notifications: noop,
|
2021-11-19 13:44:44 +01:00
|
|
|
enable_spectator_access: noop,
|
2020-07-15 02:14:03 +02:00
|
|
|
signup_notifications_stream_id: noop,
|
|
|
|
emails_restricted_to_domains: noop,
|
|
|
|
video_chat_provider: compose.update_video_chat_button_display,
|
2021-04-27 21:58:19 +02:00
|
|
|
giphy_rating: giphy.update_giphy_rating,
|
2020-07-15 02:14:03 +02:00
|
|
|
waiting_period_threshold: noop,
|
2022-04-22 18:45:30 +02:00
|
|
|
want_advertise_in_communities_directory: noop,
|
2020-09-14 19:26:42 +02:00
|
|
|
wildcard_mention_policy: noop,
|
2022-08-05 12:13:21 +02:00
|
|
|
enable_read_receipts: settings_account.update_send_read_receipts_tooltip,
|
2020-07-15 02:14:03 +02:00
|
|
|
};
|
2020-10-15 14:04:36 +02:00
|
|
|
switch (event.op) {
|
|
|
|
case "update":
|
2022-01-24 08:23:22 +01:00
|
|
|
if (Object.hasOwn(realm_settings, event.property)) {
|
2020-10-15 14:04:36 +02:00
|
|
|
page_params["realm_" + event.property] = event.value;
|
|
|
|
realm_settings[event.property]();
|
|
|
|
settings_org.sync_realm_settings(event.property);
|
2018-03-20 18:30:25 +01:00
|
|
|
|
2020-10-15 14:04:36 +02:00
|
|
|
if (event.property === "name" && window.electron_bridge !== undefined) {
|
|
|
|
window.electron_bridge.send_event("realm_name", event.value);
|
|
|
|
}
|
2021-11-24 15:29:25 +01:00
|
|
|
|
|
|
|
const stream_creation_settings = [
|
|
|
|
"create_private_stream_policy",
|
|
|
|
"create_public_stream_policy",
|
|
|
|
"create_web_public_stream_policy",
|
|
|
|
];
|
|
|
|
if (stream_creation_settings.includes(event.property)) {
|
|
|
|
stream_settings_ui.update_stream_privacy_choices(event.property);
|
|
|
|
}
|
2021-11-24 19:23:52 +01:00
|
|
|
|
|
|
|
if (event.property === "enable_spectator_access") {
|
|
|
|
stream_settings_ui.update_stream_privacy_choices(
|
|
|
|
"create_web_public_stream_policy",
|
|
|
|
);
|
|
|
|
}
|
2020-10-15 14:04:36 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "update_dict":
|
|
|
|
switch (event.property) {
|
|
|
|
case "default":
|
|
|
|
for (const [key, value] of Object.entries(event.data)) {
|
|
|
|
page_params["realm_" + key] = value;
|
|
|
|
if (key === "allow_message_editing") {
|
|
|
|
message_edit.update_message_topic_editing_pencil();
|
|
|
|
}
|
2022-01-24 08:23:22 +01:00
|
|
|
if (Object.hasOwn(realm_settings, key)) {
|
2020-10-15 14:04:36 +02:00
|
|
|
settings_org.sync_realm_settings(key);
|
|
|
|
}
|
2020-10-15 13:38:38 +02:00
|
|
|
}
|
2020-10-15 14:04:36 +02:00
|
|
|
if (event.data.authentication_methods !== undefined) {
|
|
|
|
settings_org.populate_auth_methods(
|
|
|
|
event.data.authentication_methods,
|
|
|
|
);
|
2020-10-15 13:38:38 +02:00
|
|
|
}
|
2020-10-15 14:04:36 +02:00
|
|
|
break;
|
|
|
|
case "icon":
|
|
|
|
page_params.realm_icon_url = event.data.icon_url;
|
|
|
|
page_params.realm_icon_source = event.data.icon_source;
|
|
|
|
realm_icon.rerender();
|
|
|
|
{
|
|
|
|
const electron_bridge = window.electron_bridge;
|
|
|
|
if (electron_bridge !== undefined) {
|
|
|
|
electron_bridge.send_event(
|
|
|
|
"realm_icon_url",
|
|
|
|
event.data.icon_url,
|
|
|
|
);
|
|
|
|
}
|
2020-10-15 13:38:38 +02:00
|
|
|
}
|
2020-10-15 14:04:36 +02:00
|
|
|
break;
|
|
|
|
case "logo":
|
|
|
|
page_params.realm_logo_url = event.data.logo_url;
|
|
|
|
page_params.realm_logo_source = event.data.logo_source;
|
2021-07-19 13:49:40 +02:00
|
|
|
realm_logo.render();
|
2020-10-15 14:04:36 +02:00
|
|
|
break;
|
|
|
|
case "night_logo":
|
|
|
|
page_params.realm_night_logo_url = event.data.night_logo_url;
|
|
|
|
page_params.realm_night_logo_source = event.data.night_logo_source;
|
2021-07-19 13:49:40 +02:00
|
|
|
realm_logo.render();
|
2020-10-15 14:04:36 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
blueslip.error(
|
|
|
|
"Unexpected event type realm/update_dict/" + event.property,
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "deactivated":
|
|
|
|
// This handler is likely unnecessary, in that if we
|
|
|
|
// did nothing here, we'd reload and end up at the
|
|
|
|
// same place when we attempt the next `GET /events`
|
|
|
|
// and get an error. Some clients will do that even
|
|
|
|
// with this code, if they didn't have an active
|
|
|
|
// longpoll waiting at the moment the realm was
|
|
|
|
// deactivated.
|
|
|
|
window.location.href = "/accounts/deactivated/";
|
|
|
|
break;
|
2020-02-06 04:23:20 +01:00
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
if (page_params.is_admin) {
|
2020-07-15 00:34:28 +02:00
|
|
|
// Update the UI notice about the user's profile being
|
|
|
|
// incomplete, as we might have filled in the missing field(s).
|
2021-05-17 10:01:02 +02:00
|
|
|
navbar_alerts.show_profile_incomplete(navbar_alerts.check_profile_incomplete());
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-03-26 08:15:26 +01:00
|
|
|
}
|
2017-05-31 08:53:09 +02:00
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "realm_bot":
|
2020-10-15 14:08:49 +02:00
|
|
|
switch (event.op) {
|
|
|
|
case "add":
|
|
|
|
bot_data.add(event.bot);
|
2021-07-23 18:47:08 +02:00
|
|
|
settings_bots.render_bots();
|
2022-09-22 21:25:45 +02:00
|
|
|
settings_users.redraw_bots_list();
|
2020-10-15 14:08:49 +02:00
|
|
|
break;
|
|
|
|
case "remove":
|
|
|
|
bot_data.deactivate(event.bot.user_id);
|
|
|
|
event.bot.is_active = false;
|
2021-07-23 18:47:08 +02:00
|
|
|
settings_bots.render_bots();
|
2020-10-15 14:08:49 +02:00
|
|
|
settings_users.update_bot_data(event.bot.user_id);
|
|
|
|
break;
|
|
|
|
case "delete":
|
2022-03-19 09:34:42 +01:00
|
|
|
bot_data.del(event.bot.user_id);
|
|
|
|
settings_bots.render_bots();
|
|
|
|
settings_users.redraw_bots_list();
|
2020-10-15 14:08:49 +02:00
|
|
|
break;
|
|
|
|
case "update":
|
|
|
|
bot_data.update(event.bot.user_id, event.bot);
|
2021-07-23 18:47:08 +02:00
|
|
|
settings_bots.render_bots();
|
2020-10-15 14:08:49 +02:00
|
|
|
settings_users.update_bot_data(event.bot.user_id);
|
|
|
|
break;
|
2020-10-15 14:11:54 +02:00
|
|
|
default:
|
|
|
|
blueslip.error("Unexpected event type realm_bot/" + event.op);
|
|
|
|
break;
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
2020-05-28 22:29:52 +02:00
|
|
|
break;
|
2020-07-15 02:14:03 +02:00
|
|
|
case "realm_emoji":
|
2020-07-25 14:27:39 +02:00
|
|
|
// The authoritative data source is here.
|
2020-07-15 02:14:03 +02:00
|
|
|
emoji.update_emojis(event.realm_emoji);
|
2020-07-25 14:27:39 +02:00
|
|
|
|
|
|
|
// And then let other widgets know.
|
2020-07-24 00:42:44 +02:00
|
|
|
settings_emoji.populate_emoji();
|
2020-07-25 16:11:28 +02:00
|
|
|
emoji_picker.rebuild_catalog();
|
2020-07-15 02:14:03 +02:00
|
|
|
composebox_typeahead.update_emoji_data();
|
|
|
|
break;
|
|
|
|
|
2021-03-30 12:51:54 +02:00
|
|
|
case "realm_linkifiers":
|
|
|
|
page_params.realm_linkifiers = event.realm_linkifiers;
|
2021-05-19 06:18:23 +02:00
|
|
|
linkifiers.update_linkifier_rules(page_params.realm_linkifiers);
|
2021-03-30 12:51:54 +02:00
|
|
|
settings_linkifiers.populate_linkifiers(page_params.realm_linkifiers);
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
|
|
|
|
2021-04-13 08:43:03 +02:00
|
|
|
case "realm_playgrounds":
|
|
|
|
page_params.realm_playgrounds = event.realm_playgrounds;
|
|
|
|
realm_playground.update_playgrounds(page_params.realm_playgrounds);
|
2021-04-16 04:04:18 +02:00
|
|
|
settings_playgrounds.populate_playgrounds(page_params.realm_playgrounds);
|
2021-04-13 08:43:03 +02:00
|
|
|
break;
|
|
|
|
|
2020-10-15 14:42:15 +02:00
|
|
|
case "realm_domains":
|
|
|
|
{
|
|
|
|
let i;
|
|
|
|
switch (event.op) {
|
|
|
|
case "add":
|
|
|
|
page_params.realm_domains.push(event.realm_domain);
|
2021-07-20 14:51:48 +02:00
|
|
|
settings_org.populate_realm_domains_label(page_params.realm_domains);
|
|
|
|
settings_realm_domains.populate_realm_domains_table(
|
|
|
|
page_params.realm_domains,
|
|
|
|
);
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
2020-10-15 14:42:15 +02:00
|
|
|
case "change":
|
|
|
|
for (i = 0; i < page_params.realm_domains.length; i += 1) {
|
|
|
|
if (page_params.realm_domains[i].domain === event.realm_domain.domain) {
|
|
|
|
page_params.realm_domains[i].allow_subdomains =
|
|
|
|
event.realm_domain.allow_subdomains;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-07-20 14:51:48 +02:00
|
|
|
settings_org.populate_realm_domains_label(page_params.realm_domains);
|
|
|
|
settings_realm_domains.populate_realm_domains_table(
|
|
|
|
page_params.realm_domains,
|
|
|
|
);
|
2020-10-15 14:42:15 +02:00
|
|
|
break;
|
|
|
|
case "remove":
|
|
|
|
for (i = 0; i < page_params.realm_domains.length; i += 1) {
|
|
|
|
if (page_params.realm_domains[i].domain === event.domain) {
|
|
|
|
page_params.realm_domains.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-07-20 14:51:48 +02:00
|
|
|
settings_org.populate_realm_domains_label(page_params.realm_domains);
|
|
|
|
settings_realm_domains.populate_realm_domains_table(
|
|
|
|
page_params.realm_domains,
|
|
|
|
);
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
2020-10-15 16:34:13 +02:00
|
|
|
default:
|
|
|
|
blueslip.error("Unexpected event type realm_domains/" + event.op);
|
|
|
|
break;
|
2017-05-31 08:53:09 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
2017-05-31 08:53:09 +02:00
|
|
|
|
2021-08-30 16:26:38 +02:00
|
|
|
case "realm_user_settings_defaults": {
|
|
|
|
realm_user_settings_defaults[event.property] = event.value;
|
2021-10-02 13:34:52 +02:00
|
|
|
settings_realm_user_settings_defaults.update_page(event.property);
|
2021-08-30 16:26:38 +02:00
|
|
|
|
2021-10-02 13:34:52 +02:00
|
|
|
if (event.property === "notification_sound") {
|
2021-09-16 12:47:12 +02:00
|
|
|
notifications.update_notification_sound_source(
|
|
|
|
$("#realm-default-notification-sound-audio"),
|
|
|
|
realm_user_settings_defaults,
|
|
|
|
);
|
2021-08-30 16:26:38 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "realm_user":
|
2020-10-15 16:38:10 +02:00
|
|
|
switch (event.op) {
|
2021-03-23 22:17:08 +01:00
|
|
|
case "add":
|
|
|
|
people.add_active_user(event.person);
|
|
|
|
break;
|
|
|
|
case "remove":
|
|
|
|
people.deactivate(event.person);
|
|
|
|
stream_events.remove_deactivated_user_from_all_streams(event.person.user_id);
|
2022-02-25 12:06:40 +01:00
|
|
|
settings_users.update_view_on_deactivate(event.person.user_id);
|
2022-02-25 17:33:58 +01:00
|
|
|
buddy_list.maybe_remove_key({key: event.person.user_id});
|
2021-03-23 22:17:08 +01:00
|
|
|
break;
|
|
|
|
case "update":
|
|
|
|
user_events.update_person(event.person);
|
|
|
|
break;
|
2020-10-16 03:55:11 +02:00
|
|
|
default:
|
|
|
|
blueslip.error("Unexpected event type realm_user/" + event.op);
|
|
|
|
break;
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-05-31 08:53:09 +02:00
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "stream":
|
2020-10-16 04:08:33 +02:00
|
|
|
switch (event.op) {
|
|
|
|
case "update":
|
|
|
|
stream_events.update_property(event.stream_id, event.property, event.value, {
|
|
|
|
rendered_description: event.rendered_description,
|
|
|
|
history_public_to_subscribers: event.history_public_to_subscribers,
|
2020-11-10 15:57:14 +01:00
|
|
|
is_web_public: event.is_web_public,
|
2020-10-16 04:08:33 +02:00
|
|
|
});
|
2020-07-15 02:14:03 +02:00
|
|
|
settings_streams.update_default_streams_table();
|
2022-08-15 21:32:10 +02:00
|
|
|
stream_list.update_subscribe_to_more_streams_link();
|
2020-10-16 04:08:33 +02:00
|
|
|
break;
|
|
|
|
case "create":
|
|
|
|
stream_data.create_streams(event.streams);
|
|
|
|
|
|
|
|
for (const stream of event.streams) {
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(stream.stream_id);
|
2020-10-16 04:08:33 +02:00
|
|
|
if (overlays.streams_open()) {
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.add_sub_to_table(sub);
|
2020-10-16 04:08:33 +02:00
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
2022-08-15 21:32:10 +02:00
|
|
|
stream_list.update_subscribe_to_more_streams_link();
|
2020-10-16 04:08:33 +02:00
|
|
|
break;
|
|
|
|
case "delete":
|
|
|
|
for (const stream of event.streams) {
|
2021-04-15 17:02:54 +02:00
|
|
|
const was_subscribed = sub_store.get(stream.stream_id).subscribed;
|
2020-10-16 04:08:33 +02:00
|
|
|
const is_narrowed_to_stream = narrow_state.is_for_stream_id(
|
|
|
|
stream.stream_id,
|
|
|
|
);
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.remove_stream(stream.stream_id);
|
2020-10-16 04:08:33 +02:00
|
|
|
stream_data.delete_sub(stream.stream_id);
|
|
|
|
if (was_subscribed) {
|
|
|
|
stream_list.remove_sidebar_row(stream.stream_id);
|
|
|
|
}
|
|
|
|
settings_streams.update_default_streams_table();
|
|
|
|
stream_data.remove_default_stream(stream.stream_id);
|
|
|
|
if (is_narrowed_to_stream) {
|
2021-03-30 02:21:21 +02:00
|
|
|
message_lists.current.update_trailing_bookend();
|
2020-10-16 04:08:33 +02:00
|
|
|
}
|
|
|
|
if (page_params.realm_notifications_stream_id === stream.stream_id) {
|
|
|
|
page_params.realm_notifications_stream_id = -1;
|
|
|
|
settings_org.sync_realm_settings("notifications_stream_id");
|
|
|
|
}
|
|
|
|
if (page_params.realm_signup_notifications_stream_id === stream.stream_id) {
|
|
|
|
page_params.realm_signup_notifications_stream_id = -1;
|
|
|
|
settings_org.sync_realm_settings("signup_notifications_stream_id");
|
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
2022-08-15 21:32:10 +02:00
|
|
|
stream_list.update_subscribe_to_more_streams_link();
|
2020-10-16 04:08:33 +02:00
|
|
|
break;
|
2020-10-16 04:13:38 +02:00
|
|
|
default:
|
|
|
|
blueslip.error("Unexpected event type stream/" + event.op);
|
|
|
|
break;
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
2017-05-31 08:53:09 +02:00
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "submessage": {
|
2020-07-15 00:34:28 +02:00
|
|
|
// The fields in the event don't quite exactly
|
|
|
|
// match the layout of a submessage, since there's
|
|
|
|
// an event id. We also want to be explicit here.
|
2020-07-15 02:14:03 +02:00
|
|
|
const submsg = {
|
|
|
|
id: event.submessage_id,
|
|
|
|
sender_id: event.sender_id,
|
|
|
|
msg_type: event.msg_type,
|
|
|
|
message_id: event.message_id,
|
|
|
|
content: event.content,
|
|
|
|
};
|
|
|
|
submessage.handle_event(submsg);
|
|
|
|
break;
|
|
|
|
}
|
2018-02-12 15:12:40 +01:00
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "subscription":
|
2020-06-20 21:06:40 +02:00
|
|
|
switch (event.op) {
|
|
|
|
case "add":
|
|
|
|
for (const rec of event.subscriptions) {
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(rec.stream_id);
|
2020-06-20 21:06:40 +02:00
|
|
|
if (sub) {
|
|
|
|
stream_data.update_stream_email_address(sub, rec.email_address);
|
|
|
|
stream_events.mark_subscribed(sub, rec.subscribers, rec.color);
|
|
|
|
} else {
|
|
|
|
blueslip.error(
|
|
|
|
"Subscribing to unknown stream with ID " + rec.stream_id,
|
|
|
|
);
|
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
2020-06-20 21:06:40 +02:00
|
|
|
break;
|
|
|
|
case "peer_add": {
|
2021-04-15 17:02:54 +02:00
|
|
|
const stream_ids = sub_store.validate_stream_ids(event.stream_ids);
|
2020-06-20 21:06:40 +02:00
|
|
|
const user_ids = people.validate_user_ids(event.user_ids);
|
2020-07-15 02:14:03 +02:00
|
|
|
|
2020-06-20 21:06:40 +02:00
|
|
|
peer_data.bulk_add_subscribers({stream_ids, user_ids});
|
2020-07-15 02:14:03 +02:00
|
|
|
|
2020-06-20 21:06:40 +02:00
|
|
|
for (const stream_id of stream_ids) {
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(stream_id);
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.update_subscribers_ui(sub);
|
2020-06-20 21:06:40 +02:00
|
|
|
}
|
2021-01-27 15:54:06 +01:00
|
|
|
|
2020-06-20 21:06:40 +02:00
|
|
|
compose_fade.update_faded_users();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "peer_remove": {
|
2021-04-15 17:02:54 +02:00
|
|
|
const stream_ids = sub_store.validate_stream_ids(event.stream_ids);
|
2020-06-20 21:06:40 +02:00
|
|
|
const user_ids = people.validate_user_ids(event.user_ids);
|
2020-07-15 02:14:03 +02:00
|
|
|
|
2020-06-20 21:06:40 +02:00
|
|
|
peer_data.bulk_remove_subscribers({stream_ids, user_ids});
|
2020-07-15 02:14:03 +02:00
|
|
|
|
2020-06-20 21:06:40 +02:00
|
|
|
for (const stream_id of stream_ids) {
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(stream_id);
|
2021-07-09 15:51:31 +02:00
|
|
|
stream_settings_ui.update_subscribers_ui(sub);
|
2020-06-20 21:06:40 +02:00
|
|
|
}
|
2021-01-27 15:54:06 +01:00
|
|
|
|
2020-06-20 21:06:40 +02:00
|
|
|
compose_fade.update_faded_users();
|
|
|
|
break;
|
2020-06-12 16:54:01 +02:00
|
|
|
}
|
2020-06-20 21:06:40 +02:00
|
|
|
case "remove":
|
|
|
|
for (const rec of event.subscriptions) {
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub = sub_store.get(rec.stream_id);
|
2020-06-20 21:06:40 +02:00
|
|
|
stream_events.mark_unsubscribed(sub);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "update":
|
|
|
|
stream_events.update_property(event.stream_id, event.property, event.value);
|
|
|
|
break;
|
2020-06-20 21:14:09 +02:00
|
|
|
default:
|
|
|
|
blueslip.error("Unexpected event type subscription/" + event.op);
|
|
|
|
break;
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
|
|
|
case "typing":
|
|
|
|
if (event.sender.user_id === page_params.user_id) {
|
2020-07-15 00:34:28 +02:00
|
|
|
// typing notifications are sent to the user who is typing
|
|
|
|
// as well as recipients; we ignore such self-generated events.
|
2020-07-15 02:14:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-10-16 04:19:27 +02:00
|
|
|
switch (event.op) {
|
|
|
|
case "start":
|
|
|
|
typing_events.display_notification(event);
|
|
|
|
break;
|
|
|
|
case "stop":
|
|
|
|
typing_events.hide_notification(event);
|
|
|
|
break;
|
2020-10-16 04:28:43 +02:00
|
|
|
default:
|
|
|
|
blueslip.error("Unexpected event type typing/" + event.op);
|
|
|
|
break;
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-07-27 19:02:05 +02:00
|
|
|
case "user_settings": {
|
|
|
|
if (settings_config.all_notification_settings.includes(event.property)) {
|
|
|
|
notifications.handle_global_notification_updates(event.property, event.value);
|
2021-09-20 15:56:32 +02:00
|
|
|
settings_notifications.update_page(settings_notifications.user_settings_panel);
|
2021-07-27 19:02:05 +02:00
|
|
|
// TODO: This should also do a refresh of the stream_edit UI
|
|
|
|
// if it's currently displayed, possibly reusing some code
|
|
|
|
// from stream_events.js
|
|
|
|
// (E.g. update_stream_push_notifications).
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
const user_display_settings = [
|
|
|
|
"color_scheme",
|
|
|
|
"default_language",
|
2021-03-10 13:56:10 +01:00
|
|
|
"default_view",
|
2020-07-15 02:14:03 +02:00
|
|
|
"demote_inactive_streams",
|
|
|
|
"dense_mode",
|
|
|
|
"emojiset",
|
2021-10-25 19:17:19 +02:00
|
|
|
"escape_navigates_to_default_view",
|
2020-07-15 02:14:03 +02:00
|
|
|
"fluid_layout_width",
|
|
|
|
"high_contrast_mode",
|
|
|
|
"left_side_userlist",
|
|
|
|
"timezone",
|
|
|
|
"twenty_four_hour_time",
|
|
|
|
"translate_emoticons",
|
2022-04-08 16:04:22 +02:00
|
|
|
"display_emoji_reaction_users",
|
2022-08-12 22:41:06 +02:00
|
|
|
"user_list_style",
|
2020-07-15 02:14:03 +02:00
|
|
|
"starred_message_counts",
|
2021-10-03 08:36:36 +02:00
|
|
|
"send_stream_typing_notifications",
|
|
|
|
"send_private_typing_notifications",
|
2021-10-03 08:53:35 +02:00
|
|
|
"send_read_receipts",
|
2020-07-15 02:14:03 +02:00
|
|
|
];
|
2021-08-18 11:47:07 +02:00
|
|
|
|
2021-07-27 19:02:05 +02:00
|
|
|
if (user_display_settings.includes(event.property)) {
|
2021-07-28 16:00:58 +02:00
|
|
|
user_settings[event.property] = event.value;
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "default_language") {
|
2020-07-15 00:34:28 +02:00
|
|
|
// We additionally need to set the language name.
|
2021-04-24 01:32:32 +02:00
|
|
|
//
|
|
|
|
// Note that this does not change translations at all;
|
|
|
|
// a reload is fundamentally required because we
|
|
|
|
// cannot rerender with the new language the strings
|
|
|
|
// present in the backend/Jinja2 templates.
|
2021-06-15 17:23:38 +02:00
|
|
|
settings_display.set_default_language_name(event.language_name);
|
2017-05-31 08:53:09 +02:00
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "twenty_four_hour_time") {
|
2020-07-15 00:34:28 +02:00
|
|
|
// Rerender the whole message list UI
|
2022-08-17 07:10:19 +02:00
|
|
|
for (const msg_list of message_lists.all_rendered_message_lists()) {
|
|
|
|
msg_list.rerender();
|
2017-11-30 02:31:21 +01:00
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "high_contrast_mode") {
|
2020-07-15 02:14:03 +02:00
|
|
|
$("body").toggleClass("high-contrast");
|
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "demote_inactive_streams") {
|
2020-07-15 02:14:03 +02:00
|
|
|
stream_list.update_streams_sidebar();
|
|
|
|
stream_data.set_filter_out_inactives();
|
|
|
|
}
|
2022-08-12 22:41:06 +02:00
|
|
|
if (event.property === "user_list_style") {
|
|
|
|
settings_display.report_user_list_style_change(
|
|
|
|
settings_display.user_settings_panel,
|
|
|
|
);
|
|
|
|
activity.build_user_sidebar();
|
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "dense_mode") {
|
2020-07-15 02:14:03 +02:00
|
|
|
$("body").toggleClass("less_dense_mode");
|
|
|
|
$("body").toggleClass("more_dense_mode");
|
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "color_scheme") {
|
2020-07-15 02:14:03 +02:00
|
|
|
$("body").fadeOut(300);
|
|
|
|
setTimeout(() => {
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.value === settings_config.color_scheme_values.night.code) {
|
2021-11-26 08:36:54 +01:00
|
|
|
dark_theme.enable();
|
2021-07-19 13:49:40 +02:00
|
|
|
realm_logo.render();
|
2021-07-27 19:02:05 +02:00
|
|
|
} else if (event.value === settings_config.color_scheme_values.day.code) {
|
2021-11-26 08:36:54 +01:00
|
|
|
dark_theme.disable();
|
2021-07-19 13:49:40 +02:00
|
|
|
realm_logo.render();
|
2020-07-15 02:14:03 +02:00
|
|
|
} else {
|
2021-11-26 08:36:54 +01:00
|
|
|
dark_theme.default_preference_checker();
|
2021-07-19 13:49:40 +02:00
|
|
|
realm_logo.render();
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
|
|
|
$("body").fadeIn(300);
|
|
|
|
}, 300);
|
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "starred_message_counts") {
|
2020-07-15 02:14:03 +02:00
|
|
|
starred_messages.rerender_ui();
|
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "fluid_layout_width") {
|
2020-07-15 02:14:03 +02:00
|
|
|
scroll_bar.set_layout_width();
|
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "left_side_userlist") {
|
2020-07-15 00:34:28 +02:00
|
|
|
// TODO: Make this change the view immediately rather
|
|
|
|
// than requiring a reload or page resize.
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "default_language") {
|
2020-07-15 00:34:28 +02:00
|
|
|
// TODO: Make this change the view immediately rather than
|
|
|
|
// requiring a reload. This is likely fairly difficult,
|
|
|
|
// because various i18n strings are rendered by the
|
|
|
|
// server; we may want to instead just trigger a page
|
|
|
|
// reload.
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "emojiset") {
|
2021-09-20 13:38:38 +02:00
|
|
|
settings_display.report_emojiset_change(settings_display.user_settings_panel);
|
2018-01-02 21:11:23 +01:00
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
// Rerender the whole message list UI
|
2022-08-17 07:10:19 +02:00
|
|
|
for (const msg_list of message_lists.all_rendered_message_lists()) {
|
|
|
|
msg_list.rerender();
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
2021-06-27 19:04:17 +02:00
|
|
|
// Rerender buddy list status emoji
|
|
|
|
activity.build_user_sidebar();
|
2018-01-02 13:02:13 +01:00
|
|
|
}
|
2022-04-08 16:04:22 +02:00
|
|
|
|
|
|
|
if (event.property === "display_emoji_reaction_users") {
|
|
|
|
message_live_update.rerender_messages_view();
|
|
|
|
}
|
2021-11-05 19:09:34 +01:00
|
|
|
if (event.property === "escape_navigates_to_default_view") {
|
|
|
|
$("#go-to-default-view-hotkey-help").toggleClass("notdisplayed", !event.value);
|
|
|
|
}
|
2021-07-27 19:02:05 +02:00
|
|
|
if (event.property === "enter_sends") {
|
2021-07-28 16:00:58 +02:00
|
|
|
user_settings.enter_sends = event.value;
|
2021-11-25 10:00:04 +01:00
|
|
|
$(`.enter_sends_${!user_settings.enter_sends}`).hide();
|
|
|
|
$(`.enter_sends_${user_settings.enter_sends}`).show();
|
2021-07-26 21:55:14 +02:00
|
|
|
break;
|
|
|
|
}
|
2021-09-17 13:14:04 +02:00
|
|
|
if (event.property === "presence_enabled") {
|
|
|
|
user_settings.presence_enabled = event.value;
|
|
|
|
$("#user_presence_enabled").prop("checked", user_settings.presence_enabled);
|
2021-12-04 01:20:20 +01:00
|
|
|
activity.redraw_user(page_params.user_id);
|
2022-09-20 20:49:22 +02:00
|
|
|
|
|
|
|
// Temporary transition code to update the set of
|
|
|
|
// user_status.away_user_ids so that the user info
|
|
|
|
// popover will update when the user updates their
|
|
|
|
// presence_enabled privacy setting.
|
|
|
|
if (event.value) {
|
|
|
|
user_status.revoke_away(page_params.user_id);
|
|
|
|
} else {
|
|
|
|
user_status.set_away(page_params.user_id);
|
|
|
|
}
|
2021-09-17 13:14:04 +02:00
|
|
|
break;
|
|
|
|
}
|
2021-11-05 19:09:34 +01:00
|
|
|
settings_display.update_page(event.property);
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
2017-05-31 08:53:09 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "update_message_flags": {
|
2020-08-24 21:44:29 +02:00
|
|
|
const new_value = event.op === "add";
|
2020-07-15 02:14:03 +02:00
|
|
|
switch (event.flag) {
|
|
|
|
case "starred":
|
|
|
|
for (const message_id of event.messages) {
|
|
|
|
message_flags.update_starred_flag(message_id, new_value);
|
|
|
|
}
|
|
|
|
|
2020-08-24 21:44:29 +02:00
|
|
|
if (event.op === "add") {
|
2020-07-15 02:14:03 +02:00
|
|
|
starred_messages.add(event.messages);
|
|
|
|
} else {
|
|
|
|
starred_messages.remove(event.messages);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "read":
|
2021-06-09 13:31:39 +02:00
|
|
|
if (event.op === "add") {
|
|
|
|
unread_ops.process_read_messages_event(event.messages);
|
|
|
|
} else {
|
|
|
|
unread_ops.process_unread_messages_event({
|
|
|
|
message_ids: event.messages,
|
|
|
|
message_details: event.message_details,
|
|
|
|
});
|
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
2018-08-17 03:46:32 +02:00
|
|
|
}
|
2017-05-31 08:53:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "user_group":
|
2020-10-16 04:32:34 +02:00
|
|
|
switch (event.op) {
|
|
|
|
case "add":
|
|
|
|
user_groups.add(event.group);
|
|
|
|
break;
|
2021-03-26 18:25:36 +01:00
|
|
|
case "remove":
|
|
|
|
user_groups.remove(user_groups.get_user_group_from_id(event.group_id));
|
|
|
|
break;
|
2020-10-16 04:32:34 +02:00
|
|
|
case "add_members":
|
|
|
|
user_groups.add_members(event.group_id, event.user_ids);
|
|
|
|
break;
|
|
|
|
case "remove_members":
|
|
|
|
user_groups.remove_members(event.group_id, event.user_ids);
|
|
|
|
break;
|
2022-05-02 16:41:51 +02:00
|
|
|
case "add_subgroups":
|
2022-05-16 17:02:44 +02:00
|
|
|
user_groups.add_subgroups(event.group_id, event.direct_subgroup_ids);
|
2022-05-02 16:41:51 +02:00
|
|
|
break;
|
|
|
|
case "remove_subgroups":
|
2022-05-16 17:02:44 +02:00
|
|
|
user_groups.remove_subgroups(event.group_id, event.direct_subgroup_ids);
|
2022-05-02 16:41:51 +02:00
|
|
|
break;
|
2020-10-16 04:32:34 +02:00
|
|
|
case "update":
|
|
|
|
user_groups.update(event);
|
|
|
|
break;
|
2020-10-16 04:28:43 +02:00
|
|
|
default:
|
|
|
|
blueslip.error("Unexpected event type user_group/" + event.op);
|
|
|
|
break;
|
2019-01-23 19:25:22 +01:00
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
settings_user_groups.reload();
|
|
|
|
break;
|
2019-01-23 19:25:22 +01:00
|
|
|
|
2020-07-15 02:14:03 +02:00
|
|
|
case "user_status":
|
|
|
|
if (event.away !== undefined) {
|
|
|
|
if (event.away) {
|
|
|
|
activity.on_set_away(event.user_id);
|
|
|
|
} else {
|
|
|
|
activity.on_revoke_away(event.user_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.status_text !== undefined) {
|
|
|
|
user_status.set_status_text({
|
|
|
|
user_id: event.user_id,
|
|
|
|
status_text: event.status_text,
|
|
|
|
});
|
|
|
|
activity.redraw_user(event.user_id);
|
2021-08-02 16:55:27 +02:00
|
|
|
|
|
|
|
// Update the status text in compose box placeholder when opened to self.
|
|
|
|
if (compose_pm_pill.get_user_ids().includes(event.user_id)) {
|
|
|
|
compose_actions.update_placeholder_text();
|
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
}
|
2021-06-27 19:04:17 +02:00
|
|
|
|
|
|
|
if (event.emoji_name !== undefined) {
|
|
|
|
user_status.set_status_emoji(event);
|
|
|
|
activity.redraw_user(event.user_id);
|
2022-02-05 19:10:59 +01:00
|
|
|
pm_list.update_private_messages();
|
2022-02-05 19:13:05 +01:00
|
|
|
message_live_update.update_user_status_emoji(
|
|
|
|
event.user_id,
|
|
|
|
user_status.get_status_emoji(event.user_id),
|
|
|
|
);
|
2021-06-27 19:04:17 +02:00
|
|
|
}
|
2020-07-15 02:14:03 +02:00
|
|
|
break;
|
|
|
|
case "realm_export":
|
|
|
|
settings_exports.populate_exports_table(event.exports);
|
|
|
|
break;
|
2017-05-31 08:53:09 +02:00
|
|
|
}
|
2021-02-10 17:02:31 +01:00
|
|
|
}
|