mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	js: Convert static/js/alert_words.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							f3af16db3f
						
					
				
				
					commit
					5655e326c9
				
			@@ -137,7 +137,6 @@
 | 
			
		||||
                "UserSearch": false,
 | 
			
		||||
                "activity": false,
 | 
			
		||||
                "admin": false,
 | 
			
		||||
                "alert_words": false,
 | 
			
		||||
                "alert_words_ui": false,
 | 
			
		||||
                "attachments_ui": false,
 | 
			
		||||
                "avatar": false,
 | 
			
		||||
 
 | 
			
		||||
@@ -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) => {
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
 
 | 
			
		||||
@@ -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";
 | 
			
		||||
 
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
import * as alert_words from "./alert_words";
 | 
			
		||||
import * as people from "./people";
 | 
			
		||||
import * as util from "./util";
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user