message_helper: Be more explicit about converting subject to topic.

This commit is contained in:
evykassirer
2024-05-28 13:22:15 -07:00
committed by Tim Abbott
parent 297d393539
commit 28107eb913
4 changed files with 7 additions and 9 deletions

View File

@@ -124,6 +124,7 @@ js_rules = RuleList(
"web/src/message_store.ts", "web/src/message_store.ts",
"web/src/types.ts", "web/src/types.ts",
"web/src/util.ts", "web/src/util.ts",
"web/src/message_helper.ts",
"web/tests/", "web/tests/",
}, },
"exclude_pattern": "emails", "exclude_pattern": "emails",

View File

@@ -38,7 +38,10 @@ export function process_new_message(message) {
switch (message.type) { switch (message.type) {
case "stream": case "stream":
util.convert_message_topic(message); if (message.topic === undefined) {
message.topic = message.subject;
}
delete message.subject;
message.is_stream = true; message.is_stream = true;
message.reply_to = message.sender_email; message.reply_to = message.sender_email;

View File

@@ -269,12 +269,6 @@ export function is_topic_synonym(operator: string): boolean {
return operator === "subject"; 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 // TODO: When "stream" is renamed to "channel", update these stream
// synonym helper functions for the reverse logic. // synonym helper functions for the reverse logic.
export function is_stream_synonym(text: string): boolean { export function is_stream_synonym(text: string): boolean {

View File

@@ -42,7 +42,7 @@ const messages = {
stream_id: denmark_stream.stream_id, stream_id: denmark_stream.stream_id,
type: "stream", type: "stream",
flags: ["has_alert_word"], flags: ["has_alert_word"],
topic: "copenhagen", subject: "copenhagen",
// note we don't have every field that a "real" message // note we don't have every field that a "real" message
// would have, and that can be fine // 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); assert.equal(unread.num_unread_for_topic(stream_id, topic_name), 0);
let in_message = {...messages.isaac_to_denmark_stream}; 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]); unread.process_loaded_messages([in_message]);
assert.equal(unread.num_unread_for_topic(stream_id, topic_name), 1); assert.equal(unread.num_unread_for_topic(stream_id, topic_name), 1);