Avoid blueslip error for empty streams.

We simplify the code for deciding whether
we show a subscribe button or not, and in
doing so avoid a blueslip error where we
were passing `undefined` into `get_sub()`.
This commit is contained in:
Steve Howell
2020-03-20 20:46:52 +00:00
committed by Tim Abbott
parent 304b538b33
commit 778d457bf7

View File

@@ -946,11 +946,23 @@ function pick_empty_narrow_banner() {
} else if (first_operator === "stream" && !stream_data.is_subscribed(first_operand)) {
// You are narrowed to a stream which does not exist or is a private stream
// in which you were never subscribed.
const stream_sub = stream_data.get_sub(narrow_state.stream());
if (!stream_sub || !stream_sub.should_display_subscription_button) {
return $("#nonsubbed_private_nonexistent_stream_narrow_message");
function should_display_subscription_button() {
const stream_name = narrow_state.stream();
if (!stream_name) {
return false;
}
const stream_sub = stream_data.get_sub(first_operand);
return stream_sub && stream_sub.should_display_subscription_button;
}
return $("#nonsubbed_stream_narrow_message");
if (should_display_subscription_button()) {
return $("#nonsubbed_stream_narrow_message");
}
return $("#nonsubbed_private_nonexistent_stream_narrow_message");
} else if (first_operator === "search") {
// You are narrowed to empty search results.
show_search_query();