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

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-27 16:10:03 -08:00 committed by Tim Abbott
parent ac65935b16
commit 7145cb4a0d
46 changed files with 118 additions and 61 deletions

View File

@ -154,7 +154,6 @@
"message_events": false, "message_events": false,
"message_fetch": false, "message_fetch": false,
"message_list": false, "message_list": false,
"message_store": false,
"message_util": false, "message_util": false,
"narrow": false, "narrow": false,
"padded_widget": false, "padded_widget": false,

View File

@ -14,9 +14,12 @@ const stream_topic_history = {__esModule: true};
rewiremock("../../static/js/stream_topic_history").with(stream_topic_history); rewiremock("../../static/js/stream_topic_history").with(stream_topic_history);
const message_store = set_global("message_store", { const message_store = {
__esModule: true,
user_ids: () => [], user_ids: () => [],
}); };
rewiremock("../../static/js/message_store").with(message_store);
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
const channel = {__esModule: true}; const channel = {__esModule: true};

View File

@ -30,7 +30,7 @@ rewiremock("../../static/js/sent_messages").with({
}, },
}); });
set_global("message_store", { rewiremock("../../static/js/message_store").with({
get: () => ({failed_request: true}), get: () => ({failed_request: true}),
update_booleans: () => {}, update_booleans: () => {},
}); });

View File

@ -2,13 +2,18 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace"); const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery"); const $ = require("../zjsunit/zjquery");
const message_store = set_global("message_store", {}); const message_store = {__esModule: true};
rewiremock("../../static/js/message_store").with(message_store);
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
rewiremock.enable();
zrequire("unread"); zrequire("unread");
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");
const people = zrequire("people"); const people = zrequire("people");
@ -1553,3 +1558,4 @@ run_test("error_cases", () => {
const predicate = get_predicate([["pm-with", "Joe@example.com"]]); const predicate = get_predicate([["pm-with", "Joe@example.com"]]);
assert(!predicate({type: "private"})); assert(!predicate({type: "private"}));
}); });
rewiremock.disable();

View File

@ -22,7 +22,9 @@ rewiremock.enable();
const rows = zrequire("rows"); const rows = zrequire("rows");
const lightbox = zrequire("lightbox"); const lightbox = zrequire("lightbox");
const message_store = set_global("message_store", {}); const message_store = {__esModule: true};
rewiremock("../../static/js/message_store").with(message_store);
rows.__Rewire__("is_draft_row", () => false); rows.__Rewire__("is_draft_row", () => false);

View File

@ -39,7 +39,6 @@ const fenced_code = zrequire("fenced_code", "shared/js/fenced_code");
const markdown_config = zrequire("markdown_config"); const markdown_config = zrequire("markdown_config");
const marked = zrequire("marked", "third/marked/lib/marked"); const marked = zrequire("marked", "third/marked/lib/marked");
const markdown = zrequire("markdown"); const markdown = zrequire("markdown");
zrequire("message_store");
const people = zrequire("people"); const people = zrequire("people");
const stream_data = zrequire("stream_data"); const stream_data = zrequire("stream_data");
const user_groups = zrequire("user_groups"); const user_groups = zrequire("user_groups");

View File

@ -22,7 +22,6 @@ rewiremock("katex").with({
rewiremock.enable(); rewiremock.enable();
const markdown_config = zrequire("markdown_config"); const markdown_config = zrequire("markdown_config");
zrequire("message_store");
const markdown = zrequire("markdown"); const markdown = zrequire("markdown");

View File

@ -40,7 +40,8 @@ rewiremock("../../static/js/message_scroll").with({
update_top_of_narrow_notices: () => {}, update_top_of_narrow_notices: () => {},
}); });
const message_util = set_global("message_util", {}); const message_util = set_global("message_util", {});
const message_store = set_global("message_store", {}); const message_store = {__esModule: true};
rewiremock("../../static/js/message_store").with(message_store);
const narrow_state = {__esModule: true}; const narrow_state = {__esModule: true};
rewiremock("../../static/js/narrow_state").with(narrow_state); rewiremock("../../static/js/narrow_state").with(narrow_state);
const pm_list = {__esModule: true}; const pm_list = {__esModule: true};

View File

