mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
Add filter.can_bucket_by().
This commit is contained in:
@@ -685,15 +685,20 @@ function make_sub(name, stream_id) {
|
||||
{operator: 'stream', operand: 'My Stream'},
|
||||
];
|
||||
filter = new Filter(terms);
|
||||
assert.equal(filter.can_bucket_by('stream'), true);
|
||||
assert.equal(filter.can_bucket_by('stream', 'topic'), true);
|
||||
assert.equal(filter.is_exactly('stream'), false);
|
||||
assert.equal(filter.is_exactly('stream', 'topic'), true);
|
||||
assert.equal(filter.is_exactly('pm-with'), false);
|
||||
assert.equal(filter.can_bucket_by('pm-with'), false);
|
||||
|
||||
terms = [
|
||||
{operator: 'stream', operand: 'My Stream', negated: true},
|
||||
{operator: 'topic', operand: 'My Topic'},
|
||||
];
|
||||
filter = new Filter(terms);
|
||||
assert.equal(filter.can_bucket_by('stream'), false);
|
||||
assert.equal(filter.can_bucket_by('stream', 'topic'), false);
|
||||
assert.equal(filter.is_exactly('stream'), false);
|
||||
assert.equal(filter.is_exactly('stream', 'topic'), false);
|
||||
assert.equal(filter.is_exactly('pm-with'), false);
|
||||
@@ -737,6 +742,13 @@ function make_sub(name, stream_id) {
|
||||
filter = new Filter(terms);
|
||||
assert.equal(filter.is_exactly('is-mentioned'), false);
|
||||
assert.equal(filter.is_exactly('is-private'), false);
|
||||
assert.equal(filter.can_bucket_by('is-mentioned'), true);
|
||||
assert.equal(filter.can_bucket_by('is-private'), false);
|
||||
|
||||
// The call below returns false for somewhat arbitrary
|
||||
// reasons -- we say is-private has precedence over
|
||||
// is-starred.
|
||||
assert.equal(filter.can_bucket_by('is-starred'), false);
|
||||
|
||||
terms = [
|
||||
{operator: 'is', operand: 'mentioned', negated: true},
|
||||
|
||||
@@ -415,6 +415,26 @@ Filter.prototype = {
|
||||
return _.isEqual(term_types, wanted_term_types);
|
||||
},
|
||||
|
||||
can_bucket_by: function () {
|
||||
// TODO: in ES6 use spread operator
|
||||
//
|
||||
// Examples call:
|
||||
// filter.can_bucket_by('stream', 'topic')
|
||||
//
|
||||
// The use case of this function is that we want
|
||||
// to know if a filter can start with a bucketing
|
||||
// data structure similar to the ones we have in
|
||||
// unread.js to pre-filter ids, rather than apply
|
||||
// a predicate to a larger list of candidate ids.
|
||||
//
|
||||
// (It's for optimization, basically.)
|
||||
var wanted_term_types = [].slice.call(arguments);
|
||||
var all_term_types = this.sorted_term_types();
|
||||
var term_types = all_term_types.slice(0, wanted_term_types.length);
|
||||
|
||||
return _.isEqual(term_types, wanted_term_types);
|
||||
},
|
||||
|
||||
first_valid_id_from: function (msg_ids) {
|
||||
var predicate = this.predicate();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user