mirror of https://github.com/zulip/zulip.git
refactor: Move insert_message to echo.
This change does not impact the overall complexity of our dependency graph (at least in terms of the number of edges that we would need to remove to get a tree), but it does clarify the picture a bit.
This commit is contained in:
parent
1585c2a12c
commit
e72f208fde
|
@ -48,7 +48,6 @@ const _document = {
|
||||||
set_global("document", _document);
|
set_global("document", _document);
|
||||||
const channel = mock_esm("../../static/js/channel");
|
const channel = mock_esm("../../static/js/channel");
|
||||||
const loading = mock_esm("../../static/js/loading");
|
const loading = mock_esm("../../static/js/loading");
|
||||||
const local_message = mock_esm("../../static/js/local_message");
|
|
||||||
const markdown = mock_esm("../../static/js/markdown");
|
const markdown = mock_esm("../../static/js/markdown");
|
||||||
const reminder = mock_esm("../../static/js/reminder", {
|
const reminder = mock_esm("../../static/js/reminder", {
|
||||||
is_deferred_delivery: noop,
|
is_deferred_delivery: noop,
|
||||||
|
@ -724,9 +723,9 @@ test_ui("send_message", (override) => {
|
||||||
override(compose_state, "private_message_recipient", () => "alice@example.com");
|
override(compose_state, "private_message_recipient", () => "alice@example.com");
|
||||||
|
|
||||||
const server_message_id = 127;
|
const server_message_id = 127;
|
||||||
local_message.insert_message = (message) => {
|
override(echo, "insert_message", (message) => {
|
||||||
assert.equal(message.timestamp, fake_now);
|
assert.equal(message.timestamp, fake_now);
|
||||||
};
|
});
|
||||||
|
|
||||||
markdown.apply_markdown = () => {};
|
markdown.apply_markdown = () => {};
|
||||||
markdown.add_topic_links = () => {};
|
markdown.add_topic_links = () => {};
|
||||||
|
|
|
@ -8,7 +8,6 @@ const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
const {page_params} = require("../zjsunit/zpage_params");
|
const {page_params} = require("../zjsunit/zpage_params");
|
||||||
|
|
||||||
const local_message = mock_esm("../../static/js/local_message");
|
|
||||||
const markdown = mock_esm("../../static/js/markdown");
|
const markdown = mock_esm("../../static/js/markdown");
|
||||||
|
|
||||||
let disparities = [];
|
let disparities = [];
|
||||||
|
@ -188,7 +187,7 @@ run_test("insert_local_message streams", (override) => {
|
||||||
add_topic_links_called = true;
|
add_topic_links_called = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
override(local_message, "insert_message", (message) => {
|
override(echo, "insert_message", (message) => {
|
||||||
assert.equal(message.display_recipient, "general");
|
assert.equal(message.display_recipient, "general");
|
||||||
assert.equal(message.timestamp, fake_now);
|
assert.equal(message.timestamp, fake_now);
|
||||||
assert.equal(message.sender_email, "iago@zulip.com");
|
assert.equal(message.sender_email, "iago@zulip.com");
|
||||||
|
@ -232,7 +231,7 @@ run_test("insert_local_message PM", (override) => {
|
||||||
let apply_markdown_called = false;
|
let apply_markdown_called = false;
|
||||||
let insert_message_called = false;
|
let insert_message_called = false;
|
||||||
|
|
||||||
override(local_message, "insert_message", (message) => {
|
override(echo, "insert_message", (message) => {
|
||||||
assert.equal(message.display_recipient.length, 3);
|
assert.equal(message.display_recipient.length, 3);
|
||||||
insert_message_called = true;
|
insert_message_called = true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,7 @@ import * as blueslip from "./blueslip";
|
||||||
import * as compose from "./compose";
|
import * as compose from "./compose";
|
||||||
import * as local_message from "./local_message";
|
import * as local_message from "./local_message";
|
||||||
import * as markdown from "./markdown";
|
import * as markdown from "./markdown";
|
||||||
|
import * as message_events from "./message_events";
|
||||||
import * as message_list from "./message_list";
|
import * as message_list from "./message_list";
|
||||||
import * as message_store from "./message_store";
|
import * as message_store from "./message_store";
|
||||||
import * as narrow_state from "./narrow_state";
|
import * as narrow_state from "./narrow_state";
|
||||||
|
@ -27,6 +28,13 @@ import * as util from "./util";
|
||||||
const waiting_for_id = new Map();
|
const waiting_for_id = new Map();
|
||||||
let waiting_for_ack = new Map();
|
let waiting_for_ack = new Map();
|
||||||
|
|
||||||
|
function insert_message(message) {
|
||||||
|
// It is a little bit funny to go through the message_events
|
||||||
|
// codepath, but it's sort of the idea behind local echo that
|
||||||
|
// we are simulating server events before they actually arrive.
|
||||||
|
message_events.insert_new_messages([message], true);
|
||||||
|
}
|
||||||
|
|
||||||
function failed_message_success(message_id) {
|
function failed_message_success(message_id) {
|
||||||
message_store.get(message_id).failed_request = false;
|
message_store.get(message_id).failed_request = false;
|
||||||
ui.show_failed_message_success(message_id);
|
ui.show_failed_message_success(message_id);
|
||||||
|
@ -159,7 +167,7 @@ export function insert_local_message(message_request, local_id_float) {
|
||||||
waiting_for_ack.set(message.local_id, message);
|
waiting_for_ack.set(message.local_id, message);
|
||||||
|
|
||||||
message.display_recipient = build_display_recipient(message);
|
message.display_recipient = build_display_recipient(message);
|
||||||
local_message.insert_message(message);
|
insert_message(message);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import * as blueslip from "./blueslip";
|
import * as blueslip from "./blueslip";
|
||||||
import * as message_events from "./message_events";
|
|
||||||
import * as message_list from "./message_list";
|
import * as message_list from "./message_list";
|
||||||
import {page_params} from "./page_params";
|
import {page_params} from "./page_params";
|
||||||
|
|
||||||
|
@ -7,13 +6,6 @@ function truncate_precision(float) {
|
||||||
return Number.parseFloat(float.toFixed(3));
|
return Number.parseFloat(float.toFixed(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function insert_message(message) {
|
|
||||||
// It is a little bit funny to go through the message_events
|
|
||||||
// codepath, but it's sort of the idea behind local echo that
|
|
||||||
// we are simulating server events before they actually arrive.
|
|
||||||
message_events.insert_new_messages([message], true);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const get_next_id_float = (function () {
|
export const get_next_id_float = (function () {
|
||||||
const already_used = new Set();
|
const already_used = new Set();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue