mirror of https://github.com/zulip/zulip.git
Change stream_data.add_subscriber() to accept user_ids.
We no longer require passing in an email to stream_data.add_subscriber(), since we only track user ids in stream_data.js.
This commit is contained in:
parent
a03a7d4c95
commit
537a3b8ca8
|
@ -649,10 +649,10 @@ run(function (override, capture, args) {
|
|||
assert_same(args.sub, event.subscriptions[0]);
|
||||
|
||||
event = event_fixtures.subscription__peer_add;
|
||||
override('stream_data', 'add_subscriber', capture(['sub', 'email']));
|
||||
override('stream_data', 'add_subscriber', capture(['sub', 'user_id']));
|
||||
dispatch(event);
|
||||
assert_same(args.sub, event.subscriptions[0]);
|
||||
assert_same(args.email, 'bob@example.com');
|
||||
assert_same(args.user_id, 555);
|
||||
|
||||
event = event_fixtures.subscription__peer_remove;
|
||||
override('stream_data', 'remove_subscriber', capture(['sub', 'email']));
|
||||
|
|
|
@ -134,14 +134,14 @@ var people = global.people;
|
|||
assert(!stream_data.user_is_subscribed('Rome', email));
|
||||
|
||||
// add
|
||||
stream_data.add_subscriber('Rome', email);
|
||||
stream_data.add_subscriber('Rome', brutus.user_id);
|
||||
assert(stream_data.user_is_subscribed('Rome', email));
|
||||
sub = stream_data.get_sub('Rome');
|
||||
stream_data.update_subscribers_count(sub);
|
||||
assert.equal(sub.subscriber_count, 1);
|
||||
|
||||
// verify that adding an already-added subscriber is a noop
|
||||
stream_data.add_subscriber('Rome', email);
|
||||
stream_data.add_subscriber('Rome', brutus.user_id);
|
||||
assert(stream_data.user_is_subscribed('Rome', email));
|
||||
sub = stream_data.get_sub('Rome');
|
||||
stream_data.update_subscribers_count(sub);
|
||||
|
@ -165,14 +165,14 @@ var people = global.people;
|
|||
// can be undefined.
|
||||
stream_data.set_subscribers(sub);
|
||||
stream_data.add_sub('Rome', sub);
|
||||
stream_data.add_subscriber('Rome', email);
|
||||
stream_data.add_subscriber('Rome', brutus.user_id);
|
||||
sub.subscribed = true;
|
||||
assert(stream_data.user_is_subscribed('Rome', email));
|
||||
|
||||
// Verify that we noop and don't crash when unsubsribed.
|
||||
// Verify that we noop and don't crash when unsubscribed.
|
||||
sub.subscribed = false;
|
||||
global.blueslip.warn = function () {};
|
||||
stream_data.add_subscriber('Rome', email);
|
||||
stream_data.add_subscriber('Rome', brutus.user_id);
|
||||
assert.equal(stream_data.user_is_subscribed('Rome', email), undefined);
|
||||
stream_data.remove_subscriber('Rome', email);
|
||||
assert.equal(stream_data.user_is_subscribed('Rome', email), undefined);
|
||||
|
|
|
@ -133,7 +133,7 @@ function dispatch_normal_event(event) {
|
|||
person = people.get_person_from_user_id(event.user_id);
|
||||
email = person.email;
|
||||
_.each(event.subscriptions, function (sub) {
|
||||
stream_data.add_subscriber(sub, email);
|
||||
stream_data.add_subscriber(sub, event.user_id);
|
||||
$(document).trigger('peer_subscribe.zulip',
|
||||
{stream_name: sub, user_email: email});
|
||||
});
|
||||
|
|
|
@ -146,15 +146,15 @@ exports.set_subscriber_emails = function (sub, emails) {
|
|||
});
|
||||
};
|
||||
|
||||
exports.add_subscriber = function (stream_name, user_email) {
|
||||
exports.add_subscriber = function (stream_name, user_id) {
|
||||
var sub = exports.get_sub(stream_name);
|
||||
if (typeof sub === 'undefined') {
|
||||
blueslip.warn("We got an add_subscriber call for a non-existent stream.");
|
||||
return;
|
||||
}
|
||||
var user_id = people.get_user_id(user_email);
|
||||
if (!user_id) {
|
||||
blueslip.error("We tried to add invalid subscriber: " + user_email);
|
||||
var person = people.get_person_from_user_id(user_id);
|
||||
if (person === undefined) {
|
||||
blueslip.error("We tried to add invalid subscriber: " + user_id);
|
||||
return;
|
||||
}
|
||||
sub.subscribers.set(user_id, true);
|
||||
|
|
Loading…
Reference in New Issue