mirror of https://github.com/zulip/zulip.git
Extract stream_data.unsubscribe_myself().
This commit is contained in:
parent
b5ef679360
commit
00068f3164
|
@ -91,6 +91,38 @@ var people = global.people;
|
||||||
assert.equal(sub.name, 'Sweden');
|
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() {
|
(function test_subscribers() {
|
||||||
stream_data.clear_subscriptions();
|
stream_data.clear_subscriptions();
|
||||||
var sub = {name: 'Rome', subscribed: true, stream_id: 1};
|
var sub = {name: 'Rome', subscribed: true, stream_id: 1};
|
||||||
|
|
|
@ -30,6 +30,12 @@ exports.rename_sub = function (stream_id, new_name) {
|
||||||
return sub;
|
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) {
|
exports.add_sub = function (stream_name, sub) {
|
||||||
if (!_.has(sub, 'subscribers')) {
|
if (!_.has(sub, 'subscribers')) {
|
||||||
sub.subscribers = Dict.from_array([]);
|
sub.subscribers = Dict.from_array([]);
|
||||||
|
|
|
@ -443,10 +443,8 @@ exports.mark_sub_unsubscribed = function (sub) {
|
||||||
return;
|
return;
|
||||||
} else if (sub.subscribed) {
|
} else if (sub.subscribed) {
|
||||||
stream_list.remove_narrow_filter(sub.name, 'stream');
|
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);
|
var button = button_for_sub(sub);
|
||||||
button.toggleClass("checked");
|
button.toggleClass("checked");
|
||||||
|
|
Loading…
Reference in New Issue