diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index 5abcbde681..65a1e65186 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -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'])); diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js index 43a53c88f1..15071bc36e 100644 --- a/frontend_tests/node_tests/stream_data.js +++ b/frontend_tests/node_tests/stream_data.js @@ -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); diff --git a/static/js/server_events.js b/static/js/server_events.js index 8611884929..1d7444bda6 100644 --- a/static/js/server_events.js +++ b/static/js/server_events.js @@ -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}); }); diff --git a/static/js/stream_data.js b/static/js/stream_data.js index 39f2ce9a00..3d7e270ddc 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -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);