message_fetch: Fix load_messages called unexpectedly.

Since we set a new timeout on every connection error, we can
unconditionally clear the timeout when load_messages is called.

This fixes the error when `load_messages` is called irrespective
of `delay_secs` timer.
This commit is contained in:
Aman Agrawal
2025-03-18 12:18:06 +05:30
committed by Tim Abbott
parent e5f4ba92f1
commit 37d91d9759

View File

@@ -394,25 +394,22 @@ export function load_messages(opts: MessageFetchOptions, attempt = 1): void {
});
}
if (load_messages_timeout !== undefined) {
clearTimeout(load_messages_timeout);
}
void channel.get({
url: "/json/messages",
data,
success(raw_data) {
if (load_messages_timeout !== undefined) {
clearTimeout(load_messages_timeout);
}
popup_banners.close_connection_error_popup_banner("message_fetch");
const data = response_schema.parse(raw_data);
get_messages_success(data, opts);
},
error(xhr) {
if (xhr.status === 400) {
// We successfully reached the server, so hide the
// connection error notice, even if the request failed
// for other reasons.
if (load_messages_timeout !== undefined) {
clearTimeout(load_messages_timeout);
}
// Even though the request failed, we did reach the
// server, and can hide the connection error notice.
popup_banners.close_connection_error_popup_banner("message_fetch");
}