message_edit: Fix edit last msg hotkey unintentionally marks msgs read.

Fixes #17737

If you write a message in a narrowed view, then go back to an unnarrowed
view, there may now be many unread messages between your new current
position and the message you just wrote. If you then accidentally press
`←`, all of those messages will be marked read unexpectedly, causing you
to lose your place while catching up.

So, we disable the hotkey in this scenario to fix this bug.
This commit is contained in:
Aman Agrawal 2024-11-17 10:10:12 +05:30 committed by Tim Abbott
parent dd58698c02
commit 98265fd149
1 changed files with 12 additions and 0 deletions

View File

@ -1272,6 +1272,18 @@ export function edit_last_sent_message(): void {
return;
}
const current_selected_msg = message_store.get(message_lists.current.selected_id());
if (current_selected_msg && current_selected_msg.id < last_sent_msg.id) {
// If there are any unread messages between the selected message and the
// message we want to edit, we don't edit the last sent message to avoid
// marking messages as read unintentionally.
for (const msg of message_lists.current.all_messages()) {
if (current_selected_msg.id < msg.id && msg.id < last_sent_msg.id && msg.unread) {
return;
}
}
}
message_lists.current.select_id(last_sent_msg.id, {then_scroll: true});
const $msg_row = message_lists.current.get_row(last_sent_msg.id);