js: Convert static/js/echo.js to ES6 module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-10 07:53:37 -08:00 committed by Tim Abbott
parent f66441adb2
commit 1a45d53f3a
10 changed files with 33 additions and 40 deletions

View File

@ -166,7 +166,6 @@
"current_msg_list": true,
"drafts": false,
"dropdown_list_widget": false,
"echo": false,
"emoji_picker": false,
"favicon": false,
"flatpickr": false,

View File

@ -33,12 +33,6 @@ set_global("reload_state", {
// we also directly write to pointer
set_global("pointer", {});
set_global("echo", {
process_from_server(messages) {
return messages;
},
update_realm_filter_rules: noop,
});
set_global("ui_report", {
hide_error() {
return false;

View File

@ -84,7 +84,6 @@ ui.get_scroll_element = (element) => element;
zrequire("alert_words");
zrequire("hash_util");
zrequire("echo");
zrequire("colorspace");
zrequire("stream_color");
zrequire("stream_edit");

View File

@ -57,7 +57,6 @@ import "../reload";
import "../compose_fade";
import "../markdown";
import "../local_message";
import "../echo";
import "../sent_messages";
import "../compose_state";
import "../compose_actions";

View File

@ -9,6 +9,7 @@ const render_compose_invite_users = require("../templates/compose_invite_users.h
const render_compose_not_subscribed = require("../templates/compose_not_subscribed.hbs");
const render_compose_private_stream_alert = require("../templates/compose_private_stream_alert.hbs");
const echo = require("./echo");
const peer_data = require("./peer_data");
const people = require("./people");
const rendered_markdown = require("./rendered_markdown");

View File

@ -1,7 +1,6 @@
"use strict";
import * as people from "./people";
import * as util from "./util";
const people = require("./people");
const util = require("./util");
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
const waiting_for_id = new Map();
@ -36,7 +35,7 @@ function resend_message(message, row) {
}
function on_error(response) {
exports.message_send_error(message.id, response);
message_send_error(message.id, response);
setTimeout(() => {
retry_spinner.toggleClass("rotating", false);
}, 300);
@ -47,7 +46,7 @@ function resend_message(message, row) {
transmit.send_message(message, on_success, on_error);
}
exports.build_display_recipient = function (message) {
export function build_display_recipient(message) {
if (message.type === "stream") {
return message.stream;
}
@ -108,9 +107,9 @@ exports.build_display_recipient = function (message) {
});
}
return display_recipient;
};
}
exports.insert_local_message = function (message_request, local_id_float) {
export function insert_local_message(message_request, local_id_float) {
// Shallow clone of message request object that is turned into something suitable
// for zulip.js:add_message
// Keep this in sync with changes to compose.create_message_object
@ -138,16 +137,16 @@ exports.insert_local_message = function (message_request, local_id_float) {
waiting_for_id.set(message.local_id, message);
waiting_for_ack.set(message.local_id, message);
message.display_recipient = exports.build_display_recipient(message);
message.display_recipient = build_display_recipient(message);
local_message.insert_message(message);
return message;
};
}
exports.is_slash_command = function (content) {
export function is_slash_command(content) {
return !content.startsWith("/me") && content.startsWith("/");
};
}
exports.try_deliver_locally = function (message_request) {
export function try_deliver_locally(message_request) {
if (markdown.contains_backend_only_syntax(message_request.content)) {
return undefined;
}
@ -156,7 +155,7 @@ exports.try_deliver_locally = function (message_request) {
return undefined;
}
if (exports.is_slash_command(message_request.content)) {
if (is_slash_command(message_request.content)) {
return undefined;
}
@ -180,11 +179,11 @@ exports.try_deliver_locally = function (message_request) {
return undefined;
}
const message = exports.insert_local_message(message_request, local_id_float);
const message = insert_local_message(message_request, local_id_float);
return message;
};
}
exports.edit_locally = function (message, request) {
export function edit_locally(message, request) {
// Responsible for doing the rendering work of locally editing the
// content ofa message. This is used in several code paths:
// * Editing a message where a message was locally echoed but
@ -260,9 +259,9 @@ exports.edit_locally = function (message, request) {
}
stream_list.update_streams_sidebar();
pm_list.update_private_messages();
};
}
exports.reify_message_id = function (local_id, server_id) {
export function reify_message_id(local_id, server_id) {
const message = waiting_for_id.get(local_id);
waiting_for_id.delete(local_id);
@ -281,9 +280,9 @@ exports.reify_message_id = function (local_id, server_id) {
message_store.reify_message_id(opts);
notifications.reify_message_id(opts);
recent_topics.reify_message_id_if_available(opts);
};
}
exports.process_from_server = function (messages) {
export function process_from_server(messages) {
const msgs_to_rerender = [];
const non_echo_messages = [];
@ -300,7 +299,7 @@ exports.process_from_server = function (messages) {
continue;
}
exports.reify_message_id(local_id, message.id);
reify_message_id(local_id, message.id);
if (message_store.get(message.id).failed_request) {
failed_message_success(message.id);
@ -346,18 +345,18 @@ exports.process_from_server = function (messages) {
}
return non_echo_messages;
};
}
exports._patch_waiting_for_ack = function (data) {
export function _patch_waiting_for_ack(data) {
// Only for testing
waiting_for_ack = data;
};
}
exports.message_send_error = function (message_id, error_response) {
export function message_send_error(message_id, error_response) {
// Error sending message, show inline
message_store.get(message_id).failed_request = true;
ui.show_message_failed(message_id, error_response);
};
}
function abort_message(message) {
// Remove in all lists in which it exists
@ -366,7 +365,7 @@ function abort_message(message) {
}
}
exports.initialize = function () {
export function initialize() {
function on_failed_action(selector, callback) {
$("#main_div").on("click", selector, function (e) {
e.stopPropagation();
@ -389,6 +388,4 @@ exports.initialize = function () {
on_failed_action(".remove-failed-message", abort_message);
on_failed_action(".refresh-failed-message", resend_message);
};
window.echo = exports;
}

View File

@ -38,7 +38,6 @@ declare let copy_and_paste: any;
declare let csrf_token: any;
declare let current_msg_list: any;
declare let drafts: any;
declare let echo: any;
declare let emoji: any;
declare let emoji_picker: any;
declare let favicon: any;

View File

@ -5,6 +5,8 @@ const ClipboardJS = require("clipboard");
const render_message_edit_form = require("../templates/message_edit_form.hbs");
const render_topic_edit_form = require("../templates/topic_edit_form.hbs");
const echo = require("./echo");
const currently_editing_messages = new Map();
let currently_deleting_messages = [];
let currently_topic_editing_messages = [];

View File

@ -1,6 +1,8 @@
"use strict";
const _ = require("lodash");
const echo = require("./echo");
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/events-system.html
let waiting_on_homeview_load = true;

View File

@ -8,6 +8,7 @@ const emoji = require("../shared/js/emoji");
const fenced_code = require("../shared/js/fenced_code");
const render_edit_content_button = require("../templates/edit_content_button.hbs");
const echo = require("./echo");
const emojisets = require("./emojisets");
const markdown_config = require("./markdown_config");
const people = require("./people");