Extract stream_data.unsubscribe_myself().

This commit is contained in:
Steve Howell 2016-11-09 07:26:35 -08:00 committed by Tim Abbott
parent b5ef679360
commit 00068f3164
3 changed files with 39 additions and 3 deletions

View File

@ -91,6 +91,38 @@ var people = global.people;
assert.equal(sub.name, 'Sweden');
}());
(function test_unsubscribe() {
stream_data.clear_subscriptions();
var sub = {name: 'devel', subscribed: false, stream_id: 1};
var me = {
email: 'me@zulip.com',
full_name: 'Current User',
user_id: 81
};
// set up user data
global.page_params.email = 'me@zulip.com';
people.add(me);
// set up our subscription
stream_data.add_sub('devel', sub);
sub.subscribed = true;
stream_data.set_subscribers(sub, [me.user_id]);
// ensure our setup is accurate
assert(stream_data.is_subscribed('devel'));
// DO THE UNSUBSCRIBE HERE
stream_data.unsubscribe_myself(sub);
assert(!sub.subscribed);
assert(!stream_data.is_subscribed('devel'));
// make sure subsequent calls work
sub = stream_data.get_sub('devel');
assert(!sub.subscribed);
}());
(function test_subscribers() {
stream_data.clear_subscriptions();
var sub = {name: 'Rome', subscribed: true, stream_id: 1};

View File

@ -30,6 +30,12 @@ exports.rename_sub = function (stream_id, new_name) {
return sub;
};
exports.unsubscribe_myself = function (sub) {
// Remove user from subscriber's list
exports.remove_subscriber(sub.name, page_params.email);
sub.subscribed = false;
};
exports.add_sub = function (stream_name, sub) {
if (!_.has(sub, 'subscribers')) {
sub.subscribers = Dict.from_array([]);

View File

@ -443,10 +443,8 @@ exports.mark_sub_unsubscribed = function (sub) {
return;
} else if (sub.subscribed) {
stream_list.remove_narrow_filter(sub.name, 'stream');
// Remove user from subscriber's list
stream_data.remove_subscriber(sub.name, page_params.email);
sub.subscribed = false;
stream_data.unsubscribe_myself(sub);
var button = button_for_sub(sub);
button.toggleClass("checked");