mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	Use people.get_all_persons() for search_suggestion.js.
This is better than using page_params.people_list, which may go out of sync when live updates happen.
This commit is contained in:
		@@ -5,18 +5,24 @@
 | 
			
		||||
// clean up after themselves, and they should explicitly stub all
 | 
			
		||||
// dependencies.
 | 
			
		||||
 | 
			
		||||
global.stub_out_jquery();
 | 
			
		||||
 | 
			
		||||
add_dependencies({
 | 
			
		||||
    util: 'js/util.js',
 | 
			
		||||
    Handlebars: 'handlebars',
 | 
			
		||||
    Filter: 'js/filter.js',
 | 
			
		||||
    typeahead_helper: 'js/typeahead_helper.js',
 | 
			
		||||
    people: 'js/people.js',
 | 
			
		||||
    stream_data: 'js/stream_data.js',
 | 
			
		||||
    narrow: 'js/narrow.js'
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
var people = global.people;
 | 
			
		||||
 | 
			
		||||
var search = require('js/search_suggestion.js');
 | 
			
		||||
 | 
			
		||||
set_global('page_params', {
 | 
			
		||||
    people_list: [], // TODO: should not need eventually
 | 
			
		||||
    email: 'bob@zulip.com'
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@@ -74,16 +80,21 @@ global.stream_data.populate_stream_topics_for_tests({});
 | 
			
		||||
        return undefined;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    global.page_params.people_list = [
 | 
			
		||||
    var ted =
 | 
			
		||||
    {
 | 
			
		||||
        email: 'ted@zulip.com',
 | 
			
		||||
        user_id: 101,
 | 
			
		||||
        full_name: 'Ted Smith'
 | 
			
		||||
        },
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    var alice =
 | 
			
		||||
    {
 | 
			
		||||
        email: 'alice@zulip.com',
 | 
			
		||||
        full_name: 'Alice Ignore'
 | 
			
		||||
        }
 | 
			
		||||
    ];
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    people.add(ted);
 | 
			
		||||
    people.add(alice);
 | 
			
		||||
 | 
			
		||||
    var query = 'is:private';
 | 
			
		||||
    var suggestions = search.get_suggestions(query);
 | 
			
		||||
@@ -182,7 +193,8 @@ global.stream_data.populate_stream_topics_for_tests({});
 | 
			
		||||
    ];
 | 
			
		||||
    assert.deepEqual(suggestions.strings, expected);
 | 
			
		||||
 | 
			
		||||
    global.page_params.people_list = [];
 | 
			
		||||
    people.remove(ted);
 | 
			
		||||
    people.remove(alice);
 | 
			
		||||
}());
 | 
			
		||||
 | 
			
		||||
(function test_empty_query_suggestions() {
 | 
			
		||||
@@ -349,20 +361,24 @@ global.stream_data.populate_stream_topics_for_tests({});
 | 
			
		||||
        return;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    global.page_params.people_list = [
 | 
			
		||||
        {
 | 
			
		||||
    var ted = {
 | 
			
		||||
        email: 'ted@zulip.com',
 | 
			
		||||
        full_name: 'Ted Smith'
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    var bob = {
 | 
			
		||||
        email: 'bob@zulip.com',
 | 
			
		||||
        full_name: 'Bob Terry'
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    var alice = {
 | 
			
		||||
        email: 'alice@zulip.com',
 | 
			
		||||
        full_name: 'Alice Ignore'
 | 
			
		||||
        }
 | 
			
		||||
    ];
 | 
			
		||||
    };
 | 
			
		||||
    people.add(ted);
 | 
			
		||||
    people.add(bob);
 | 
			
		||||
    people.add(alice);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    global.stream_data.populate_stream_topics_for_tests({
 | 
			
		||||
        office: [
 | 
			
		||||
@@ -400,4 +416,8 @@ global.stream_data.populate_stream_topics_for_tests({});
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    assert.deepEqual(suggestions.strings, expected);
 | 
			
		||||
 | 
			
		||||
    people.remove(ted);
 | 
			
		||||
    people.remove(bob);
 | 
			
		||||
    people.remove(alice);
 | 
			
		||||
}());
 | 
			
		||||
 
 | 
			
		||||
@@ -389,15 +389,15 @@ exports.get_suggestions = function (query) {
 | 
			
		||||
    suggestions = get_stream_suggestions(operators);
 | 
			
		||||
    result = result.concat(suggestions);
 | 
			
		||||
 | 
			
		||||
    var people = page_params.people_list;
 | 
			
		||||
    var persons = people.get_all_persons();
 | 
			
		||||
 | 
			
		||||
    suggestions = get_person_suggestions(people, query, 'pm-with');
 | 
			
		||||
    suggestions = get_person_suggestions(persons, query, 'pm-with');
 | 
			
		||||
    result = result.concat(suggestions);
 | 
			
		||||
 | 
			
		||||
    suggestions = get_person_suggestions(people, query, 'sender');
 | 
			
		||||
    suggestions = get_person_suggestions(persons, query, 'sender');
 | 
			
		||||
    result = result.concat(suggestions);
 | 
			
		||||
 | 
			
		||||
    suggestions = get_private_suggestions(people, operators, ['pm-with', 'sender']);
 | 
			
		||||
    suggestions = get_private_suggestions(persons, operators, ['pm-with', 'sender']);
 | 
			
		||||
    result = result.concat(suggestions);
 | 
			
		||||
 | 
			
		||||
    suggestions = get_topic_suggestions(operators);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user