From 017bca56e494b7d0e09174c1f4343d7df35f3a12 Mon Sep 17 00:00:00 2001
From: evykassirer
Date: Wed, 21 Aug 2024 16:40:27 -0700
Subject: [PATCH] message_list_view: Refactor me message calculation for
typescript.
We're going to need to be able to build the message list view
in pieces and put it all together in the end, instead of assigning
values directly to a half-formed object (which is hard to type).
This is part of the work towards that.
---
docs/subsystems/widgets.md | 2 +-
web/src/message_list_view.js | 26 ++++++++++++++++----------
web/tests/message_list_view.test.js | 10 ++++++++--
3 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/docs/subsystems/widgets.md b/docs/subsystems/widgets.md
index 1cae85a855..610ad17247 100644
--- a/docs/subsystems/widgets.md
+++ b/docs/subsystems/widgets.md
@@ -23,7 +23,7 @@ These are the least complex. We use our markdown processors to
detect if a message is a `/me` message, plumb the flag through
the message object (as `is_me_message`) and have the clients
format it correctly. Related code (for the web app) lies in
-`message_list_view.js` in `_maybe_format_me_message`.
+`message_list_view.js` in `_maybe_get_me_message`.
## Polls, todo lists, and games
diff --git a/web/src/message_list_view.js b/web/src/message_list_view.js
index bf94dc5705..e4ea320518 100644
--- a/web/src/message_list_view.js
+++ b/web/src/message_list_view.js
@@ -527,7 +527,10 @@ export class MessageListView {
);
}
- this._maybe_format_me_message(message_container);
+ Object.assign(
+ message_container,
+ this._maybe_get_me_message(message_container.is_hidden, message_container.msg),
+ );
// Once all other variables are updated
this._add_msg_edited_vars(message_container);
}
@@ -1656,22 +1659,25 @@ export class MessageListView {
}
}
- _maybe_format_me_message(message_container) {
+ _maybe_get_me_message(is_hidden, message) {
// If the message is to be hidden anyway, no need to render
// it differently.
- if (!message_container.is_hidden && message_container.msg.is_me_message) {
+ if (!is_hidden && message.is_me_message) {
// Slice the '/me ' off the front, and '
' off the first line
// 'p' tag is sliced off to get sender in the same line as the
// first line of the message
- const msg_content = message_container.msg.content;
+ const msg_content = message.content;
const p_index = msg_content.indexOf("
");
- message_container.status_message =
- msg_content.slice("/me ".length, p_index) +
- msg_content.slice(p_index + "
".length);
- message_container.include_sender = true;
- } else {
- message_container.status_message = false;
+ return {
+ status_message:
+ msg_content.slice("/me ".length, p_index) +
+ msg_content.slice(p_index + "
".length),
+ include_sender: true,
+ };
}
+ return {
+ status_message: false,
+ };
}
/* This function exist for two purposes:
diff --git a/web/tests/message_list_view.test.js b/web/tests/message_list_view.test.js
index e23c3891cc..962258a35b 100644
--- a/web/tests/message_list_view.test.js
+++ b/web/tests/message_list_view.test.js
@@ -168,7 +168,10 @@ test("msg_moved_var", () => {
const list = build_list([message_group]);
for (const message_container of messages) {
- list._maybe_format_me_message(message_container);
+ Object.assign(
+ message_container,
+ list._maybe_get_me_message(message_container.is_hidden, message_container.msg),
+ );
list._add_msg_edited_vars(message_container);
}
@@ -277,7 +280,10 @@ test("msg_edited_vars", () => {
const list = build_list([message_group]);
for (const message_container of messages) {
- list._maybe_format_me_message(message_container);
+ Object.assign(
+ message_container,
+ list._maybe_get_me_message(message_container.is_hidden, message_container.msg),
+ );
list._add_msg_edited_vars(message_container);
}