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:
Steve Howell 2013-09-16 16:26:53 -04:00
parent 3db51fa17f
commit 4b90f1685d
2 changed files with 12 additions and 3 deletions

View File

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

View File

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