Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

navbar: Fix navbar for unknown streams.

YashRE4246247623fc27
diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js
index 22bd8468612..140207b2fc2 100644
--- a/frontend_tests/node_tests/filter.js
+++ b/frontend_tests/node_tests/filter.js
@@ -1375,11 +1375,17 @@ run_test('navbar_helpers', () => {
{ operator: 'stream', operand: 'foo' },
{ operator: 'topic', operand: 'bar' },
];
+ // foo stream exists
const stream_operator = [{ operator: 'stream', operand: 'foo'}];
make_private_sub('psub', '22');
const private_stream_operator = [{ operator: 'stream', operand: 'psub'}];
make_web_public_sub('webPublicSub', '12'); // capitalized just to try be tricky and robust.
const web_public_stream_operator = [{ operator: 'stream', operand: 'webPublicSub'}];
+ const non_existent_stream = [{ operator: 'stream', operand: 'Elephant' }];
+ const non_existent_stream_topic = [
+ { operator: 'stream', operand: 'Elephant' },
+ { operator: 'topic', operand: 'pink' },
+ ];
const pm_with = [{ operator: 'pm-with', operand: '[email protected]'}];
const group_pm = [{ operator: 'pm-with', operand: '[email protected],[email protected]'}];
const group_pm_including_missing_person = [{ operator: 'pm-with', operand: '[email protected],[email protected],[email protected]'}];
@@ -1441,6 +1447,20 @@ run_test('navbar_helpers', () => {
title: 'Foo',
redirect_url_with_search: '/#narrow/stream/42-Foo',
},
+ {
+ operator: non_existent_stream,
+ is_common_narrow: true,
+ icon: 'question-circle-o',
+ title: 'translated: Unknown stream',
+ redirect_url_with_search: '#',
+ },
+ {
+ operator: non_existent_stream_topic,
+ is_common_narrow: true,
+ icon: 'question-circle-o',
+ title: 'translated: Unknown stream',
+ redirect_url_with_search: '#',
+ },
{
operator: private_stream_operator,
is_common_narrow: true,
diff --git a/static/js/filter.js b/static/js/filter.js
index b81d0e6c48e..dc2046856ca 100644
--- a/static/js/filter.js
+++ b/static/js/filter.js
@@ -479,6 +479,10 @@ Filter.prototype = {
// this comes first because it has 3 term_types but is not a "complex filter"
if (_.isEqual(term_types, ['stream', 'topic', 'search'])) {
+ // if stream does not exist, redirect to All
+ if (!this._stream_params) {
+ return "#";
+ }
return '/#narrow/stream/' + stream_data.name_to_slug(this.operands('stream')[0]) + '/topic/' + this.operands('topic')[0];
}
@@ -490,6 +494,10 @@ Filter.prototype = {
if (term_types[1] === 'search') {
switch (term_types[0]) {
case 'stream':
+ // if stream does not exist, redirect to All
+ if (!this._stream_params) {
+ return "#";
+ }
return '/#narrow/stream/' + stream_data.name_to_slug(this.operands('stream')[0]);
case 'is-private':
return '/#narrow/is/private';
@@ -541,6 +549,9 @@ Filter.prototype = {
case 'in-all':
return 'home';
case 'stream':
+ if (!this._stream_params) {
+ return 'question-circle-o';
+ }
if (this._stream_params._is_stream_private) {
return 'lock';
}
@@ -564,6 +575,9 @@ Filter.prototype = {
const term_types = this.sorted_term_types();
if (term_types.length === 3 && _.isEqual(term_types, ['stream', 'topic', 'search']) ||
term_types.length === 2 && _.isEqual(term_types, ['stream', 'topic'])) {
+ if (!this._stream_params) {
+ return i18n.t('Unknown stream');
+ }
return this._stream_params._stream_name;
}
if (term_types.length === 1 || term_types.length === 2 && term_types[1] === 'search') {
@@ -575,6 +589,9 @@ Filter.prototype = {
case 'streams-public':
return i18n.t('Public stream messages in organization');
case 'stream':
+ if (!this._stream_params) {
+ return i18n.t('Unknown stream');
+ }
return this._stream_params._stream_name;
case 'is-starred':
return i18n.t('Starred messages');
diff --git a/static/js/tab_bar.js b/static/js/tab_bar.js
index ae7a923cb64..8a0cc36a1ea 100644
--- a/static/js/tab_bar.js
+++ b/static/js/tab_bar.js
@@ -25,30 +25,31 @@ function make_tab_data(filter) {
}
tab_data.title = filter.get_title();
tab_data.icon = filter.get_icon();
+ if (tab_data.icon === 'question-circle-o') {
+ tab_data.sub_count = '0';
+ tab_data.formatted_sub_count = '0';
+ tab_data.rendered_narrow_description = i18n.t("This stream does not exist or is private.");
+ return tab_data;
+ }
if (['hashtag', 'lock', 'globe'].includes(tab_data.icon)) {
const stream = filter.operands("stream")[0];
- const current_stream = stream_data.get_sub_by_name(stream);
- if (current_stream) {
- tab_data.rendered_narrow_description = current_stream.rendered_description;
- tab_data.sub_count = get_sub_count(current_stream);
- tab_data.formatted_sub_count = get_formatted_sub_count(current_stream);
- // the "title" is passed as a variable and doesn't get translated (nor should it)
- tab_data.sub_count_tooltip_text =
- i18n.t("__count__ users are subscribed to #__title__", {count: tab_data.sub_count, title: tab_data.title});
- tab_data.stream_settings_link = "#streams/" + current_stream.stream_id + "/" + current_stream.name;
- } else {
- tab_data.title = i18n.t('Unknown stream');
- tab_data.sub_count = '0';
- tab_data.formatted_sub_count = '0';
- tab_data.rendered_narrow_description = i18n.t("This stream does not exist or is private.");
- }
+ // We can rely on current_stream because if the stream doesn't
+ // exist then the "question-circle-o" case would case early exit.
+ const current_stream = stream_data.get_sub_by_name(stream);
+ tab_data.rendered_narrow_description = current_stream.rendered_description;
+ tab_data.sub_count = get_sub_count(current_stream);
+ tab_data.formatted_sub_count = get_formatted_sub_count(current_stream);
+ // the "title" is passed as a variable and doesn't get translated (nor should it)
+ tab_data.sub_count_tooltip_text =
+ i18n.t("__count__ users are subscribed to #__title__", { count: tab_data.sub_count, title: tab_data.title });
+ tab_data.stream_settings_link = "#streams/" + current_stream.stream_id + "/" + current_stream.name;
}
return tab_data;
}
exports.colorize_tab_bar = function () {
const filter = narrow_state.filter();
- if (filter === undefined || !filter.has_operator('stream')) {return;}
+ if (filter === undefined || !filter.has_operator('stream') || !filter._stream_params) {return;}
const color_for_stream = stream_data.get_color(filter._stream_params._stream_name);
const stream_light = colorspace.getHexColor(colorspace.getDecimalColor(color_for_stream));
$("#tab_list .fa-hashtag").css('color', stream_light);