mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +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
 | 
					// clean up after themselves, and they should explicitly stub all
 | 
				
			||||||
// dependencies.
 | 
					// dependencies.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					global.stub_out_jquery();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_dependencies({
 | 
					add_dependencies({
 | 
				
			||||||
    util: 'js/util.js',
 | 
					    util: 'js/util.js',
 | 
				
			||||||
    Handlebars: 'handlebars',
 | 
					    Handlebars: 'handlebars',
 | 
				
			||||||
    Filter: 'js/filter.js',
 | 
					    Filter: 'js/filter.js',
 | 
				
			||||||
    typeahead_helper: 'js/typeahead_helper.js',
 | 
					    typeahead_helper: 'js/typeahead_helper.js',
 | 
				
			||||||
 | 
					    people: 'js/people.js',
 | 
				
			||||||
    stream_data: 'js/stream_data.js',
 | 
					    stream_data: 'js/stream_data.js',
 | 
				
			||||||
    narrow: 'js/narrow.js'
 | 
					    narrow: 'js/narrow.js'
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var people = global.people;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var search = require('js/search_suggestion.js');
 | 
					var search = require('js/search_suggestion.js');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set_global('page_params', {
 | 
					set_global('page_params', {
 | 
				
			||||||
 | 
					    people_list: [], // TODO: should not need eventually
 | 
				
			||||||
    email: 'bob@zulip.com'
 | 
					    email: 'bob@zulip.com'
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -74,16 +80,21 @@ global.stream_data.populate_stream_topics_for_tests({});
 | 
				
			|||||||
        return undefined;
 | 
					        return undefined;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    global.page_params.people_list = [
 | 
					    var ted =
 | 
				
			||||||
        {
 | 
					    {
 | 
				
			||||||
            email: 'ted@zulip.com',
 | 
					        email: 'ted@zulip.com',
 | 
				
			||||||
            full_name: 'Ted Smith'
 | 
					        user_id: 101,
 | 
				
			||||||
        },
 | 
					        full_name: 'Ted Smith'
 | 
				
			||||||
        {
 | 
					    };
 | 
				
			||||||
            email: 'alice@zulip.com',
 | 
					
 | 
				
			||||||
            full_name: 'Alice Ignore'
 | 
					    var alice =
 | 
				
			||||||
        }
 | 
					    {
 | 
				
			||||||
    ];
 | 
					        email: 'alice@zulip.com',
 | 
				
			||||||
 | 
					        full_name: 'Alice Ignore'
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    people.add(ted);
 | 
				
			||||||
 | 
					    people.add(alice);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var query = 'is:private';
 | 
					    var query = 'is:private';
 | 
				
			||||||
    var suggestions = search.get_suggestions(query);
 | 
					    var suggestions = search.get_suggestions(query);
 | 
				
			||||||
@@ -182,7 +193,8 @@ global.stream_data.populate_stream_topics_for_tests({});
 | 
				
			|||||||
    ];
 | 
					    ];
 | 
				
			||||||
    assert.deepEqual(suggestions.strings, expected);
 | 
					    assert.deepEqual(suggestions.strings, expected);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    global.page_params.people_list = [];
 | 
					    people.remove(ted);
 | 
				
			||||||
 | 
					    people.remove(alice);
 | 
				
			||||||
}());
 | 
					}());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(function test_empty_query_suggestions() {
 | 
					(function test_empty_query_suggestions() {
 | 
				
			||||||
@@ -349,20 +361,24 @@ global.stream_data.populate_stream_topics_for_tests({});
 | 
				
			|||||||
        return;
 | 
					        return;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    global.page_params.people_list = [
 | 
					    var ted = {
 | 
				
			||||||
        {
 | 
					        email: 'ted@zulip.com',
 | 
				
			||||||
            email: 'ted@zulip.com',
 | 
					        full_name: 'Ted Smith'
 | 
				
			||||||
            full_name: 'Ted Smith'
 | 
					    };
 | 
				
			||||||
        },
 | 
					
 | 
				
			||||||
        {
 | 
					    var bob = {
 | 
				
			||||||
            email: 'bob@zulip.com',
 | 
					        email: 'bob@zulip.com',
 | 
				
			||||||
            full_name: 'Bob Terry'
 | 
					        full_name: 'Bob Terry'
 | 
				
			||||||
        },
 | 
					    };
 | 
				
			||||||
        {
 | 
					
 | 
				
			||||||
            email: 'alice@zulip.com',
 | 
					    var alice = {
 | 
				
			||||||
            full_name: 'Alice Ignore'
 | 
					        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({
 | 
					    global.stream_data.populate_stream_topics_for_tests({
 | 
				
			||||||
        office: [
 | 
					        office: [
 | 
				
			||||||
@@ -400,4 +416,8 @@ global.stream_data.populate_stream_topics_for_tests({});
 | 
				
			|||||||
    ];
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert.deepEqual(suggestions.strings, expected);
 | 
					    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);
 | 
					    suggestions = get_stream_suggestions(operators);
 | 
				
			||||||
    result = result.concat(suggestions);
 | 
					    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);
 | 
					    result = result.concat(suggestions);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    suggestions = get_person_suggestions(people, query, 'sender');
 | 
					    suggestions = get_person_suggestions(persons, query, 'sender');
 | 
				
			||||||
    result = result.concat(suggestions);
 | 
					    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);
 | 
					    result = result.concat(suggestions);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    suggestions = get_topic_suggestions(operators);
 | 
					    suggestions = get_topic_suggestions(operators);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user