subscription: Add real time sync for user-just-deactivated case.

Currently, stream subscriptions aren't getting updated without
hard reload when user is deactivated in realm.

Fix this issue by updating stream subscription widgets on user
deactivation event.

Fixes #5623
This commit is contained in:
YJDave
2018-03-25 18:23:01 +05:30
committed by Tim Abbott
parent cf40536ed2
commit 24f51739eb
4 changed files with 18 additions and 0 deletions

View File

@@ -750,6 +750,7 @@ with_overrides(function (override) {
event = event_fixtures.realm_user__remove;
global.with_stub(function (stub) {
override('people.deactivate', stub.f);
override('stream_data.remove_deactivated_user_from_all_streams', noop);
dispatch(event);
var args = stub.get_args('person');
assert_same(args.person, event.person);

View File

@@ -209,6 +209,12 @@ zrequire('marked', 'third/marked/lib/marked');
stream_data.update_subscribers_count(sub);
assert.equal(sub.subscriber_count, 0);
// verify that deactivating user should unsubscribe user from all streams
assert(stream_data.add_subscriber('Rome', george.user_id));
set_global('subs', { rerender_subscriptions_settings: function () {} });
stream_data.remove_deactivated_user_from_all_streams(george.user_id);
assert(!stream_data.is_user_subscribed('Rome', george.user_id));
// verify that checking subscription with undefined user id
global.blueslip.warn = function (msg) {
assert.equal(msg, "Undefined user_id passed to function is_user_subscribed");

View File

@@ -197,6 +197,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
people.add_in_realm(event.person);
} else if (event.op === 'remove') {
people.deactivate(event.person);
stream_data.remove_deactivated_user_from_all_streams(event.person.user_id);
} else if (event.op === 'update') {
user_events.update_person(event.person);
}

View File

@@ -349,6 +349,16 @@ exports.add_subscriber = function (stream_name, user_id) {
return true;
};
exports.remove_deactivated_user_from_all_streams = function (user_id) {
(stream_info.values()).forEach(function (stream) {
if (exports.is_user_subscribed(stream.name, user_id)) {
exports.remove_subscriber(stream.name, user_id);
var sub = exports.get_sub(stream.name);
subs.rerender_subscriptions_settings(sub);
}
});
};
exports.remove_subscriber = function (stream_name, user_id) {
var sub = exports.get_sub(stream_name);
if (typeof sub === 'undefined') {