mirror of https://github.com/zulip/zulip.git
Add stream_data.set_subscribers() method.
This allows us to encapsulate our use of Dict for the internal data structure. (imported from commit e8acc50b4c17d339015cb9db9939b9452a62cc8b)
This commit is contained in:
parent
3db51fa17f
commit
4b90f1685d
|
@ -92,6 +92,10 @@ exports.get_name = function (stream_name) {
|
|||
return sub.name;
|
||||
};
|
||||
|
||||
exports.set_subscribers = function (sub, emails) {
|
||||
sub.subscribers = Dict.from_array(emails || []);
|
||||
};
|
||||
|
||||
// NOTE: If you do anything with the `subscribers` attribute on the stream
|
||||
// properties object, first make sure `is_subscribed` is true (i.e., the local
|
||||
// user is subscribed). Otherwise we don't and can't update the subscribers
|
||||
|
|
|
@ -71,9 +71,15 @@ var stream_data = require('js/stream_data.js');
|
|||
stream_data.clear_subscriptions();
|
||||
var sub = {name: 'Rome', subscribed: true};
|
||||
|
||||
sub.subscribers = new global.Dict(); // TODO: encapsulate this in stream_data.js
|
||||
|
||||
stream_data.add_sub('Rome', sub);
|
||||
|
||||
stream_data.set_subscribers(sub, ['fred@zulip.com', 'george@zulip.com']);
|
||||
assert(stream_data.user_is_subscribed('Rome', 'fred@zulip.com'));
|
||||
assert(stream_data.user_is_subscribed('Rome', 'george@zulip.com'));
|
||||
assert(!stream_data.user_is_subscribed('Rome', 'not_fred@zulip.com'));
|
||||
|
||||
stream_data.set_subscribers(sub, []);
|
||||
|
||||
var email = 'brutus@zulip.com';
|
||||
assert(!stream_data.user_is_subscribed('Rome', email));
|
||||
|
||||
|
@ -93,7 +99,6 @@ var stream_data = require('js/stream_data.js');
|
|||
stream_data.remove_subscriber('Rome', email);
|
||||
assert(!stream_data.user_is_subscribed('Rome', email));
|
||||
|
||||
|
||||
// Verify that we noop and don't crash when unsubsribed.
|
||||
sub.subscribed = false;
|
||||
stream_data.add_subscriber('Rome', email);
|
||||
|
|
Loading…
Reference in New Issue