Skip to content

Commit

Permalink
narrow_state: Extract cannot compute response.
Browse files Browse the repository at this point in the history
  • Loading branch information
amanagr authored and timabbott committed Oct 25, 2024
1 parent 88082bc commit 1de1570
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions web/src/narrow_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,31 +197,26 @@ export function pm_emails_string(
export function get_first_unread_info(
current_filter: Filter | undefined = filter(),
): {flavor: "cannot_compute" | "not_found"} | {flavor: "found"; msg_id: number} {
const cannot_compute_response: {flavor: "cannot_compute"} = {flavor: "cannot_compute"};
if (current_filter === undefined) {
// we don't yet support the all-messages view
blueslip.error("unexpected call to get_first_unread_info");
return {
flavor: "cannot_compute",
};
return cannot_compute_response;
}

if (!current_filter.can_apply_locally()) {
// For things like search queries, where the server has info
// that the client isn't privy to, we need to wait for the
// server to give us a definitive list of messages before
// deciding where we'll move the selection.
return {
flavor: "cannot_compute",
};
return cannot_compute_response;
}

const unread_ids = _possible_unread_message_ids(current_filter);

if (unread_ids === undefined) {
// _possible_unread_message_ids() only works for certain narrows
return {
flavor: "cannot_compute",
};
return cannot_compute_response;
}

const msg_id = current_filter.first_valid_id_from(unread_ids);
Expand Down

0 comments on commit 1de1570

Please sign in to comment.