mirror of https://github.com/zulip/zulip.git
refactor: Simplify narrow_state.is_for_stream_id().
This takes advantage of the new function narrow_state.stream_id(). We now assume the incoming stream_id is a valid stream_id, so we no longer need to test some of the error checking. (It's possible that the incoming stream_id may no longer be for a stream you subscribe to, but the nice benefit of working more in "id space" is that if it doesn't match the narrow's stream id, we know false is a safe return value.)
This commit is contained in:
parent
a62c85c015
commit
7222dbd99b
|
@ -23,12 +23,6 @@ function set_filter(operators) {
|
|||
|
||||
assert(!narrow_state.is_for_stream_id(test_stream.stream_id));
|
||||
|
||||
var bad_stream_id = 1000000;
|
||||
blueslip.set_test_data('error', 'Bad stream id ' + bad_stream_id);
|
||||
assert(!narrow_state.is_for_stream_id(bad_stream_id));
|
||||
assert.equal(blueslip.get_test_logs('error').length, 1);
|
||||
blueslip.clear_test_data();
|
||||
|
||||
set_filter([
|
||||
['stream', 'Test'],
|
||||
['topic', 'Bar'],
|
||||
|
|
|
@ -234,20 +234,13 @@ exports.is_for_stream_id = function (stream_id) {
|
|||
// This is not perfect, since we still track narrows by
|
||||
// name, not id, but at least the interface is good going
|
||||
// forward.
|
||||
var sub = stream_data.get_sub_by_id(stream_id);
|
||||
var narrow_stream_id = exports.stream_id();
|
||||
|
||||
if (sub === undefined) {
|
||||
blueslip.error('Bad stream id ' + stream_id);
|
||||
if (narrow_stream_id === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var narrow_stream_name = exports.stream();
|
||||
|
||||
if (narrow_stream_name === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (sub.name === narrow_stream_name);
|
||||
return (stream_id === narrow_stream_id);
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
|
Loading…
Reference in New Issue