Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
alert_words: Extract highlighting logic from `process_message`.
Amit Patil6d30c38601f0
diff --git a/web/src/alert_words.ts b/web/src/alert_words.tsindex ff52e57c040..77145e37db8 100644--- a/web/src/alert_words.ts+++ b/web/src/alert_words.ts@@ -41,12 +41,8 @@ const alert_regex_replacements = new Map<string, string>([["'", "(?:'|')"],]);-export function process_message(message: Message): void {- // 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) {- return;- }+export function highlight_alert_words(content: string): string {+ let updated_content = content;for (const word of my_alert_words) {const clean = _.escapeRegExp(word).replaceAll(@@ -57,7 +53,7 @@ export function process_message(message: Message): void {const after_punctuation = "(?=\\s)|$|<|[\\)\\\"\\?!:.,';\\]!]";const regex = new RegExp(`(${before_punctuation})(${clean})(${after_punctuation})`, "ig");- const updated_content = message.content.replace(+ updated_content = updated_content.replace(regex,(match: string,@@ -82,8 +78,20 @@ export function process_message(message: Message): void {return before + "<span class='alert-word'>" + word + "</span>" + after;},);- message_store.update_message_content(message, updated_content);}++ return updated_content;+}++export function process_message(message: Message): void {+ // Parsing for alert words is expensive, so we rely on the host+ // to tell us if there are any alert words to even look for.+ if (!message.alerted) {+ return;+ }++ const updated_content = highlight_alert_words(message.content);+ message_store.update_message_content(message, updated_content);}export function notifies(message: Message): boolean {