diff --git a/.eslintrc.json b/.eslintrc.json index 404ccb5367..72fde36967 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -189,7 +189,6 @@ "padded_widget": false, "page_params": false, "panels": false, - "pm_list": false, "pointer": false, "popovers": false, "presence": false, diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js index 4e74492aa4..6e7b12e876 100644 --- a/frontend_tests/node_tests/activity.js +++ b/frontend_tests/node_tests/activity.js @@ -47,6 +47,7 @@ const _scroll_util = { }; const _pm_list = { + __esModule: true, update_private_messages: () => {}, }; @@ -72,7 +73,7 @@ rewiremock("../../static/js/channel").with(channel); set_global("compose_state", compose_state); set_global("document", _document); rewiremock("../../static/js/keydown_util").with(_keydown_util); -set_global("pm_list", _pm_list); +rewiremock("../../static/js/pm_list").with(_pm_list); set_global("popovers", _popovers); set_global("resize", _resize); rewiremock("../../static/js/scroll_util").with(_scroll_util); diff --git a/frontend_tests/node_tests/message_events.js b/frontend_tests/node_tests/message_events.js index 262bd787fa..84023d3ad7 100644 --- a/frontend_tests/node_tests/message_events.js +++ b/frontend_tests/node_tests/message_events.js @@ -13,7 +13,8 @@ const message_edit = set_global("message_edit", {}); const message_list = set_global("message_list", {}); const notifications = set_global("notifications", {}); const page_params = set_global("page_params", {}); -const pm_list = set_global("pm_list", {}); +const pm_list = {__esModule: true}; +rewiremock("../../static/js/pm_list").with(pm_list); const stream_list = set_global("stream_list", {}); const unread_ui = {__esModule: true}; diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js index 7235175ac9..3bd5d6c2b6 100644 --- a/frontend_tests/node_tests/message_fetch.js +++ b/frontend_tests/node_tests/message_fetch.js @@ -40,7 +40,8 @@ set_global("message_scroll", { const message_util = set_global("message_util", {}); const message_store = set_global("message_store", {}); const narrow_state = set_global("narrow_state", {}); -const pm_list = set_global("pm_list", {}); +const pm_list = {__esModule: true}; +rewiremock("../../static/js/pm_list").with(pm_list); const server_events = set_global("server_events", {}); const stream_list = set_global("stream_list", { maybe_scroll_narrow_into_view: () => {}, diff --git a/frontend_tests/node_tests/top_left_corner.js b/frontend_tests/node_tests/top_left_corner.js index 2c68e35630..cb1513f46a 100644 --- a/frontend_tests/node_tests/top_left_corner.js +++ b/frontend_tests/node_tests/top_left_corner.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const rewiremock = require("rewiremock/node"); + const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); const $ = require("../zjsunit/zjquery"); @@ -9,6 +11,7 @@ const $ = require("../zjsunit/zjquery"); set_global("resize", { resize_stream_filters_container: () => {}, }); +rewiremock.enable(); const Filter = zrequire("Filter", "js/filter"); const people = zrequire("people"); @@ -20,7 +23,7 @@ run_test("narrowing", () => { let pm_expanded; let pm_closed; - set_global("pm_list", { + rewiremock("../../static/js/pm_list").with({ close() { pm_closed = true; }, @@ -135,3 +138,4 @@ run_test("update_count_in_dom", () => { assert.equal($("").text(), ""); assert.equal($("").text(), ""); }); +rewiremock.disable(); diff --git a/frontend_tests/node_tests/tutorial.js b/frontend_tests/node_tests/tutorial.js index 4b58d2fbe5..957c7eb44d 100644 --- a/frontend_tests/node_tests/tutorial.js +++ b/frontend_tests/node_tests/tutorial.js @@ -23,7 +23,8 @@ set_global("page_params", {}); const activity = set_global("activity", {}); const message_live_update = set_global("message_live_update", {}); -const pm_list = set_global("pm_list", {}); +const pm_list = {__esModule: true}; +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", {}); diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js index bf75d60b01..defa408713 100644 --- a/frontend_tests/node_tests/ui_init.js +++ b/frontend_tests/node_tests/ui_init.js @@ -129,7 +129,6 @@ zrequire("narrow"); zrequire("search_suggestion"); zrequire("search"); zrequire("notifications"); -zrequire("pm_list"); zrequire("stream_list"); zrequire("sent_messages"); zrequire("top_left_corner"); diff --git a/frontend_tests/node_tests/user_events.js b/frontend_tests/node_tests/user_events.js index f5c7a764d6..2f6e6e4eb2 100644 --- a/frontend_tests/node_tests/user_events.js +++ b/frontend_tests/node_tests/user_events.js @@ -2,6 +2,8 @@ const {strict: assert} = require("assert"); +const rewiremock = require("rewiremock/node"); + const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); @@ -32,7 +34,7 @@ const page_params = set_global("page_params", { is_admin: true, }); -set_global("pm_list", { +rewiremock("../../static/js/pm_list").with({ update_private_messages() {}, }); @@ -51,6 +53,8 @@ const settings_account = set_global("settings_account", { const message_live_update = set_global("message_live_update", {}); +rewiremock.enable(); + const people = zrequire("people"); const settings_config = zrequire("settings_config"); const user_events = zrequire("user_events"); @@ -207,3 +211,4 @@ run_test("updates", () => { person = people.get_by_email(test_bot.email); assert.equal(person.bot_owner_id, me.user_id); }); +rewiremock.disable(); diff --git a/static/js/activity.js b/static/js/activity.js index bdb7c92b64..34cedaca01 100644 --- a/static/js/activity.js +++ b/static/js/activity.js @@ -6,6 +6,7 @@ const channel = require("./channel"); const keydown_util = require("./keydown_util"); const {ListCursor} = require("./list_cursor"); const people = require("./people"); +const pm_list = require("./pm_list"); const {UserSearch} = require("./user_search"); const user_status = require("./user_status"); diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js index 459806851f..fdf2ebc56a 100644 --- a/static/js/bundles/app.js +++ b/static/js/bundles/app.js @@ -19,7 +19,6 @@ import "../input_pill"; import "../setup"; import "../unread_ops"; import "../unread"; -import "../pm_list"; import "../recent_senders"; import "../top_left_corner"; import "../stream_list"; diff --git a/static/js/echo.js b/static/js/echo.js index 66cf60dabb..b0ceba17f6 100644 --- a/static/js/echo.js +++ b/static/js/echo.js @@ -1,5 +1,6 @@ import * as alert_words from "./alert_words"; import * as people from "./people"; +import * as pm_list from "./pm_list"; import * as rows from "./rows"; import * as util from "./util"; diff --git a/static/js/global.d.ts b/static/js/global.d.ts index 3bfd1e4486..e2a4b7970e 100644 --- a/static/js/global.d.ts +++ b/static/js/global.d.ts @@ -63,7 +63,6 @@ declare let overlays: any; declare let padded_widget: any; declare let page_params: any; declare let panels: any; -declare let pm_list: any; declare let pointer: any; declare let poll_widget: any; declare let popovers: any; diff --git a/static/js/message_events.js b/static/js/message_events.js index fdb952d191..c1e3a8e94c 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -4,6 +4,7 @@ const alert_words = require("./alert_words"); const channel = require("./channel"); const huddle_data = require("./huddle_data"); const message_edit_history = require("./message_edit_history"); +const pm_list = require("./pm_list"); const unread_ui = require("./unread_ui"); const util = require("./util"); diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js index bcc074dd58..a72297fee8 100644 --- a/static/js/message_fetch.js +++ b/static/js/message_fetch.js @@ -3,6 +3,7 @@ const channel = require("./channel"); const huddle_data = require("./huddle_data"); const people = require("./people"); +const pm_list = require("./pm_list"); const consts = { backfill_idle_time: 10 * 1000, diff --git a/static/js/pm_list.js b/static/js/pm_list.js index 130ee1499b..a9e39f22e8 100644 --- a/static/js/pm_list.js +++ b/static/js/pm_list.js @@ -1,10 +1,8 @@ -"use strict"; - -const people = require("./people"); -const pm_conversations = require("./pm_conversations"); -const pm_list_dom = require("./pm_list_dom"); -const unread_ui = require("./unread_ui"); -const vdom = require("./vdom"); +import * as people from "./people"; +import * as pm_conversations from "./pm_conversations"; +import * as pm_list_dom from "./pm_list_dom"; +import * as unread_ui from "./unread_ui"; +import * as vdom from "./vdom"; let prior_dom; let private_messages_open = false; @@ -37,13 +35,13 @@ function remove_expanded_private_messages() { ui.get_content_element($("#private-container")).empty(); } -exports.close = function () { +export function close() { private_messages_open = false; prior_dom = undefined; remove_expanded_private_messages(); -}; +} -exports.get_active_user_ids_string = function () { +export function get_active_user_ids_string() { const filter = narrow_state.filter(); if (!filter) { @@ -57,12 +55,12 @@ exports.get_active_user_ids_string = function () { } return people.emails_strings_to_user_ids_string(emails); -}; +} -exports._get_convos = function () { +export function _get_convos() { const private_messages = pm_conversations.recent.get(); const display_messages = []; - const active_user_ids_string = exports.get_active_user_ids_string(); + const active_user_ids_string = get_active_user_ids_string(); for (const private_message_obj of private_messages) { const user_ids_string = private_message_obj.user_ids_string; @@ -106,22 +104,22 @@ exports._get_convos = function () { } return display_messages; -}; +} -exports._build_private_messages_list = function () { - const convos = exports._get_convos(); +export function _build_private_messages_list() { + const convos = _get_convos(); const dom_ast = pm_list_dom.pm_ul(convos); return dom_ast; -}; +} -exports.update_private_messages = function () { +export function update_private_messages() { if (!narrow_state.active()) { return; } if (private_messages_open) { const container = ui.get_content_element($("#private-container")); - const new_dom = exports._build_private_messages_list(); + const new_dom = _build_private_messages_list(); function replace_content(html) { container.html(html); @@ -134,9 +132,9 @@ exports.update_private_messages = function () { vdom.update(replace_content, find, new_dom, prior_dom); prior_dom = new_dom; } -}; +} -exports.is_all_privates = function () { +export function is_all_privates() { const filter = narrow_state.filter(); if (!filter) { @@ -144,26 +142,24 @@ exports.is_all_privates = function () { } return filter.operands("is").includes("private"); -}; +} -exports.expand = function () { +export function expand() { private_messages_open = true; stream_popover.hide_topic_popover(); - exports.update_private_messages(); - if (exports.is_all_privates()) { + update_private_messages(); + if (is_all_privates()) { $(".top_left_private_messages").addClass("active-filter"); } -}; +} -exports.update_dom_with_unread_counts = function (counts) { - exports.update_private_messages(); +export function update_dom_with_unread_counts(counts) { + update_private_messages(); set_count(counts.private_message_count); unread_ui.set_count_toggle_button( $("#userlist-toggle-unreadcount"), counts.private_message_count, ); -}; +} -exports.initialize = function () {}; - -window.pm_list = exports; +export function initialize() {} diff --git a/static/js/top_left_corner.js b/static/js/top_left_corner.js index 76de44ae72..9d50af3f5b 100644 --- a/static/js/top_left_corner.js +++ b/static/js/top_left_corner.js @@ -1,6 +1,7 @@ "use strict"; const people = require("./people"); +const pm_list = require("./pm_list"); const unread_ui = require("./unread_ui"); exports.update_count_in_dom = function (unread_count_elem, count) { diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 77b245082b..920c875c96 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -20,6 +20,7 @@ const message_viewport = require("./message_viewport"); const muting = require("./muting"); const people = require("./people"); const pm_conversations = require("./pm_conversations"); +const pm_list = require("./pm_list"); const rows = require("./rows"); const spoilers = require("./spoilers"); const topic_list = require("./topic_list"); diff --git a/static/js/unread_ui.js b/static/js/unread_ui.js index 76c73f22e9..103402f6a7 100644 --- a/static/js/unread_ui.js +++ b/static/js/unread_ui.js @@ -1,3 +1,4 @@ +import * as pm_list from "./pm_list"; import * as topic_list from "./topic_list"; let last_mention_count = 0; diff --git a/static/js/user_events.js b/static/js/user_events.js index 5410fbd5bf..5d53f5fa65 100644 --- a/static/js/user_events.js +++ b/static/js/user_events.js @@ -5,6 +5,7 @@ // dependencies that existed when this code was in people.js. // (We should do bot updates here too.) const people = require("./people"); +const pm_list = require("./pm_list"); const settings_config = require("./settings_config"); exports.update_person = function update(person) {