From 28107eb91384c769214db37f7cbd9dc57b2c83bc Mon Sep 17 00:00:00 2001 From: evykassirer Date: Tue, 28 May 2024 13:22:15 -0700 Subject: [PATCH] message_helper: Be more explicit about converting subject to topic. --- tools/linter_lib/custom_check.py | 1 + web/src/message_helper.js | 5 ++++- web/src/util.ts | 6 ------ web/tests/example2.test.js | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index fa29914feb..61d3510977 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -124,6 +124,7 @@ js_rules = RuleList( "web/src/message_store.ts", "web/src/types.ts", "web/src/util.ts", + "web/src/message_helper.ts", "web/tests/", }, "exclude_pattern": "emails", diff --git a/web/src/message_helper.js b/web/src/message_helper.js index 92ef4faa6b..6a38cef671 100644 --- a/web/src/message_helper.js +++ b/web/src/message_helper.js @@ -38,7 +38,10 @@ export function process_new_message(message) { switch (message.type) { case "stream": - util.convert_message_topic(message); + if (message.topic === undefined) { + message.topic = message.subject; + } + delete message.subject; message.is_stream = true; message.reply_to = message.sender_email; diff --git a/web/src/util.ts b/web/src/util.ts index 044e3d10f9..58f5454eda 100644 --- a/web/src/util.ts +++ b/web/src/util.ts @@ -269,12 +269,6 @@ export function is_topic_synonym(operator: string): boolean { return operator === "subject"; } -export function convert_message_topic(message: Message): void { - if (message.type === "stream" && message.topic === undefined) { - message.topic = message.subject; - } -} - // TODO: When "stream" is renamed to "channel", update these stream // synonym helper functions for the reverse logic. export function is_stream_synonym(text: string): boolean { diff --git a/web/tests/example2.test.js b/web/tests/example2.test.js index 4bfa7daed1..be41ae5501 100644 --- a/web/tests/example2.test.js +++ b/web/tests/example2.test.js @@ -42,7 +42,7 @@ const messages = { stream_id: denmark_stream.stream_id, type: "stream", flags: ["has_alert_word"], - topic: "copenhagen", + subject: "copenhagen", // note we don't have every field that a "real" message // would have, and that can be fine }, @@ -91,7 +91,7 @@ run_test("unread", () => { assert.equal(unread.num_unread_for_topic(stream_id, topic_name), 0); let in_message = {...messages.isaac_to_denmark_stream}; - in_message = message_store.set_message_booleans(in_message); + in_message = message_helper.process_new_message(in_message); unread.process_loaded_messages([in_message]); assert.equal(unread.num_unread_for_topic(stream_id, topic_name), 1);