mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 23:19:10 +00:00
Suggest special filters like "All" and "Private messages" in search.
(They will show up for empty queries or queries that are prefixes of either the operator syntax or the label used in the sidebar.) (imported from commit 3765896e3bc1fc95caf987194e22d89d649ba5ae)
This commit is contained in:
@@ -279,6 +279,50 @@ function get_topic_suggestions(query, query_operators) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_special_filter_suggestions(query, operators) {
|
||||||
|
if (operators.length >= 2) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var suggestions = [
|
||||||
|
{
|
||||||
|
search_string: '',
|
||||||
|
description: 'Home'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
search_string: 'in:all',
|
||||||
|
description: 'All messages'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
search_string: 'is:private',
|
||||||
|
description: 'Private messages'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
search_string: 'is:starred',
|
||||||
|
description: 'Starred messages'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
search_string: 'is:mentioned',
|
||||||
|
description: '@-mentions'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
query = query.toLowerCase();
|
||||||
|
|
||||||
|
suggestions = $.grep(suggestions, function (s) {
|
||||||
|
if (s.search_string.toLowerCase() === query) {
|
||||||
|
return false; // redundant
|
||||||
|
}
|
||||||
|
if (query === '') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return (s.search_string.toLowerCase().indexOf(query) === 0) ||
|
||||||
|
(s.description.toLowerCase().indexOf(query) === 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
return suggestions;
|
||||||
|
}
|
||||||
|
|
||||||
exports.initialize = function () {
|
exports.initialize = function () {
|
||||||
$( "#search_query" ).typeahead({
|
$( "#search_query" ).typeahead({
|
||||||
source: function (query, process) {
|
source: function (query, process) {
|
||||||
@@ -291,6 +335,9 @@ exports.initialize = function () {
|
|||||||
suggestion = get_suggestion_based_on_query(query, operators);
|
suggestion = get_suggestion_based_on_query(query, operators);
|
||||||
result = [suggestion];
|
result = [suggestion];
|
||||||
|
|
||||||
|
suggestions = get_special_filter_suggestions(query, operators);
|
||||||
|
result = result.concat(suggestions);
|
||||||
|
|
||||||
suggestions = get_stream_suggestions(query);
|
suggestions = get_stream_suggestions(query);
|
||||||
result = result.concat(suggestions);
|
result = result.concat(suggestions);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user