@ -7,7 +7,8 @@ const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace"); const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const message_store = set_global("message_store", {}); const message_store = {__esModule: true};
rewiremock("../../static/js/message_store").with(message_store);
set_global("page_params", {}); set_global("page_params", {});
rewiremock("../../static/js/muting").with({ rewiremock("../../static/js/muting").with({

View File

@ -5,13 +5,17 @@ const {strict: assert} = require("assert");
const {parseISO} = require("date-fns"); const {parseISO} = require("date-fns");
const _ = require("lodash"); const _ = require("lodash");
const MockDate = require("mockdate"); const MockDate = require("mockdate");
const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace"); const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const message_store = set_global("message_store", {}); const message_store = {__esModule: true};
rewiremock("../../static/js/message_store").with(message_store);
const page_params = set_global("page_params", {}); const page_params = set_global("page_params", {});
rewiremock.enable();
const people = zrequire("people"); const people = zrequire("people");
const settings_config = zrequire("settings_config"); const settings_config = zrequire("settings_config");
const visibility = settings_config.email_address_visibility_values; const visibility = settings_config.email_address_visibility_values;
@ -1113,3 +1117,4 @@ run_test("get_active_message_people", () => {
// reset to native Date() // reset to native Date()
MockDate.reset(); MockDate.reset();
rewiremock.disable();

View File

@ -54,12 +54,16 @@ const message = {
], ],
}; };
const message_store = set_global("message_store", { const message_store = {
__esModule: true,
get(message_id) { get(message_id) {
assert.equal(message_id, 1001); assert.equal(message_id, 1001);
return message; return message;
}, },
}); };
rewiremock("../../static/js/message_store").with(message_store);
set_global("current_msg_list", { set_global("current_msg_list", {
selected_message() { selected_message() {

View File

@ -2,13 +2,15 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace"); const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
let next_id = 0; let next_id = 0;
const messages = []; const messages = [];
set_global("message_store", { rewiremock("../../static/js/message_store").with({
get: (msg_id) => messages[msg_id - 1], get: (msg_id) => messages[msg_id - 1],
}); });
set_global("message_list", { set_global("message_list", {
@ -19,6 +21,8 @@ set_global("message_list", {
}, },
}); });
rewiremock.enable();
const rs = zrequire("recent_senders"); const rs = zrequire("recent_senders");
zrequire("message_util.js"); zrequire("message_util.js");
@ -228,3 +232,4 @@ run_test("process_message_for_senders", () => {
// no changes should take place in this case. // no changes should take place in this case.
rs.update_topics_of_deleted_message_ids([-1]); rs.update_topics_of_deleted_message_ids([-1]);
}); });
rewiremock.disable();

View File

@ -146,7 +146,7 @@ set_global("message_list", {
}, },
}, },
}); });
set_global("message_store", { rewiremock("../../static/js/message_store").with({
get: (msg_id) => messages[msg_id - 1], get: (msg_id) => messages[msg_id - 1],
}); });
rewiremock("../../static/js/stream_data").with({ rewiremock("../../static/js/stream_data").with({

View File

@ -2,6 +2,8 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace"); const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
@ -9,12 +11,14 @@ const page_params = set_global("page_params", {
search_pills_enabled: true, search_pills_enabled: true,
}); });
set_global("message_store", { rewiremock("../../static/js/message_store").with({
user_ids: () => [], user_ids: () => [],
}); });
set_global("narrow", {}); set_global("narrow", {});
rewiremock.enable();
const settings_config = zrequire("settings_config"); const settings_config = zrequire("settings_config");
page_params.realm_email_address_visibility = page_params.realm_email_address_visibility =
settings_config.email_address_visibility_values.admins_only.code; settings_config.email_address_visibility_values.admins_only.code;
@ -966,3 +970,4 @@ run_test("multiple_operators_without_pills", () => {
expected = ["is:alerted sender:ted@zulip.com abc"]; expected = ["is:alerted sender:ted@zulip.com abc"];
assert.deepEqual(suggestions.strings, expected); assert.deepEqual(suggestions.strings, expected);
}); });
rewiremock.disable();

View File

@ -2,17 +2,21 @@
const {strict: assert} = require("assert"); const {strict: assert} = require("assert");
const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace"); const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test"); const {run_test} = require("../zjsunit/test");
const page_params = set_global("page_params", { const page_params = set_global("page_params", {
search_pills_enabled: false, search_pills_enabled: false,
}); });
set_global("message_store", { rewiremock("../../static/js/message_store").with({
user_ids: () => [], user_ids: () => [],
}); });
set_global("narrow", {}); set_global("narrow", {});
rewiremock.enable();
const settings_config = zrequire("settings_config"); const settings_config = zrequire("settings_config");
page_params.realm_email_address_visibility = page_params.realm_email_address_visibility =
settings_config.email_address_visibility_values.admins_only.code; settings_config.email_address_visibility_values.admins_only.code;
@ -884,3 +888,4 @@ run_test("queries_with_spaces", () => {
expected = ["stream:offi", "stream:office"]; expected = ["stream:offi", "stream:office"];
assert.deepEqual(suggestions.strings, expected); assert.deepEqual(suggestions.strings, expected);
}); });
rewiremock.disable();

