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:
Steve Howell
2017-03-04 15:09:48 -08:00
committed by Tim Abbott
parent 2f8ecad295
commit c5757ac8fe
3 changed files with 19 additions and 12 deletions

View File

@@ -283,6 +283,7 @@ var event_fixtures = {
{
name: 'devel',
stream_id: 42,
subscribers: ['alice@example.com', 'bob@example.com'],
// etc.
},
],
@@ -653,10 +654,13 @@ run(function (override, capture, args) {
});
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);
assert_same(args.name, 'devel');
assert_same(args.sub, event.subscriptions[0]);
assert_same(args.sub.stream_id, event.subscriptions[0].stream_id);
assert_same(args.subscribers, event.subscriptions[0].subscribers);
event = event_fixtures.subscription__peer_add;
override('stream_data', 'add_subscriber', capture(['sub', 'user_id']));

View File

@@ -177,8 +177,13 @@ function dispatch_normal_event(event) {
var email;
if (event.op === 'add') {
_.each(event.subscriptions, function (sub) {
subs.mark_subscribed(sub.name, sub);
_.each(event.subscriptions, function (rec) {
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') {
// TODO: remove email shim here and fix called functions

View File

@@ -411,11 +411,9 @@ exports.show_settings_for = function (stream_id) {
show_subscription_settings(stream);
};
exports.mark_subscribed = function (stream_name, attrs) {
var sub = stream_data.get_sub(stream_name);
exports.mark_subscribed = function (sub, subscribers) {
if (sub === undefined) {
blueslip.error('Unknown stream in mark_subscribed: ' + stream_name);
blueslip.error('Undefined sub passed to mark_subscribed');
return;
}
@@ -427,8 +425,8 @@ exports.mark_subscribed = function (stream_name, attrs) {
var color = get_color();
exports.set_color(sub.stream_id, color);
stream_data.subscribe_myself(sub);
if (attrs) {
stream_data.set_subscriber_emails(sub, attrs.subscribers);
if (subscribers) {
stream_data.set_subscriber_emails(sub, subscribers);
}
var settings = settings_for_sub(sub);
var button = button_for_sub(sub);
@@ -1378,7 +1376,7 @@ $(function () {
warning_elem.addClass("hide");
if (people.is_current_user(principal)) {
// mark_subscribed adds the user to the member list
exports.mark_subscribed(sub.name);
exports.mark_subscribed(sub);
}
} else {
error_elem.addClass("hide");