mirror of https://github.com/zulip/zulip.git
filter: Eliminate a few "subject" references.
This continues the effort to isolate "subject" references to util calls. Also, we fix a comment. Finally, we use canonicalized operators in a switch statement.
This commit is contained in:
parent
8121d19122
commit
2fdb44803d
|
@ -161,6 +161,7 @@ run_test('canonicalizations', () => {
|
|||
assert.equal(Filter.canonicalize_operator('Is'), 'is');
|
||||
assert.equal(Filter.canonicalize_operator('Stream'), 'stream');
|
||||
assert.equal(Filter.canonicalize_operator('Subject'), 'topic');
|
||||
assert.equal(Filter.canonicalize_operator('FROM'), 'sender');
|
||||
|
||||
var term;
|
||||
term = Filter.canonicalize_term({operator: 'Stream', operand: 'Denmark'});
|
||||
|
|
|
@ -7,6 +7,7 @@ zrequire('MessageListData', 'js/message_list_data');
|
|||
zrequire('unread');
|
||||
zrequire('narrow');
|
||||
zrequire('search_pill');
|
||||
zrequire('util');
|
||||
|
||||
set_global('blueslip', {});
|
||||
set_global('channel', {});
|
||||
|
@ -27,7 +28,6 @@ set_global('tab_bar', {});
|
|||
set_global('top_left_corner', {});
|
||||
set_global('typing_events', {});
|
||||
set_global('ui_util', {});
|
||||
set_global('util', {});
|
||||
set_global('unread_ops', {});
|
||||
set_global('search_pill_widget', {
|
||||
widget: {
|
||||
|
|
|
@ -3,6 +3,7 @@ zrequire('MessageListData', 'js/message_list_data');
|
|||
zrequire('narrow_state');
|
||||
zrequire('narrow');
|
||||
zrequire('stream_data');
|
||||
zrequire('util');
|
||||
|
||||
set_global('message_list', {});
|
||||
set_global('muting', {
|
||||
|
|
|
@ -2,6 +2,7 @@ zrequire('people');
|
|||
zrequire('Filter', 'js/filter');
|
||||
zrequire('stream_data');
|
||||
zrequire('narrow_state');
|
||||
zrequire('util');
|
||||
|
||||
set_global('blueslip', global.make_zblueslip());
|
||||
set_global('page_params', {});
|
||||
|
|
|
@ -3,6 +3,7 @@ set_global('$', global.make_zjquery());
|
|||
zrequire('Filter', 'js/filter');
|
||||
zrequire('unread_ui');
|
||||
zrequire('people');
|
||||
zrequire('util');
|
||||
|
||||
zrequire('top_left_corner');
|
||||
|
||||
|
|
|
@ -154,12 +154,15 @@ function Filter(operators) {
|
|||
}
|
||||
}
|
||||
|
||||
var canonical_operators = {from: "sender", subject: "topic"};
|
||||
|
||||
Filter.canonicalize_operator = function (operator) {
|
||||
operator = operator.toLowerCase();
|
||||
if (canonical_operators.hasOwnProperty(operator)) {
|
||||
return canonical_operators[operator];
|
||||
|
||||
if (operator === 'from') {
|
||||
return 'sender';
|
||||
}
|
||||
|
||||
if (util.is_topic_synonym(operator)) {
|
||||
return 'topic';
|
||||
}
|
||||
return operator;
|
||||
};
|
||||
|
@ -298,7 +301,7 @@ Filter.parse = function (str) {
|
|||
/* Convert a list of operators to a string.
|
||||
Each operator is a key-value pair like
|
||||
|
||||
['subject', 'my amazing subject']
|
||||
['topic', 'my amazing topic']
|
||||
|
||||
These are not keys in a JavaScript object, because we
|
||||
might need to support multiple operators of the same type.
|
||||
|
@ -575,6 +578,8 @@ Filter.sorted_term_types = function (term_types) {
|
|||
Filter.operator_to_prefix = function (operator, negated) {
|
||||
var verb;
|
||||
|
||||
operator = Filter.canonicalize_operator(operator);
|
||||
|
||||
if (operator === 'search') {
|
||||
return negated ? 'exclude' : 'search for';
|
||||
}
|
||||
|
@ -595,11 +600,9 @@ Filter.operator_to_prefix = function (operator, negated) {
|
|||
case 'id':
|
||||
return verb + 'message ID';
|
||||
|
||||
case 'subject':
|
||||
case 'topic':
|
||||
return verb + 'topic';
|
||||
|
||||
case 'from':
|
||||
case 'sender':
|
||||
return verb + 'sent by';
|
||||
|
||||
|
|
|
@ -311,6 +311,10 @@ exports.get_topic = function (obj) {
|
|||
return obj.subject;
|
||||
};
|
||||
|
||||
exports.is_topic_synonym = function (operator) {
|
||||
return operator === 'subject';
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
||||
}());
|
||||
|
|
Loading…
Reference in New Issue