mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
refactor: Change params for subs.mark_subscribed().
We pass in sub instead of stream_name, to support callers that already do lookups by stream id. And then we make the second optional argument be subscribers, since that is all we were using from the old `attrs` argument.
This commit is contained in:
@@ -283,6 +283,7 @@ var event_fixtures = {
|
|||||||
{
|
{
|
||||||
name: 'devel',
|
name: 'devel',
|
||||||
stream_id: 42,
|
stream_id: 42,
|
||||||
|
subscribers: ['alice@example.com', 'bob@example.com'],
|
||||||
// etc.
|
// etc.
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -653,10 +654,13 @@ run(function (override, capture, args) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var event = event_fixtures.subscription__add;
|
var event = event_fixtures.subscription__add;
|
||||||
override('subs', 'mark_subscribed', capture(['name', 'sub']));
|
override('stream_data', 'get_sub_by_id', function (stream_id) {
|
||||||
|
return {stream_id: stream_id};
|
||||||
|
});
|
||||||
|
override('subs', 'mark_subscribed', capture(['sub', 'subscribers']));
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
assert_same(args.name, 'devel');
|
assert_same(args.sub.stream_id, event.subscriptions[0].stream_id);
|
||||||
assert_same(args.sub, event.subscriptions[0]);
|
assert_same(args.subscribers, event.subscriptions[0].subscribers);
|
||||||
|
|
||||||
event = event_fixtures.subscription__peer_add;
|
event = event_fixtures.subscription__peer_add;
|
||||||
override('stream_data', 'add_subscriber', capture(['sub', 'user_id']));
|
override('stream_data', 'add_subscriber', capture(['sub', 'user_id']));
|
||||||
|
|||||||
@@ -177,8 +177,13 @@ function dispatch_normal_event(event) {
|
|||||||
var email;
|
var email;
|
||||||
|
|
||||||
if (event.op === 'add') {
|
if (event.op === 'add') {
|
||||||
_.each(event.subscriptions, function (sub) {
|
_.each(event.subscriptions, function (rec) {
|
||||||
subs.mark_subscribed(sub.name, sub);
|
var sub = stream_data.get_sub_by_id(rec.stream_id);
|
||||||
|
if (sub) {
|
||||||
|
subs.mark_subscribed(sub, rec.subscribers);
|
||||||
|
} else {
|
||||||
|
blueslip.error('Subscribing to unknown stream' + rec.stream_id);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else if (event.op === 'peer_add') {
|
} else if (event.op === 'peer_add') {
|
||||||
// TODO: remove email shim here and fix called functions
|
// TODO: remove email shim here and fix called functions
|
||||||
|
|||||||
@@ -411,11 +411,9 @@ exports.show_settings_for = function (stream_id) {
|
|||||||
show_subscription_settings(stream);
|
show_subscription_settings(stream);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.mark_subscribed = function (stream_name, attrs) {
|
exports.mark_subscribed = function (sub, subscribers) {
|
||||||
var sub = stream_data.get_sub(stream_name);
|
|
||||||
|
|
||||||
if (sub === undefined) {
|
if (sub === undefined) {
|
||||||
blueslip.error('Unknown stream in mark_subscribed: ' + stream_name);
|
blueslip.error('Undefined sub passed to mark_subscribed');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,8 +425,8 @@ exports.mark_subscribed = function (stream_name, attrs) {
|
|||||||
var color = get_color();
|
var color = get_color();
|
||||||
exports.set_color(sub.stream_id, color);
|
exports.set_color(sub.stream_id, color);
|
||||||
stream_data.subscribe_myself(sub);
|
stream_data.subscribe_myself(sub);
|
||||||
if (attrs) {
|
if (subscribers) {
|
||||||
stream_data.set_subscriber_emails(sub, attrs.subscribers);
|
stream_data.set_subscriber_emails(sub, subscribers);
|
||||||
}
|
}
|
||||||
var settings = settings_for_sub(sub);
|
var settings = settings_for_sub(sub);
|
||||||
var button = button_for_sub(sub);
|
var button = button_for_sub(sub);
|
||||||
@@ -1378,7 +1376,7 @@ $(function () {
|
|||||||
warning_elem.addClass("hide");
|
warning_elem.addClass("hide");
|
||||||
if (people.is_current_user(principal)) {
|
if (people.is_current_user(principal)) {
|
||||||
// mark_subscribed adds the user to the member list
|
// mark_subscribed adds the user to the member list
|
||||||
exports.mark_subscribed(sub.name);
|
exports.mark_subscribed(sub);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error_elem.addClass("hide");
|
error_elem.addClass("hide");
|
||||||
|
|||||||
Reference in New Issue
Block a user