mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	navbar: Fix navbar for unknown streams.
In commit 35c8dcb599 we introduced the
`_stream_params` object within filter.js but we didn't correctly
handle cases where `_stream param`s is undefined within `get_title()`,
`generate_url()` and `get_icon()`, which cause the navbar to if eg a
guest user tries to access a stream they weren't subscribed to.
This commit fixes this by:
  * Adding the relevant checks
  * Adding node tests that include non-existent streams.
  * Adds the 'question-circle-o' icon for non-existent stream narrows.
A side note here is that "non-existent streams" fall under
"common narrows" as per our current definitions, which doesn't really
make sense but shouldn't bother us.
Fixes: #15387.
			
			
This commit is contained in:
		@@ -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');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user