diff --git a/.eslintrc.json b/.eslintrc.json index 053d440a2c..72a0ccdaf1 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 f4cacfa7df..7d74fe5b52 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 4c1e6d9697..8110a69193 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 776086beaa..9c9643c8a8 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 d6fb27c151..c6d504f383 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 9e1f9e6681..464b53ced4 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 d857c4c788..122b690549 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 a72f958ad2..a18a33b5d2 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 e61258225c..55b56a311d 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");