Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

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

Anders Kaseorg636587665b28
diff --git a/.eslintrc.json b/.eslintrc.json
index 053d440a2c0..72a0ccdaf14 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -187,7 +187,6 @@
"settings_streams": false,
"settings_user_groups": false,
"settings_users": false,
- "starred_messages": false,
"stream_list": false,
"StripeCheckout": false,
"subs": false,
diff --git a/frontend_tests/node_tests/message_flags.js b/frontend_tests/node_tests/message_flags.js
index f4cacfa7df7..7d74fe5b528 100644
--- a/frontend_tests/node_tests/message_flags.js
+++ b/frontend_tests/node_tests/message_flags.js
@@ -7,7 +7,7 @@ const rewiremock = require("rewiremock/node");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
-set_global("starred_messages", {
+rewiremock("../../static/js/starred_messages").with({
add: () => {},
remove: () => {},
});
diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js
index 4c1e6d9697b..8110a691936 100644
--- a/frontend_tests/node_tests/ui_init.js
+++ b/frontend_tests/node_tests/ui_init.js
@@ -119,7 +119,6 @@ const compose = zrequire("compose");
zrequire("composebox_typeahead");
zrequire("narrow");
zrequire("stream_list");
-zrequire("starred_messages");
zrequire("recent_topics");
run_test("initialize_everything", () => {
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 776086beaab..9c9643c8a87 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -30,7 +30,6 @@ import "../ui";
import "../composebox_typeahead";
import "../hotkey";
import "../notifications";
-import "../starred_messages";
import "../alert_words_ui";
import "../attachments_ui";
import "../message_store";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index d6fb27c1510..c6d504f3831 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -59,7 +59,6 @@ declare let settings_sections: any;
declare let settings_streams: any;
declare let settings_user_groups: any;
declare let settings_users: any;
-declare let starred_messages: any;
declare let stream_list: any;
declare let subs: any;
declare let message_view_header: any;
diff --git a/static/js/message_flags.js b/static/js/message_flags.js
index 9e1f9e66816..464b53ced4d 100644
--- a/static/js/message_flags.js
+++ b/static/js/message_flags.js
@@ -1,6 +1,7 @@
import _ from "lodash";
import * as channel from "./channel";
+import * as starred_messages from "./starred_messages";
function send_flag_update(message, flag, op) {
channel.post({
diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js
index d857c4c7882..122b6905492 100644
--- a/static/js/server_events_dispatch.js
+++ b/static/js/server_events_dispatch.js
@@ -16,6 +16,7 @@ import * as people from "./people";
import * as reload from "./reload";
import * as scroll_bar from "./scroll_bar";
import * as settings_config from "./settings_config";
+import * as starred_messages from "./starred_messages";
import * as stream_data from "./stream_data";
import * as stream_events from "./stream_events";
import * as stream_topic_history from "./stream_topic_history";
diff --git a/static/js/starred_messages.js b/static/js/starred_messages.js
index a72f958ad2b..a18a33b5d20 100644
--- a/static/js/starred_messages.js
+++ b/static/js/starred_messages.js
@@ -1,45 +1,43 @@
-"use strict";
+import * as top_left_corner from "./top_left_corner";
-const top_left_corner = require("./top_left_corner");
+export const starred_ids = new Set();
-exports.starred_ids = new Set();
-
-exports.initialize = function () {
- exports.starred_ids.clear();
+export function initialize() {
+ starred_ids.clear();
for (const id of page_params.starred_messages) {
- exports.starred_ids.add(id);
+ starred_ids.add(id);
}
- exports.rerender_ui();
-};
+ rerender_ui();
+}
-exports.add = function (ids) {
+export function add(ids) {
for (const id of ids) {
- exports.starred_ids.add(id);
+ starred_ids.add(id);
}
- exports.rerender_ui();
-};
+ rerender_ui();
+}
-exports.remove = function (ids) {
+export function remove(ids) {
for (const id of ids) {
- exports.starred_ids.delete(id);
+ starred_ids.delete(id);
}
- exports.rerender_ui();
-};
+ rerender_ui();
+}
-exports.get_count = function () {
- return exports.starred_ids.size;
-};
+export function get_count() {
+ return starred_ids.size;
+}
-exports.get_starred_msg_ids = function () {
- return Array.from(exports.starred_ids);
-};
+export function get_starred_msg_ids() {
+ return Array.from(starred_ids);
+}
-exports.rerender_ui = function () {
- let count = exports.get_count();
+export function rerender_ui() {
+ let count = get_count();
if (!page_params.starred_message_counts) {
// This essentially hides the count
@@ -47,6 +45,4 @@ exports.rerender_ui = function () {
}
top_left_corner.update_starred_count(count);
-};
-
-window.starred_messages = exports;
+}
diff --git a/static/js/ui_init.js b/static/js/ui_init.js
index e61258225cb..55b56a311d1 100644
--- a/static/js/ui_init.js
+++ b/static/js/ui_init.js
@@ -42,6 +42,7 @@ const sent_messages = require("./sent_messages");
const settings_panel_menu = require("./settings_panel_menu");
const settings_toggle = require("./settings_toggle");
const spoilers = require("./spoilers");
+const starred_messages = require("./starred_messages");
const stream_color = require("./stream_color");
const stream_data = require("./stream_data");
const stream_edit = require("./stream_edit");