stream_data: Modify remove_subscriber to use stream id.

This commit changes stream_data.remove_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:22:31 +05:30
committed by Tim Abbott
parent ddbfbdc386
commit 235601d3b6
4 changed files with 13 additions and 13 deletions

View File

@@ -243,7 +243,7 @@ run_test('subscribers', () => {
assert.equal(sub.subscriber_count, 1);
// remove
ok = stream_data.remove_subscriber('Rome', brutus.user_id);
ok = stream_data.remove_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');
@@ -256,14 +256,14 @@ run_test('subscribers', () => {
assert.equal(stream_data.is_user_subscribed('Rome', undefined), undefined);
// Verify noop for bad stream when removing subscriber
const bad_stream = 'UNKNOWN';
blueslip.expect('warn', 'We got a remove_subscriber call for a non-existent stream ' + bad_stream);
ok = stream_data.remove_subscriber(bad_stream, brutus.user_id);
const bad_stream_id = 999999;
blueslip.expect('warn', 'We got a remove_subscriber call for a non-existent stream ' + bad_stream_id);
ok = stream_data.remove_subscriber(bad_stream_id, brutus.user_id);
assert(!ok);
// verify that removing an already-removed subscriber is a noop
blueslip.expect('warn', 'We tried to remove invalid subscriber: 104');
ok = stream_data.remove_subscriber('Rome', brutus.user_id);
ok = stream_data.remove_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');
@@ -284,7 +284,7 @@ run_test('subscribers', () => {
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);
stream_data.remove_subscriber(sub.stream_id, brutus.user_id);
assert.equal(stream_data.is_user_subscribed('Rome', brutus.user_id), false);
stream_data.add_subscriber(sub.stream_id, brutus.user_id);
assert.equal(stream_data.is_user_subscribed('Rome', brutus.user_id), true);
@@ -295,7 +295,7 @@ run_test('subscribers', () => {
sub.invite_only = true;
stream_data.update_calculated_fields(sub);
assert.equal(stream_data.is_user_subscribed('Rome', brutus.user_id), undefined);
stream_data.remove_subscriber('Rome', brutus.user_id);
stream_data.remove_subscriber(sub.stream_id, brutus.user_id);
assert.equal(stream_data.is_user_subscribed('Rome', brutus.user_id), undefined);
// Verify that we don't crash and return false for a bad stream.

View File

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

View File

@@ -176,7 +176,7 @@ exports.is_subscriber_subset = function (sub1, sub2) {
exports.unsubscribe_myself = function (sub) {
// Remove user from subscriber's list
const user_id = people.my_current_user_id();
exports.remove_subscriber(sub.name, user_id);
exports.remove_subscriber(sub.stream_id, user_id);
sub.subscribed = false;
sub.newly_subscribed = false;
stream_info.set_false(sub.name, sub);
@@ -644,10 +644,10 @@ exports.add_subscriber = function (stream_id, user_id) {
return true;
};
exports.remove_subscriber = function (stream_name, user_id) {
const sub = exports.get_sub(stream_name);
exports.remove_subscriber = function (stream_id, user_id) {
const sub = exports.get_sub_by_id(stream_id);
if (typeof sub === 'undefined') {
blueslip.warn("We got a remove_subscriber call for a non-existent stream " + stream_name);
blueslip.warn("We got a remove_subscriber call for a non-existent stream " + stream_id);
return false;
}
if (!sub.subscribers.has(user_id)) {

View File

@@ -137,7 +137,7 @@ exports.remove_deactivated_user_from_all_streams = function (user_id) {
for (const sub of all_subs) {
if (stream_data.is_user_subscribed(sub.name, user_id)) {
stream_data.remove_subscriber(sub.name, user_id);
stream_data.remove_subscriber(sub.stream_id, user_id);
subs.rerender_subscriptions_settings(sub);
}
}