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:
Steve Howell 2018-12-22 14:32:14 +00:00 committed by Tim Abbott
parent 8121d19122
commit 2fdb44803d
7 changed files with 19 additions and 8 deletions

View File

@ -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'});

View File

@ -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: {

View File

@ -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', {

View File

@ -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', {});

View File

@ -3,6 +3,7 @@ set_global('$', global.make_zjquery());
zrequire('Filter', 'js/filter');
zrequire('unread_ui');
zrequire('people');
zrequire('util');
zrequire('top_left_corner');

View File

@ -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';

View File

@ -311,6 +311,10 @@ exports.get_topic = function (obj) {
return obj.subject;
};
exports.is_topic_synonym = function (operator) {
return operator === 'subject';
};
return exports;
}());