message_list_hover: Fix glitch when hovering over a message.

If we hover over a message, we see the message move button
(provided the settings allow so). But if the move deadline is
passed while we're hovering, we still see the move button,
when it should be hidden.

This commit fixes this by updating the move button
visibility when the move deadline is passed.

Fixes #15810.
This commit is contained in:
Kislay Verma
2025-07-13 10:47:11 +05:30
committed by Tim Abbott
parent 14a115224a
commit a21afe2d60
2 changed files with 27 additions and 0 deletions

View File

@@ -310,6 +310,15 @@ export function can_move_message(message: Message): boolean {
return is_topic_editable(message) || is_stream_editable(message);
}
export function remaining_message_move_time(message: Message): number {
if (!can_move_message(message)) {
return 0;
}
const limit_seconds = realm.realm_move_messages_within_stream_limit_seconds ?? Infinity;
return limit_seconds + (message.timestamp - Date.now() / 1000);
}
export function stream_and_topic_exist_in_edit_history(
message: Message,
stream_id: number,

View File

@@ -10,6 +10,7 @@ import {user_settings} from "./user_settings.ts";
let $current_message_hover: JQuery | undefined;
let edit_timeout: ReturnType<typeof setTimeout> | undefined;
let move_timeout: ReturnType<typeof setTimeout> | undefined;
export function message_unhover(): void {
if ($current_message_hover === undefined) {
return;
@@ -18,6 +19,10 @@ export function message_unhover(): void {
clearTimeout(edit_timeout);
edit_timeout = undefined;
}
if (move_timeout !== undefined) {
clearTimeout(move_timeout);
move_timeout = undefined;
}
$current_message_hover.removeClass("can-edit-content can-move-message");
$current_message_hover = undefined;
}
@@ -78,6 +83,19 @@ function change_edit_content_button($message_row: JQuery, message: Message): voi
}, remaining_edit_time);
}
}
if (move_timeout === undefined) {
const remaining_move_time = message_edit.remaining_message_move_time(message) * 1000;
if (remaining_move_time > 0 && remaining_move_time < Infinity) {
move_timeout = setTimeout(() => {
const visible = $.contains(document.body, $edit_content[0]!);
if (!visible) {
return;
}
change_edit_content_button($message_row, message);
}, remaining_move_time);
}
}
}
export function initialize(): void {