View File

@ -53,7 +53,6 @@ set_global("$", {
rewiremock.enable(); rewiremock.enable();
zrequire("message_store");
const server_events = zrequire("server_events"); const server_events = zrequire("server_events");
set_global("$", $); set_global("$", $);

View File

@ -10,7 +10,9 @@ const {run_test} = require("../zjsunit/test");
const channel = {__esModule: true}; const channel = {__esModule: true};
rewiremock("../../static/js/channel").with(channel); rewiremock("../../static/js/channel").with(channel);
const widgetize = set_global("widgetize", {}); const widgetize = set_global("widgetize", {});
const message_store = set_global("message_store", {}); const message_store = {__esModule: true};
rewiremock("../../static/js/message_store").with(message_store);
rewiremock.enable(); rewiremock.enable();

View File

@ -15,7 +15,9 @@ let page_params = set_global("page_params", {
rewiremock("../../static/js/narrow_state").with({}); rewiremock("../../static/js/narrow_state").with({});
set_global("current_msg_list", {}); set_global("current_msg_list", {});
set_global("home_msg_list", {}); set_global("home_msg_list", {});
const message_store = set_global("message_store", {}); const message_store = {__esModule: true};
rewiremock("../../static/js/message_store").with(message_store);
rewiremock.enable(); rewiremock.enable();

View File

@ -30,7 +30,6 @@ import "../ui";
import "../composebox_typeahead"; import "../composebox_typeahead";
import "../hotkey"; import "../hotkey";
import "../notifications"; import "../notifications";
import "../message_store";
import "../message_util"; import "../message_util";
import "../message_events"; import "../message_events";
import "../message_fetch"; import "../message_fetch";

View File

@ -14,6 +14,7 @@ import * as hashchange from "./hashchange";
import * as message_edit from "./message_edit"; import * as message_edit from "./message_edit";
import * as message_edit_history from "./message_edit_history"; import * as message_edit_history from "./message_edit_history";
import * as message_flags from "./message_flags"; import * as message_flags from "./message_flags";
import * as message_store from "./message_store";
import * as muting_ui from "./muting_ui"; import * as muting_ui from "./muting_ui";
import * as notifications from "./notifications"; import * as notifications from "./notifications";
import * as overlays from "./overlays"; import * as overlays from "./overlays";

View File

@ -13,6 +13,7 @@ const channel = require("./channel");
const compose = require("./compose"); const compose = require("./compose");
const compose_pm_pill = require("./compose_pm_pill"); const compose_pm_pill = require("./compose_pm_pill");
const compose_state = require("./compose_state"); const compose_state = require("./compose_state");
const message_store = require("./message_store");
const people = require("./people"); const people = require("./people");
const rows = require("./rows"); const rows = require("./rows");
const settings_data = require("./settings_data"); const settings_data = require("./settings_data");

View File

@ -2,6 +2,7 @@ import * as alert_words from "./alert_words";
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_store from "./message_store";
import * as narrow_state from "./narrow_state"; import * as narrow_state from "./narrow_state";
import * as notifications from "./notifications"; import * as notifications from "./notifications";
import * as people from "./people"; import * as people from "./people";

View File

@ -8,6 +8,7 @@ const render_emoji_popover_content = require("../templates/emoji_popover_content
const render_emoji_popover_search_results = require("../templates/emoji_popover_search_results.hbs"); const render_emoji_popover_search_results = require("../templates/emoji_popover_search_results.hbs");
const render_emoji_showcase = require("../templates/emoji_showcase.hbs"); const render_emoji_showcase = require("../templates/emoji_showcase.hbs");
const message_store = require("./message_store");
const popovers = require("./popovers"); const popovers = require("./popovers");
const rows = require("./rows"); const rows = require("./rows");

View File

@ -1,6 +1,7 @@
import Handlebars from "handlebars/runtime"; import Handlebars from "handlebars/runtime";
import _ from "lodash"; import _ from "lodash";
import * as message_store from "./message_store";
import * as people from "./people"; import * as people from "./people";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as util from "./util"; import * as util from "./util";

View File

@ -1,3 +1,4 @@
import * as message_store from "./message_store";
import * as rows from "./rows"; import * as rows from "./rows";
let is_floating_recipient_bar_showing = false; let is_floating_recipient_bar_showing = false;

View File

@ -27,7 +27,6 @@ declare let input_pill: any;
declare let message_events: any; declare let message_events: any;
declare let message_fetch: any; declare let message_fetch: any;
declare let message_list: any; declare let message_list: any;
declare let message_store: any;
declare let message_util: any; declare let message_util: any;
declare let narrow: any; declare let narrow: any;
declare let padded_widget: any; declare let padded_widget: any;

View File

@ -1,4 +1,5 @@
import {LightboxCanvas} from "./lightbox_canvas"; import {LightboxCanvas} from "./lightbox_canvas";
import * as message_store from "./message_store";
import * as overlays from "./overlays"; import * as overlays from "./overlays";
import * as people from "./people"; import * as people from "./people";
import * as popovers from "./popovers"; import * as popovers from "./popovers";

View File

@ -6,6 +6,8 @@ import * as emoji from "../shared/js/emoji";
import * as fenced_code from "../shared/js/fenced_code"; import * as fenced_code from "../shared/js/fenced_code";
import marked from "../third/marked/lib/marked"; import marked from "../third/marked/lib/marked";
import * as message_store from "./message_store";
// This contains zulip's frontend Markdown implementation; see // This contains zulip's frontend Markdown implementation; see
// docs/subsystems/markdown.md for docs on our Markdown syntax. The other // docs/subsystems/markdown.md for docs on our Markdown syntax. The other
// main piece in rendering Markdown client-side is // main piece in rendering Markdown client-side is

View File

@ -9,6 +9,7 @@ import * as condense from "./condense";
import * as echo from "./echo"; import * as echo from "./echo";
import * as loading from "./loading"; import * as loading from "./loading";
import * as markdown from "./markdown"; import * as markdown from "./markdown";
import * as message_store from "./message_store";
import * as message_viewport from "./message_viewport"; import * as message_viewport from "./message_viewport";
import * as resize from "./resize"; import * as resize from "./resize";
import * as rows from "./rows"; import * as rows from "./rows";

View File

@ -8,6 +8,7 @@ const condense = require("./condense");
const huddle_data = require("./huddle_data"); const huddle_data = require("./huddle_data");
const message_edit = require("./message_edit"); const message_edit = require("./message_edit");
const message_edit_history = require("./message_edit_history"); const message_edit_history = require("./message_edit_history");
const message_store = require("./message_store");
const narrow_state = require("./narrow_state"); const narrow_state = require("./narrow_state");
const notifications = require("./notifications"); const notifications = require("./notifications");
const pm_list = require("./pm_list"); const pm_list = require("./pm_list");

View File

@ -4,6 +4,7 @@ const channel = require("./channel");
const {Filter} = require("./filter"); const {Filter} = require("./filter");
const huddle_data = require("./huddle_data"); const huddle_data = require("./huddle_data");
const message_scroll = require("./message_scroll"); const message_scroll = require("./message_scroll");
const message_store = require("./message_store");
const people = require("./people"); const people = require("./people");
const pm_list = require("./pm_list"); const pm_list = require("./pm_list");
const stream_data = require("./stream_data"); const stream_data = require("./stream_data");

View File

@ -1,6 +1,7 @@
import _ from "lodash"; import _ from "lodash";
import * as channel from "./channel"; import * as channel from "./channel";
import * as message_store from "./message_store";
import * as starred_messages from "./starred_messages"; import * as starred_messages from "./starred_messages";
function send_flag_update(message, flag, op) { function send_flag_update(message, flag, op) {

View File

@ -11,6 +11,7 @@ import * as compose_fade from "./compose_fade";
import * as condense from "./condense"; import * as condense from "./condense";
import * as hash_util from "./hash_util"; import * as hash_util from "./hash_util";
import * as message_edit from "./message_edit"; import * as message_edit from "./message_edit";
import * as message_store from "./message_store";
import * as message_viewport from "./message_viewport"; import * as message_viewport from "./message_viewport";
import * as narrow_state from "./narrow_state"; import * as narrow_state from "./narrow_state";
import * as people from "./people"; import * as people from "./people";

View File

@ -1,3 +1,4 @@
import * as message_store from "./message_store";
import * as people from "./people"; import * as people from "./people";
function rerender_messages_view() { function rerender_messages_view() {

View File

@ -1,11 +1,9 @@
"use strict"; import * as alert_words from "./alert_words";
import * as people from "./people";
const alert_words = require("./alert_words"); import * as pm_conversations from "./pm_conversations";
const people = require("./people"); import * as recent_senders from "./recent_senders";
const pm_conversations = require("./pm_conversations"); import * as stream_topic_history from "./stream_topic_history";
const recent_senders = require("./recent_senders"); import * as util from "./util";
const stream_topic_history = require("./stream_topic_history");
const util = require("./util");
const stored_messages = new Map(); const stored_messages = new Map();
@ -24,11 +22,11 @@ const stored_messages = new Map();
*/ */
const message_user_ids = new Set(); const message_user_ids = new Set();
exports.user_ids = function () { export function user_ids() {
return Array.from(message_user_ids); return Array.from(message_user_ids);
}; }
exports.get = function get(message_id) { export function get(message_id) {
if (message_id === undefined || message_id === null) { if (message_id === undefined || message_id === null) {
blueslip.error("message_store.get got bad value: " + message_id); blueslip.error("message_store.get got bad value: " + message_id);
return undefined; return undefined;
@ -43,15 +41,15 @@ exports.get = function get(message_id) {
} }
return stored_messages.get(message_id); return stored_messages.get(message_id);
}; }
exports.each = function (f) { export function each(f) {
for (const [id, message] of stored_messages) { for (const [id, message] of stored_messages) {
f(message, id); f(message, id);
} }
}; }
exports.get_pm_emails = function (message) { export function get_pm_emails(message) {
const user_ids = people.pm_with_user_ids(message); const user_ids = people.pm_with_user_ids(message);
const emails = user_ids const emails = user_ids
.map((user_id) => { .map((user_id) => {
@ -65,9 +63,9 @@ exports.get_pm_emails = function (message) {
.sort(); .sort();
return emails.join(", "); return emails.join(", ");
}; }
exports.get_pm_full_names = function (message) { export function get_pm_full_names(message) {
const user_ids = people.pm_with_user_ids(message); const user_ids = people.pm_with_user_ids(message);
const names = user_ids const names = user_ids
.map((user_id) => { .map((user_id) => {
@ -81,9 +79,9 @@ exports.get_pm_full_names = function (message) {
.sort(); .sort();
return names.join(", "); return names.join(", ");
}; }
exports.process_message_for_recent_private_messages = function (message) { export function process_message_for_recent_private_messages(message) {
const user_ids = people.pm_with_user_ids(message); const user_ids = people.pm_with_user_ids(message);
if (!user_ids) { if (!user_ids) {
return; return;
@ -94,9 +92,9 @@ exports.process_message_for_recent_private_messages = function (message) {
} }
pm_conversations.recent.insert(user_ids, message.id); pm_conversations.recent.insert(user_ids, message.id);
}; }
exports.set_message_booleans = function (message) { export function set_message_booleans(message) {
const flags = message.flags || []; const flags = message.flags || [];
function convert_flag(flag_name) { function convert_flag(flag_name) {
@ -115,9 +113,9 @@ exports.set_message_booleans = function (message) {
// just a distraction, so we delete it. (All the downstream code // just a distraction, so we delete it. (All the downstream code
// uses booleans.) // uses booleans.)
delete message.flags; delete message.flags;
}; }
exports.init_booleans = function (message) { export function init_booleans(message) {
// This initializes booleans for the local-echo path where // This initializes booleans for the local-echo path where
// we don't have flags from the server yet. (We want to // we don't have flags from the server yet. (We want to
// explicitly set flags to false to be consistent with other // explicitly set flags to false to be consistent with other
@ -129,9 +127,9 @@ exports.init_booleans = function (message) {
message.mentioned_me_directly = false; message.mentioned_me_directly = false;
message.collapsed = false; message.collapsed = false;
message.alerted = false; message.alerted = false;
}; }
exports.update_booleans = function (message, flags) { export function update_booleans(message, flags) {
// When we get server flags for local echo or message edits, // When we get server flags for local echo or message edits,
// we are vulnerable to race conditions, so only update flags // we are vulnerable to race conditions, so only update flags
// that are driven by message content. // that are driven by message content.
@ -142,9 +140,9 @@ exports.update_booleans = function (message, flags) {
message.mentioned = convert_flag("mentioned") || convert_flag("wildcard_mentioned"); message.mentioned = convert_flag("mentioned") || convert_flag("wildcard_mentioned");
message.mentioned_me_directly = convert_flag("mentioned"); message.mentioned_me_directly = convert_flag("mentioned");
message.alerted = convert_flag("has_alert_word"); message.alerted = convert_flag("has_alert_word");
}; }
exports.add_message_metadata = function (message) { export function add_message_metadata(message) {
const cached_msg = stored_messages.get(message.id); const cached_msg = stored_messages.get(message.id);
if (cached_msg !== undefined) { if (cached_msg !== undefined) {
// Copy the match topic and content over if they exist on // Copy the match topic and content over if they exist on
@ -188,12 +186,12 @@ exports.add_message_metadata = function (message) {
case "private": case "private":
message.is_private = true; message.is_private = true;
message.reply_to = util.normalize_recipients(exports.get_pm_emails(message)); message.reply_to = util.normalize_recipients(get_pm_emails(message));
message.display_reply_to = exports.get_pm_full_names(message); message.display_reply_to = get_pm_full_names(message);
message.pm_with_url = people.pm_with_url(message); message.pm_with_url = people.pm_with_url(message);
message.to_user_ids = people.pm_reply_user_string(message); message.to_user_ids = people.pm_reply_user_string(message);
exports.process_message_for_recent_private_messages(message); process_message_for_recent_private_messages(message);
if (people.is_my_user_id(message.sender_id)) { if (people.is_my_user_id(message.sender_id)) {
for (const recip of message.display_recipient) { for (const recip of message.display_recipient) {
@ -209,20 +207,20 @@ exports.add_message_metadata = function (message) {
} }
stored_messages.set(message.id, message); stored_messages.set(message.id, message);
return message; return message;
}; }
exports.update_property = function (property, value, info) { export function update_property(property, value, info) {
switch (property) { switch (property) {
case "sender_full_name": case "sender_full_name":
case "small_avatar_url": case "small_avatar_url":
exports.each((msg) => { each((msg) => {
if (msg.sender_id && msg.sender_id === info.user_id) { if (msg.sender_id && msg.sender_id === info.user_id) {
msg[property] = value; msg[property] = value;
} }
}); });
break; break;
case "stream_name": case "stream_name":
exports.each((msg) => { each((msg) => {
if (msg.stream_id && msg.stream_id === info.stream_id) { if (msg.stream_id && msg.stream_id === info.stream_id) {
msg.display_recipient = value; msg.display_recipient = value;
msg.stream = value; msg.stream = value;
@ -230,9 +228,9 @@ exports.update_property = function (property, value, info) {
}); });
break; break;
} }
}; }
exports.reify_message_id = function (opts) { export function reify_message_id(opts) {
const old_id = opts.old_id; const old_id = opts.old_id;
const new_id = opts.new_id; const new_id = opts.new_id;
if (stored_messages.has(old_id)) { if (stored_messages.has(old_id)) {
@ -249,6 +247,4 @@ exports.reify_message_id = function (opts) {
} }
} }
} }
}; }
window.message_store = exports;

View File

@ -1,6 +1,7 @@
"use strict"; "use strict";
const loading = require("./loading"); const loading = require("./loading");
const message_store = require("./message_store");
const resize = require("./resize"); const resize = require("./resize");
const unread_ui = require("./unread_ui"); const unread_ui = require("./unread_ui");

View File

@ -10,6 +10,7 @@ const hashchange = require("./hashchange");
const message_edit = require("./message_edit"); const message_edit = require("./message_edit");
const {MessageListData} = require("./message_list_data"); const {MessageListData} = require("./message_list_data");
const message_scroll = require("./message_scroll"); const message_scroll = require("./message_scroll");
const message_store = require("./message_store");
const narrow_state = require("./narrow_state"); const narrow_state = require("./narrow_state");
const notifications = require("./notifications"); const notifications = require("./notifications");
const people = require("./people"); const people = require("./people");

View File

@ -6,6 +6,7 @@ import render_notification from "../templates/notification.hbs";
import * as alert_words from "./alert_words"; import * as alert_words from "./alert_words";
import * as channel from "./channel"; import * as channel from "./channel";
import * as favicon from "./favicon"; import * as favicon from "./favicon";
import * as message_store from "./message_store";
import * as muting from "./muting"; import * as muting from "./muting";
import * as narrow_state from "./narrow_state"; import * as narrow_state from "./narrow_state";
import * as navigate from "./navigate"; import * as navigate from "./navigate";

View File

@ -5,6 +5,7 @@ import _ from "lodash";
import * as typeahead from "../shared/js/typeahead"; import * as typeahead from "../shared/js/typeahead";
import {FoldDict} from "./fold_dict"; import {FoldDict} from "./fold_dict";
import * as message_store from "./message_store";
import * as reload_state from "./reload_state"; import * as reload_state from "./reload_state";
import * as settings_data from "./settings_data"; import * as settings_data from "./settings_data";
import * as util from "./util"; import * as util from "./util";

View File

@ -6,6 +6,7 @@ const emoji = require("../shared/js/emoji");
const render_message_reaction = require("../templates/message_reaction.hbs"); const render_message_reaction = require("../templates/message_reaction.hbs");
const channel = require("./channel"); const channel = require("./channel");
const message_store = require("./message_store");
const people = require("./people"); const people = require("./people");
exports.view = {}; // function namespace exports.view = {}; // function namespace

View File

@ -8,6 +8,7 @@ const drafts = require("./drafts");
const hash_util = require("./hash_util"); const hash_util = require("./hash_util");
const ListWidget = require("./list_widget"); const ListWidget = require("./list_widget");
const {localstorage} = require("./localstorage"); const {localstorage} = require("./localstorage");
const message_store = require("./message_store");
const muting = require("./muting"); const muting = require("./muting");
const narrow_state = require("./narrow_state"); const narrow_state = require("./narrow_state");
const navigate = require("./navigate"); const navigate = require("./navigate");

View File

@ -1,3 +1,4 @@
import * as message_store from "./message_store";
// We don't need an andSelf() here because we already know // We don't need an andSelf() here because we already know
// that our next element is *not* a message_row, so this // that our next element is *not* a message_row, so this
// isn't going to end up empty unless we're at the bottom or top. // isn't going to end up empty unless we're at the bottom or top.

View File

@ -4,6 +4,7 @@ const _ = require("lodash");
const channel = require("./channel"); const channel = require("./channel");
const echo = require("./echo"); const echo = require("./echo");
const message_store = require("./message_store");
const reload = require("./reload"); const reload = require("./reload");
const reload_state = require("./reload_state"); const reload_state = require("./reload_state");
const sent_messages = require("./sent_messages"); const sent_messages = require("./sent_messages");

View File

@ -1,4 +1,5 @@
import * as channel from "./channel"; import * as channel from "./channel";
import * as message_store from "./message_store";
export function get_message_events(message) { export function get_message_events(message) {
if (message.locally_echoed) { if (message.locally_echoed) {

View File

@ -1,6 +1,7 @@
"use strict"; "use strict";
const {FoldDict} = require("./fold_dict"); const {FoldDict} = require("./fold_dict");
const message_store = require("./message_store");
const muting = require("./muting"); const muting = require("./muting");
const people = require("./people"); const people = require("./people");
const stream_data = require("./stream_data"); const stream_data = require("./stream_data");

View File

@ -2,6 +2,7 @@
const channel = require("./channel"); const channel = require("./channel");
const message_flags = require("./message_flags"); const message_flags = require("./message_flags");
const message_store = require("./message_store");
const message_viewport = require("./message_viewport"); const message_viewport = require("./message_viewport");
const notifications = require("./notifications"); const notifications = require("./notifications");
const overlays = require("./overlays"); const overlays = require("./overlays");