mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	js: Convert static/js/message_util.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							7145cb4a0d
						
					
				
				
					commit
					7a45ed46af
				
			@@ -154,7 +154,6 @@
 | 
			
		||||
                "message_events": false,
 | 
			
		||||
                "message_fetch": false,
 | 
			
		||||
                "message_list": false,
 | 
			
		||||
                "message_util": false,
 | 
			
		||||
                "narrow": false,
 | 
			
		||||
                "padded_widget": false,
 | 
			
		||||
                "page_params": false,
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,6 @@ rewiremock.enable();
 | 
			
		||||
zrequire("unread");
 | 
			
		||||
const stream_data = zrequire("stream_data");
 | 
			
		||||
const people = zrequire("people");
 | 
			
		||||
zrequire("message_util", "js/message_util");
 | 
			
		||||
const {Filter} = zrequire("Filter", "js/filter");
 | 
			
		||||
 | 
			
		||||
const me = {
 | 
			
		||||
 
 | 
			
		||||
@@ -39,7 +39,8 @@ rewiremock("../../static/js/message_scroll").with({
 | 
			
		||||
    hide_loading_newer: noop,
 | 
			
		||||
    update_top_of_narrow_notices: () => {},
 | 
			
		||||
});
 | 
			
		||||
const message_util = set_global("message_util", {});
 | 
			
		||||
const message_util = {__esModule: true};
 | 
			
		||||
rewiremock("../../static/js/message_util").with(message_util);
 | 
			
		||||
const message_store = {__esModule: true};
 | 
			
		||||
rewiremock("../../static/js/message_store").with(message_store);
 | 
			
		||||
const narrow_state = {__esModule: true};
 | 
			
		||||
 
 | 
			
		||||
@@ -28,7 +28,7 @@ const message_list = set_global("message_list", {
 | 
			
		||||
});
 | 
			
		||||
const message_scroll = {__esModule: true};
 | 
			
		||||
rewiremock("../../static/js/message_scroll").with(message_scroll);
 | 
			
		||||
set_global("message_util", {});
 | 
			
		||||
rewiremock("../../static/js/message_util").with({});
 | 
			
		||||
const notifications = {__esModule: true};
 | 
			
		||||
rewiremock("../../static/js/notifications").with(notifications);
 | 
			
		||||
set_global("page_params", {});
 | 
			
		||||
 
 | 
			
		||||
@@ -171,7 +171,6 @@ rewiremock("../../static/js/stream_data").with({
 | 
			
		||||
 | 
			
		||||
rewiremock.enable();
 | 
			
		||||
 | 
			
		||||
zrequire("message_util");
 | 
			
		||||
const people = zrequire("people");
 | 
			
		||||
let rt = zrequire("recent_topics");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,8 @@ set_global("settings_notifications", _settings_notifications);
 | 
			
		||||
const color_data = {__esModule: true};
 | 
			
		||||
rewiremock("../../static/js/color_data").with(color_data);
 | 
			
		||||
set_global("current_msg_list", {});
 | 
			
		||||
const message_util = set_global("message_util", {});
 | 
			
		||||
const message_util = {__esModule: true};
 | 
			
		||||
rewiremock("../../static/js/message_util").with(message_util);
 | 
			
		||||
const stream_color = {__esModule: true};
 | 
			
		||||
rewiremock("../../static/js/stream_color").with(stream_color);
 | 
			
		||||
const stream_list = set_global("stream_list", {});
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ run_test("basics", () => {
 | 
			
		||||
    assert.deepEqual(history, ["Topic1", "topic2"]);
 | 
			
		||||
    assert.deepEqual(max_message_id, 104);
 | 
			
		||||
 | 
			
		||||
    set_global("message_util", {
 | 
			
		||||
    rewiremock("../../static/js/message_util").with({
 | 
			
		||||
        get_messages_in_topic: () => [{id: 101}, {id: 102}],
 | 
			
		||||
        get_max_message_id_in_stream: () => 103,
 | 
			
		||||
    });
 | 
			
		||||
@@ -78,7 +78,7 @@ run_test("basics", () => {
 | 
			
		||||
    max_message_id = stream_topic_history.get_max_message_id(stream_id);
 | 
			
		||||
    assert.deepEqual(max_message_id, 103);
 | 
			
		||||
 | 
			
		||||
    set_global("message_util", {
 | 
			
		||||
    rewiremock("../../static/js/message_util").with({
 | 
			
		||||
        get_messages_in_topic: () => [{id: 102}],
 | 
			
		||||
        get_max_message_id_in_stream: () => 103,
 | 
			
		||||
    });
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,8 @@ rewiremock("../../static/js/pm_list").with(pm_list);
 | 
			
		||||
const settings_users = set_global("settings_users", {});
 | 
			
		||||
const home_msg_list = set_global("home_msg_list", {});
 | 
			
		||||
const message_list = set_global("message_list", {});
 | 
			
		||||
const message_util = set_global("message_util", {});
 | 
			
		||||
const message_util = {__esModule: true};
 | 
			
		||||
rewiremock("../../static/js/message_util").with(message_util);
 | 
			
		||||
const notifications = {__esModule: true};
 | 
			
		||||
rewiremock("../../static/js/notifications").with(notifications);
 | 
			
		||||
const overlays = {__esModule: true};
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,6 @@ import "../ui";
 | 
			
		||||
import "../composebox_typeahead";
 | 
			
		||||
import "../hotkey";
 | 
			
		||||
import "../notifications";
 | 
			
		||||
import "../message_util";
 | 
			
		||||
import "../message_events";
 | 
			
		||||
import "../message_fetch";
 | 
			
		||||
import "../server_events";
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ import Handlebars from "handlebars/runtime";
 | 
			
		||||
import _ from "lodash";
 | 
			
		||||
 | 
			
		||||
import * as message_store from "./message_store";
 | 
			
		||||
import * as message_util from "./message_util";
 | 
			
		||||
import * as people from "./people";
 | 
			
		||||
import * as stream_data from "./stream_data";
 | 
			
		||||
import * as util from "./util";
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -27,7 +27,6 @@ declare let input_pill: any;
 | 
			
		||||
declare let message_events: any;
 | 
			
		||||
declare let message_fetch: any;
 | 
			
		||||
declare let message_list: any;
 | 
			
		||||
declare let message_util: any;
 | 
			
		||||
declare let narrow: any;
 | 
			
		||||
declare let padded_widget: any;
 | 
			
		||||
declare let page_params: any;
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ const huddle_data = require("./huddle_data");
 | 
			
		||||
const message_edit = require("./message_edit");
 | 
			
		||||
const message_edit_history = require("./message_edit_history");
 | 
			
		||||
const message_store = require("./message_store");
 | 
			
		||||
const message_util = require("./message_util");
 | 
			
		||||
const narrow_state = require("./narrow_state");
 | 
			
		||||
const notifications = require("./notifications");
 | 
			
		||||
const pm_list = require("./pm_list");
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ const {Filter} = require("./filter");
 | 
			
		||||
const huddle_data = require("./huddle_data");
 | 
			
		||||
const message_scroll = require("./message_scroll");
 | 
			
		||||
const message_store = require("./message_store");
 | 
			
		||||
const message_util = require("./message_util");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
const pm_list = require("./pm_list");
 | 
			
		||||
const stream_data = require("./stream_data");
 | 
			
		||||
 
 | 
			
		||||
@@ -1,15 +1,13 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
import * as loading from "./loading";
 | 
			
		||||
import * as message_store from "./message_store";
 | 
			
		||||
import * as resize from "./resize";
 | 
			
		||||
import * as unread_ui from "./unread_ui";
 | 
			
		||||
 | 
			
		||||
const loading = require("./loading");
 | 
			
		||||
const message_store = require("./message_store");
 | 
			
		||||
const resize = require("./resize");
 | 
			
		||||
const unread_ui = require("./unread_ui");
 | 
			
		||||
 | 
			
		||||
exports.do_unread_count_updates = function do_unread_count_updates(messages) {
 | 
			
		||||
export function do_unread_count_updates(messages) {
 | 
			
		||||
    unread.process_loaded_messages(messages);
 | 
			
		||||
    unread_ui.update_unread_counts();
 | 
			
		||||
    resize.resize_page_components();
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function add_messages(messages, msg_list, opts) {
 | 
			
		||||
    if (!messages) {
 | 
			
		||||
@@ -32,23 +30,23 @@ function is_element_in_message_content(message, element_selector) {
 | 
			
		||||
    return $(`<div>${message.content}</div>`).find(`${element_selector}`).length > 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.message_has_link = function (message) {
 | 
			
		||||
export function message_has_link(message) {
 | 
			
		||||
    return is_element_in_message_content(message, "a");
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.message_has_image = function (message) {
 | 
			
		||||
export function message_has_image(message) {
 | 
			
		||||
    return is_element_in_message_content(message, ".message_inline_image");
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.message_has_attachment = function (message) {
 | 
			
		||||
export function message_has_attachment(message) {
 | 
			
		||||
    return is_element_in_message_content(message, "a[href^='/user_uploads']");
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.add_old_messages = function (messages, msg_list) {
 | 
			
		||||
export function add_old_messages(messages, msg_list) {
 | 
			
		||||
    return add_messages(messages, msg_list, {messages_are_new: false});
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.add_new_messages = function (messages, msg_list) {
 | 
			
		||||
export function add_new_messages(messages, msg_list) {
 | 
			
		||||
    if (!msg_list.data.fetch_status.has_found_newest()) {
 | 
			
		||||
        // We don't render newly received messages for the message list,
 | 
			
		||||
        // if we haven't found the latest messages to be displayed in the
 | 
			
		||||
@@ -58,9 +56,9 @@ exports.add_new_messages = function (messages, msg_list) {
 | 
			
		||||
        return undefined;
 | 
			
		||||
    }
 | 
			
		||||
    return add_messages(messages, msg_list, {messages_are_new: true});
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.get_messages_in_topic = function (stream_id, topic) {
 | 
			
		||||
export function get_messages_in_topic(stream_id, topic) {
 | 
			
		||||
    return message_list.all
 | 
			
		||||
        .all_messages()
 | 
			
		||||
        .filter(
 | 
			
		||||
@@ -69,9 +67,9 @@ exports.get_messages_in_topic = function (stream_id, topic) {
 | 
			
		||||
                x.stream_id === stream_id &&
 | 
			
		||||
                x.topic.toLowerCase() === topic.toLowerCase(),
 | 
			
		||||
        );
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.get_max_message_id_in_stream = function (stream_id) {
 | 
			
		||||
export function get_max_message_id_in_stream(stream_id) {
 | 
			
		||||
    let max_message_id = 0;
 | 
			
		||||
    for (const msg of message_list.all.all_messages()) {
 | 
			
		||||
        if (msg.type === "stream" && msg.stream_id === stream_id && msg.id > max_message_id) {
 | 
			
		||||
@@ -79,9 +77,9 @@ exports.get_max_message_id_in_stream = function (stream_id) {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return max_message_id;
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.get_topics_for_message_ids = function (message_ids) {
 | 
			
		||||
export function get_topics_for_message_ids(message_ids) {
 | 
			
		||||
    const topics = new Map(); // key = stream_id:topic
 | 
			
		||||
    for (const msg_id of message_ids) {
 | 
			
		||||
        // message_store still has data on deleted messages when this runs.
 | 
			
		||||
@@ -98,6 +96,4 @@ exports.get_topics_for_message_ids = function (message_ids) {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return topics;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
window.message_util = exports;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
import {FoldDict} from "./fold_dict";
 | 
			
		||||
import * as message_util from "./message_util";
 | 
			
		||||
 | 
			
		||||
// topic_senders[stream_id][topic_id][sender_id] = latest_message_id
 | 
			
		||||
const topic_senders = new Map();
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ const hash_util = require("./hash_util");
 | 
			
		||||
const ListWidget = require("./list_widget");
 | 
			
		||||
const {localstorage} = require("./localstorage");
 | 
			
		||||
const message_store = require("./message_store");
 | 
			
		||||
const message_util = require("./message_util");
 | 
			
		||||
const muting = require("./muting");
 | 
			
		||||
const narrow_state = require("./narrow_state");
 | 
			
		||||
const navigate = require("./navigate");
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
import * as color_data from "./color_data";
 | 
			
		||||
import * as message_util from "./message_util";
 | 
			
		||||
import * as narrow_state from "./narrow_state";
 | 
			
		||||
import * as overlays from "./overlays";
 | 
			
		||||
import * as peer_data from "./peer_data";
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
import * as message_scroll from "./message_scroll";
 | 
			
		||||
import * as message_util from "./message_util";
 | 
			
		||||
import * as message_viewport from "./message_viewport";
 | 
			
		||||
import * as navigate from "./navigate";
 | 
			
		||||
import * as overlays from "./overlays";
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
import * as channel from "./channel";
 | 
			
		||||
import {FoldDict} from "./fold_dict";
 | 
			
		||||
import * as message_util from "./message_util";
 | 
			
		||||
import * as stream_data from "./stream_data";
 | 
			
		||||
 | 
			
		||||
const stream_dict = new Map(); // stream_id -> PerStreamHistory object
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user