diff --git a/.eslintrc.json b/.eslintrc.json index 857e1e216d..7b677345bd 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -137,7 +137,6 @@ "UserSearch": false, "activity": false, "admin": false, - "alert_words": false, "alert_words_ui": false, "attachments_ui": false, "avatar": false, diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.js index 5df5fc4be4..7139ffbb2d 100644 --- a/frontend_tests/node_tests/echo.js +++ b/frontend_tests/node_tests/echo.js @@ -37,10 +37,6 @@ set_global("message_store", { update_booleans: () => {}, }); -set_global("alert_words", { - process_message: () => {}, -}); - set_global("home_msg_list", { view: { rerender_messages: (msgs) => { diff --git a/frontend_tests/node_tests/general.js b/frontend_tests/node_tests/general.js index d7430e1ca0..a6e8154618 100644 --- a/frontend_tests/node_tests/general.js +++ b/frontend_tests/node_tests/general.js @@ -114,10 +114,6 @@ const messages = { const noop = () => undefined; -const alert_words = set_global("alert_words", {}); - -alert_words.process_message = noop; - // We can also bring in real code: zrequire("recent_senders"); const unread = zrequire("unread"); diff --git a/frontend_tests/node_tests/message_events.js b/frontend_tests/node_tests/message_events.js index e270ec4026..7ff74b088a 100644 --- a/frontend_tests/node_tests/message_events.js +++ b/frontend_tests/node_tests/message_events.js @@ -16,7 +16,6 @@ const stream_topic_history = zrequire("stream_topic_history"); const unread = zrequire("unread"); set_global("$", make_zjquery()); -const alert_words = set_global("alert_words", {}); set_global("condense", {}); set_global("current_msg_list", {}); set_global("message_edit", {}); @@ -27,8 +26,6 @@ set_global("pm_list", {}); set_global("stream_list", {}); set_global("unread_ui", {}); -alert_words.process_message = () => {}; - const alice = { email: "alice@example.com", user_id: 32, diff --git a/frontend_tests/node_tests/message_store.js b/frontend_tests/node_tests/message_store.js index 4a11bc0476..de381e4667 100644 --- a/frontend_tests/node_tests/message_store.js +++ b/frontend_tests/node_tests/message_store.js @@ -16,10 +16,6 @@ const noop = function () {}; set_global("$", make_zjquery()); set_global("document", "document-stub"); -set_global("alert_words", { - process_message: noop, -}); - set_global("stream_topic_history", { add_message: noop, }); diff --git a/frontend_tests/node_tests/notifications.js b/frontend_tests/node_tests/notifications.js index 44524542f6..eb3ee89f28 100644 --- a/frontend_tests/node_tests/notifications.js +++ b/frontend_tests/node_tests/notifications.js @@ -32,7 +32,6 @@ const _navigator = { }; set_global("navigator", _navigator); -zrequire("alert_words"); const muting = zrequire("muting"); const stream_data = zrequire("stream_data"); zrequire("ui"); diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js index ea477c8ba8..f7a57e7629 100644 --- a/frontend_tests/node_tests/ui_init.js +++ b/frontend_tests/node_tests/ui_init.js @@ -81,7 +81,6 @@ util.is_mobile = () => false; stub_templates(() => "some-html"); ui.get_scroll_element = (element) => element; -zrequire("alert_words"); zrequire("hash_util"); zrequire("colorspace"); zrequire("stream_color"); diff --git a/static/js/alert_words.js b/static/js/alert_words.js index ce2941af7a..4c0a8bfe49 100644 --- a/static/js/alert_words.js +++ b/static/js/alert_words.js @@ -1,31 +1,29 @@ -"use strict"; +import _ from "lodash"; -const _ = require("lodash"); - -const people = require("./people"); +import * as people from "./people"; // For simplicity, we use a list for our internal // data, since that matches what the server sends us. let my_alert_words = []; -exports.set_words = function (words) { +export function set_words(words) { my_alert_words = words; -}; +} -exports.get_word_list = function () { +export function get_word_list() { // People usually only have a couple alert // words, so it's cheap to be defensive // here and give a copy of the list to // our caller (in case they want to sort it // or something). return [...my_alert_words]; -}; +} -exports.has_alert_word = function (word) { +export function has_alert_word(word) { return my_alert_words.includes(word); -}; +} -exports.process_message = function (message) { +export function process_message(message) { // Parsing for alert words is expensive, so we rely on the host // to tell us there any alert words to even look for. if (!message.alerted) { @@ -57,18 +55,16 @@ exports.process_message = function (message) { }, ); } -}; +} -exports.notifies = function (message) { +export function notifies(message) { // We exclude ourselves from notifications when we type one of our own // alert words into a message, just because that can be annoying for // certain types of workflows where everybody on your team, including // yourself, sets up an alert word to effectively mention the team. return !people.is_current_user(message.sender_email) && message.alerted; -}; +} -exports.initialize = (params) => { +export const initialize = (params) => { my_alert_words = params.alert_words; }; - -window.alert_words = exports; diff --git a/static/js/alert_words_ui.js b/static/js/alert_words_ui.js index 23dc973557..7e2c805b1b 100644 --- a/static/js/alert_words_ui.js +++ b/static/js/alert_words_ui.js @@ -2,6 +2,8 @@ const render_alert_word_settings_item = require("../templates/settings/alert_word_settings_item.hbs"); +const alert_words = require("./alert_words"); + exports.render_alert_words_ui = function () { const words = alert_words.get_word_list(); words.sort(); diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js index 9e6177791a..9e1317e70f 100644 --- a/static/js/bundles/app.js +++ b/static/js/bundles/app.js @@ -103,7 +103,6 @@ import "../hash_util"; import "../hashchange"; import "../message_flags"; import "../starred_messages"; -import "../alert_words"; import "../alert_words_ui"; import "../attachments_ui"; import "../message_store"; diff --git a/static/js/echo.js b/static/js/echo.js index 6f61103687..a26a863218 100644 --- a/static/js/echo.js +++ b/static/js/echo.js @@ -1,3 +1,4 @@ +import * as alert_words from "./alert_words"; import * as people from "./people"; import * as util from "./util"; diff --git a/static/js/global.d.ts b/static/js/global.d.ts index 38a3e4b776..72e22904e7 100644 --- a/static/js/global.d.ts +++ b/static/js/global.d.ts @@ -11,7 +11,6 @@ declare let MessageListView: any; declare let UserSearch: any; declare let activity: any; declare let admin: any; -declare let alert_words: any; declare let alert_words_ui: any; declare let attachments_ui: any; declare let avatar: any; diff --git a/static/js/message_events.js b/static/js/message_events.js index 07c12246a0..501823b8b1 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -1,5 +1,6 @@ "use strict"; +const alert_words = require("./alert_words"); const huddle_data = require("./huddle_data"); const message_edit_history = require("./message_edit_history"); const util = require("./util"); diff --git a/static/js/message_store.js b/static/js/message_store.js index a36827bf81..211404ec9b 100644 --- a/static/js/message_store.js +++ b/static/js/message_store.js @@ -1,5 +1,6 @@ "use strict"; +const alert_words = require("./alert_words"); const people = require("./people"); const pm_conversations = require("./pm_conversations"); const util = require("./util"); diff --git a/static/js/notifications.js b/static/js/notifications.js index d1265078bd..0d6074998c 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -5,6 +5,7 @@ const _ = require("lodash"); const render_compose_notification = require("../templates/compose_notification.hbs"); const render_notification = require("../templates/notification.hbs"); +const alert_words = require("./alert_words"); const favicon = require("./favicon"); const people = require("./people"); const settings_config = require("./settings_config"); diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index 9ba673ffa0..97ad5bd143 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -2,6 +2,7 @@ const emoji = require("../shared/js/emoji"); +const alert_words = require("./alert_words"); const peer_data = require("./peer_data"); const people = require("./people"); const settings_config = require("./settings_config"); diff --git a/static/js/ui_init.js b/static/js/ui_init.js index 759389c1f4..5e1b7b7d2e 100644 --- a/static/js/ui_init.js +++ b/static/js/ui_init.js @@ -8,6 +8,7 @@ const emoji = require("../shared/js/emoji"); const fenced_code = require("../shared/js/fenced_code"); const render_edit_content_button = require("../templates/edit_content_button.hbs"); +const alert_words = require("./alert_words"); const copy_and_paste = require("./copy_and_paste"); const echo = require("./echo"); const emojisets = require("./emojisets");