message_lists: Set current to be undefined for non message view.

This commit is contained in:
Aman Agrawal
2024-02-05 18:03:29 +00:00
committed by Tim Abbott
parent 4ccf64b02b
commit f630272b4c
42 changed files with 194 additions and 56 deletions

View File

@@ -1,5 +1,6 @@
import ClipboardJS from "clipboard";
import $ from "jquery";
import assert from "minimalistic-assert";
import * as resolved_topic from "../shared/src/resolved_topic";
import render_wildcard_mention_not_allowed_error from "../templates/compose_banner/wildcard_mention_not_allowed_error.hbs";
@@ -429,13 +430,13 @@ function create_copy_to_clipboard_handler($row, source, message_id) {
}
function edit_message($row, raw_content) {
assert(message_lists.current !== undefined);
const message = message_lists.current.get(rows.id($row));
$row.find(".message_reactions").hide();
condense.hide_message_expander($row);
condense.hide_message_condenser($row);
const content_top = $row.find(".message_controls")[0].getBoundingClientRect().top;
const message = message_lists.current.get(rows.id($row));
// We potentially got to this function by clicking a button that implied the
// user would be able to edit their message. Give a little bit of buffer in
// case the button has been around for a bit, e.g. we show the
@@ -584,6 +585,7 @@ function start_edit_with_content($row, content, edit_box_open_callback) {
}
export function start($row, edit_box_open_callback) {
assert(message_lists.current !== undefined);
const message = message_lists.current.get(rows.id($row));
if (message === undefined) {
blueslip.error("Couldn't find message ID for edit", {row_id: rows.id($row)});
@@ -758,6 +760,7 @@ export function toggle_resolve_topic(
}
export function start_inline_topic_edit($recipient_row) {
assert(message_lists.current !== undefined);
const $form = $(
render_topic_edit_form({
max_topic_length: realm.max_topic_length,
@@ -787,10 +790,12 @@ export function is_editing(id) {
}
export function end_inline_topic_edit($row) {
assert(message_lists.current !== undefined);
message_lists.current.hide_edit_topic_on_recipient_row($row);
}
export function end_message_row_edit($row) {
assert(message_lists.current !== undefined);
const row_id = rows.id($row);
// Clean up the upload handler
@@ -833,8 +838,8 @@ export function end_message_row_edit($row) {
}
export function end_message_edit(message_id) {
const $row = message_lists.current.get_row(message_id);
if ($row.length > 0) {
const $row = message_lists.current?.get_row(message_id);
if (message_lists.current !== undefined && $row.length > 0) {
end_message_row_edit($row);
} else if (currently_editing_messages.has(message_id)) {
// We should delete the message_id from currently_editing_messages
@@ -844,6 +849,7 @@ export function end_message_edit(message_id) {
}
export function try_save_inline_topic_edit($row) {
assert(message_lists.current !== undefined);
const message_id = rows.id_for_recipient_row($row);
const message = message_lists.current.get(message_id);
@@ -944,6 +950,7 @@ export function do_save_inline_topic_edit($row, message, new_topic) {
}
export function save_message_row_edit($row) {
assert(message_lists.current !== undefined);
const $banner_container = compose_banner.get_compose_banner_container(
$row.find(".message_edit_form textarea"),
);
@@ -1118,12 +1125,20 @@ export function save_message_row_edit($row) {
}
export function maybe_show_edit($row, id) {
if (message_lists.current === undefined) {
return;
}
if (currently_editing_messages.has(id)) {
message_lists.current.show_edit_message($row, currently_editing_messages.get(id));
}
}
export function edit_last_sent_message() {
if (message_lists.current === undefined) {
return;
}
const msg = message_lists.current.get_last_message_sent_by_me();
if (!msg) {
@@ -1223,6 +1238,7 @@ export function delete_topic(stream_id, topic_name, failures = 0) {
}
export function handle_narrow_deactivated() {
assert(message_lists.current !== undefined);
for (const [idx, elem] of currently_editing_messages) {
if (message_lists.current.get(idx) !== undefined) {
const $row = message_lists.current.get_row(idx);