From d774bba1b9f636cadb8031ae396530e6f52e0dfb Mon Sep 17 00:00:00 2001 From: Priyank Patel Date: Tue, 18 Aug 2020 17:53:22 +0000 Subject: [PATCH] js: Purge pm_conversations module from window. All the changes are done using a script followed by updates to Node tests and running eslint and prettier to fix formatting issues. --- .eslintrc.json | 1 - frontend_tests/node_tests/pm_list.js | 2 +- frontend_tests/node_tests/topic_generator.js | 5 ++--- frontend_tests/node_tests/typeahead_helper.js | 11 ++++++----- static/js/global.d.ts | 1 - static/js/message_store.js | 1 + static/js/pm_conversations.js | 2 -- static/js/pm_list.js | 2 ++ static/js/topic_generator.js | 2 ++ static/js/typeahead_helper.js | 1 + static/js/ui_init.js | 1 + 11 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 64e825e1b3..6e96f91c7b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -192,7 +192,6 @@ "panels": false, "pill_typeahead": false, "people": false, - "pm_conversations": false, "pm_list": false, "pm_list_dom": false, "pointer": false, diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.js index a20a22d6aa..569e9dbf39 100644 --- a/frontend_tests/node_tests/pm_list.js +++ b/frontend_tests/node_tests/pm_list.js @@ -21,7 +21,7 @@ zrequire("presence"); zrequire("buddy_data"); zrequire("hash_util"); zrequire("people"); -zrequire("pm_conversations"); +const pm_conversations = zrequire("pm_conversations"); zrequire("pm_list"); const alice = { diff --git a/frontend_tests/node_tests/topic_generator.js b/frontend_tests/node_tests/topic_generator.js index b944533a61..027d611403 100644 --- a/frontend_tests/node_tests/topic_generator.js +++ b/frontend_tests/node_tests/topic_generator.js @@ -1,8 +1,7 @@ "use strict"; -set_global("pm_conversations", { - recent: {}, -}); +const pm_conversations = zrequire("pm_conversations"); +pm_conversations.recent = {}; zrequire("muting"); zrequire("unread"); diff --git a/frontend_tests/node_tests/typeahead_helper.js b/frontend_tests/node_tests/typeahead_helper.js index 3f47dacf08..7fa1a41e5b 100644 --- a/frontend_tests/node_tests/typeahead_helper.js +++ b/frontend_tests/node_tests/typeahead_helper.js @@ -4,11 +4,12 @@ set_global("page_params", {realm_is_zephyr_mirror_realm: false}); set_global("md5", (s) => "md5-" + s); const settings_config = zrequire("settings_config"); +const pm_conversations = zrequire("pm_conversations"); + page_params.realm_email_address_visibility = settings_config.email_address_visibility_values.admins_only.code; zrequire("recent_senders"); -zrequire("pm_conversations"); zrequire("people"); zrequire("stream_data"); zrequire("narrow"); @@ -241,10 +242,10 @@ run_test("sort_recipients", () => { stream_data.update_calculated_fields(linux_sub); // For splitting based on whether a PM was sent - global.pm_conversations.set_partner(5); - global.pm_conversations.set_partner(6); - global.pm_conversations.set_partner(2); - global.pm_conversations.set_partner(7); + pm_conversations.set_partner(5); + pm_conversations.set_partner(6); + pm_conversations.set_partner(2); + pm_conversations.set_partner(7); // For splitting based on recency global.recent_senders.process_message_for_senders({ diff --git a/static/js/global.d.ts b/static/js/global.d.ts index a6d28558a8..6f1dcc011a 100644 --- a/static/js/global.d.ts +++ b/static/js/global.d.ts @@ -90,7 +90,6 @@ declare let page_params: any; declare let panels: any; declare let people: any; declare let pill_typeahead: any; -declare let pm_conversations: any; declare let pm_list: any; declare let pointer: any; declare let poll_widget: any; diff --git a/static/js/message_store.js b/static/js/message_store.js index 812a0e9416..df317507ee 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -1,5 +1,6 @@ "use strict"; +const pm_conversations = require("./pm_conversations"); const util = require("./util"); const stored_messages = new Map(); diff --git a/static/js/pm_conversations.js b/static/js/pm_conversations.js index a87d019b6d..34087aeb04 100644 --- a/static/js/pm_conversations.js +++ b/static/js/pm_conversations.js @@ -77,5 +77,3 @@ class RecentPrivateMessages { } exports.recent = new RecentPrivateMessages(); - -window.pm_conversations = exports; diff --git a/static/js/pm_list.js b/static/js/pm_list.js index a9eb626d8e..010838bf58 100644 --- a/static/js/pm_list.js +++ b/static/js/pm_list.js @@ -1,5 +1,7 @@ "use strict"; +const pm_conversations = require("./pm_conversations"); + let prior_dom; let private_messages_open = false; diff --git a/static/js/topic_generator.js b/static/js/topic_generator.js index 1f67cf3dba..df1e894eac 100644 --- a/static/js/topic_generator.js +++ b/static/js/topic_generator.js @@ -1,5 +1,7 @@ "use strict"; +const pm_conversations = require("./pm_conversations"); + exports.sub_list_generator = function (lst, lower, upper) { // lower/upper has Python range semantics so if you pass // in lower=5 and upper=8, you get elements 5/6/7 diff --git a/static/js/typeahead_helper.js b/static/js/typeahead_helper.js index 0d9d0b3304..18cba97bb3 100644 --- a/static/js/typeahead_helper.js +++ b/static/js/typeahead_helper.js @@ -8,6 +8,7 @@ const emoji = require("../shared/js/emoji"); const typeahead = require("../shared/js/typeahead"); const render_typeahead_list_item = require("../templates/typeahead_list_item.hbs"); +const pm_conversations = require("./pm_conversations"); const settings_data = require("./settings_data"); const util = require("./util"); diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 9e3a0e8cc4..bf29445072 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -8,6 +8,7 @@ const render_edit_content_button = require("../templates/edit_content_button.hbs const emojisets = require("./emojisets"); const markdown_config = require("./markdown_config"); +const pm_conversations = require("./pm_conversations"); // This is where most of our initialization takes place. // TODO: Organize it a lot better. In particular, move bigger