Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

echo: Clean up confusing handling of message flags in local echo.

Tim Abbott2dd0b386fed6
diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.js
index fb024c9373a..7ca02698a8e 100644
--- a/frontend_tests/node_tests/echo.js
+++ b/frontend_tests/node_tests/echo.js
@@ -29,6 +29,8 @@ const message_store = mock_esm("../../static/js/message_store", {
get: () => ({failed_request: true}),
update_booleans: () => {},
+
+ set_message_booleans: () => {},
});
mock_esm("../../static/js/message_list");
diff --git a/static/js/echo.js b/static/js/echo.js
index 3d2a8293fb8..76464fa67e7 100644
--- a/static/js/echo.js
+++ b/static/js/echo.js
@@ -173,15 +173,30 @@ export function insert_local_message(message_request, local_id_float) {
// Keep this in sync with changes to compose.create_message_object
const message = {...message_request};
- // Locally delivered messages cannot be unread (since we sent them), nor
- // can they alert the user.
- message.unread = false;
-
message.raw_content = message.content;
// NOTE: This will parse synchronously. We're not using the async pipeline
markdown.apply_markdown(message);
+ // TODO: markdown.apply_markdown has a messy interface around
+ // message flags. It mutates the message to set all the message
+ // booleans to false via message_store.init_booleans, and then
+ // proceeds to mutate primarily the mentioned flag during
+ // rendering in a messy way.
+ //
+ // We should clean that up to instead just mutate the flags list
+ // on the message, to match how the Zulip API returns this
+ // information via flags. For now, we translate back to the flags
+ // namespace here, and then message_store.set_message_booleans
+ // will get us to the correct final flags.
+ //
+ // Locally delivered messages cannot be unread (since we sent
+ // them), nor can they alert the user.
+ message.flags = ["read"];
+ if (message.mentioned) {
+ message.flags.push("mentioned");
+ }
+
message.content_type = "text/html";
message.sender_email = people.my_current_email();
message.sender_full_name = people.my_full_name();
@@ -196,6 +211,8 @@ export function insert_local_message(message_request, local_id_float) {
waiting_for_ack.set(message.local_id, message);
message.display_recipient = build_display_recipient(message);
+
+ message_store.set_message_booleans(message);
insert_message(message);
return message;
}