stream: Modify stream_data.add_subscriber to use stream_id.

Thsi commit changes stream_data.add_subscriber to use stream_id
instead of stream name. We are using stream ids so that we can
avoid bugs related to live update after stream rename.
This commit is contained in:
sahil839 2020-06-21 01:05:41 +05:30 committed by Tim Abbott
parent 320d0ca806
commit ddbfbdc386
5 changed files with 17 additions and 17 deletions

View File

@ -225,7 +225,7 @@ run_test('subscribers', () => {
assert(!stream_data.is_user_subscribed('Rome', brutus.user_id));
// add
let ok = stream_data.add_subscriber('Rome', brutus.user_id);
let ok = stream_data.add_subscriber(sub.stream_id, brutus.user_id);
assert(ok);
assert(stream_data.is_user_subscribed('Rome', brutus.user_id));
sub = stream_data.get_sub('Rome');
@ -236,7 +236,7 @@ run_test('subscribers', () => {
assert.equal(sub.email_address, sub_email);
// verify that adding an already-added subscriber is a noop
stream_data.add_subscriber('Rome', brutus.user_id);
stream_data.add_subscriber(sub.stream_id, brutus.user_id);
assert(stream_data.is_user_subscribed('Rome', brutus.user_id));
sub = stream_data.get_sub('Rome');
stream_data.update_subscribers_count(sub);
@ -274,19 +274,19 @@ run_test('subscribers', () => {
// can be undefined.
stream_data.set_subscribers(sub);
stream_data.add_sub(sub);
stream_data.add_subscriber('Rome', brutus.user_id);
stream_data.add_subscriber(sub.stream_id, brutus.user_id);
sub.subscribed = true;
assert(stream_data.is_user_subscribed('Rome', brutus.user_id));
// Verify that we noop and don't crash when unsubscribed.
sub.subscribed = false;
stream_data.update_calculated_fields(sub);
ok = stream_data.add_subscriber('Rome', brutus.user_id);
ok = stream_data.add_subscriber(sub.stream_id, brutus.user_id);
assert(ok);
assert.equal(stream_data.is_user_subscribed('Rome', brutus.user_id), true);
stream_data.remove_subscriber('Rome', brutus.user_id);
assert.equal(stream_data.is_user_subscribed('Rome', brutus.user_id), false);
stream_data.add_subscriber('Rome', brutus.user_id);
stream_data.add_subscriber(sub.stream_id, brutus.user_id);
assert.equal(stream_data.is_user_subscribed('Rome', brutus.user_id), true);
blueslip.expect(
@ -302,13 +302,13 @@ run_test('subscribers', () => {
blueslip.expect(
'warn',
'We got an add_subscriber call for a non-existent stream.');
ok = stream_data.add_subscriber('UNKNOWN', brutus.user_id);
ok = stream_data.add_subscriber(9999999, brutus.user_id);
assert(!ok);
// Verify that we don't crash and return false for a bad user id.
blueslip.expect('error', 'Unknown user_id in get_by_user_id: 9999999');
blueslip.expect('error', 'We tried to add invalid subscriber: 9999999');
ok = stream_data.add_subscriber('Rome', 9999999);
ok = stream_data.add_subscriber(sub.stream_id, 9999999);
assert(!ok);
});
@ -613,7 +613,7 @@ run_test('get_subscriber_count', () => {
user_id: 101,
};
people.add_active_user(fred);
stream_data.add_subscriber('India', 102);
stream_data.add_subscriber(india.stream_id, 102);
assert.equal(stream_data.get_subscriber_count('India'), 1);
const george = {
email: 'george@zulip.com',
@ -621,7 +621,7 @@ run_test('get_subscriber_count', () => {
user_id: 103,
};
people.add_active_user(george);
stream_data.add_subscriber('India', 103);
stream_data.add_subscriber(india.stream_id, 103);
assert.equal(stream_data.get_subscriber_count('India'), 2);
const sub = stream_data.get_sub_by_name('India');

View File

@ -382,7 +382,7 @@ run_test('remove_deactivated_user_from_all_streams', () => {
dev_help.can_access_subscribers = true;
// verify that deactivating user should unsubscribe user from all streams
assert(stream_data.add_subscriber(dev_help.name, george.user_id));
assert(stream_data.add_subscriber(dev_help.stream_id, george.user_id));
assert(dev_help.subscribers.has(george.user_id));
stream_events.remove_deactivated_user_from_all_streams(george.user_id);

View File

@ -240,9 +240,9 @@ run_test('sort_recipients', () => {
const subscriber_email_1 = "b_user_2@zulip.net";
const subscriber_email_2 = "b_user_3@zulip.net";
const subscriber_email_3 = "b_bot@example.com";
stream_data.add_subscriber("Dev", people.get_user_id(subscriber_email_1));
stream_data.add_subscriber("Dev", people.get_user_id(subscriber_email_2));
stream_data.add_subscriber("Dev", people.get_user_id(subscriber_email_3));
stream_data.add_subscriber(1, people.get_user_id(subscriber_email_1));
stream_data.add_subscriber(1, people.get_user_id(subscriber_email_2));
stream_data.add_subscriber(1, people.get_user_id(subscriber_email_3));
const dev_sub = stream_data.get_sub("Dev");
const linux_sub = stream_data.get_sub("Linux");

View File

@ -340,7 +340,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
return;
}
if (!stream_data.add_subscriber(sub.name, user_id)) {
if (!stream_data.add_subscriber(stream_id, user_id)) {
blueslip.warn('Cannot process peer_add event');
return;
}

View File

@ -157,7 +157,7 @@ exports.rename_sub = function (sub, new_name) {
exports.subscribe_myself = function (sub) {
const user_id = people.my_current_user_id();
exports.add_subscriber(sub.name, user_id);
exports.add_subscriber(sub.stream_id, user_id);
sub.subscribed = true;
sub.newly_subscribed = true;
stream_info.set_true(sub.name, sub);
@ -628,8 +628,8 @@ exports.set_subscribers = function (sub, user_ids) {
sub.subscribers = new LazySet(user_ids || []);
};
exports.add_subscriber = function (stream_name, user_id) {
const sub = exports.get_sub(stream_name);
exports.add_subscriber = function (stream_id, user_id) {
const sub = exports.get_sub_by_id(stream_id);
if (typeof sub === 'undefined') {
blueslip.warn("We got an add_subscriber call for a non-existent stream.");
return false;