mark unread: Use correct value of include_anchor in case of errors.

When the request to mark a thread as unread fails, we should use the
value of include_anchor that was sent in the request, not false.

Modified handle_mark_unread_from_here_error to take an object instead of
parameters.
This commit is contained in:
Kenneth Rodrigues 2024-05-10 23:01:39 +05:30 committed by Tim Abbott
parent 9f8d738252
commit 42a6929f5c
1 changed files with 19 additions and 17 deletions

View File

@ -287,12 +287,13 @@ function do_mark_unread_by_narrow(
} }
}, },
error(xhr) { error(xhr) {
handle_mark_unread_from_here_error( const error_options = {
xhr,
message_id, message_id,
include_anchor,
messages_marked_unread_till_now, messages_marked_unread_till_now,
narrow, narrow,
); };
handle_mark_unread_from_here_error(xhr, error_options);
}, },
}); });
} }
@ -307,7 +308,8 @@ function do_mark_unread_by_ids(message_ids_to_update) {
} }
}, },
error(xhr) { error(xhr) {
handle_mark_unread_from_here_error(xhr, undefined, 0, undefined, message_ids_to_update); const error_options = {message_ids_to_update};
handle_mark_unread_from_here_error(xhr, error_options);
}, },
}); });
} }
@ -332,29 +334,29 @@ function finish_loading(messages_marked_unread_till_now) {
); );
} }
function handle_mark_unread_from_here_error( function handle_mark_unread_from_here_error(xhr, options) {
xhr,
message_id,
messages_marked_unread_till_now,
narrow,
message_ids_to_update = undefined,
) {
if (xhr.readyState === 0) { if (xhr.readyState === 0) {
// client cancelled the request // client cancelled the request
} else if (xhr.responseJSON?.code === "RATE_LIMIT_HIT") { } else if (xhr.responseJSON?.code === "RATE_LIMIT_HIT") {
// If we hit the rate limit, just continue without showing any error. // If we hit the rate limit, just continue without showing any error.
const milliseconds_to_wait = 1000 * xhr.responseJSON["retry-after"]; const milliseconds_to_wait = 1000 * xhr.responseJSON["retry-after"];
if (message_ids_to_update !== undefined) { if (options.message_ids_to_update !== undefined) {
setTimeout(() => { setTimeout(() => {
do_mark_unread_by_ids(message_ids_to_update); do_mark_unread_by_ids(options.message_ids_to_update);
}, milliseconds_to_wait); }, milliseconds_to_wait);
} else { } else {
assert(
options.message_id !== undefined &&
options.narrow !== undefined &&
options.messages_marked_unread_till_now !== undefined &&
options.include_anchor !== undefined,
);
setTimeout(() => { setTimeout(() => {
do_mark_unread_by_narrow( do_mark_unread_by_narrow(
message_id, options.message_id,
false, options.include_anchor,
messages_marked_unread_till_now, options.messages_marked_unread_till_now,
narrow, options.narrow,
); );
}, milliseconds_to_wait); }, milliseconds_to_wait);
} }