2019-02-13 10:22:16 +01:00
|
|
|
// In theory, this group of functions should apply the account-level
|
|
|
|
// defaults, however, they are only called after a manual override, so
|
|
|
|
// doing so is unnecessary with the current code. Ideally, we'd do a
|
|
|
|
// refactor to address that, however.
|
2019-06-14 19:29:48 +02:00
|
|
|
function update_stream_setting(sub, value, setting) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const setting_checkbox = $("#" + setting + "_" + sub.stream_id);
|
2019-06-14 19:29:48 +02:00
|
|
|
setting_checkbox.prop("checked", value);
|
|
|
|
sub[setting] = value;
|
2017-03-19 16:03:07 +01:00
|
|
|
}
|
|
|
|
|
2019-05-07 08:21:21 +02:00
|
|
|
exports.update_property = function (stream_id, property, value, other_values) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const sub = stream_data.get_sub_by_id(stream_id);
|
2017-03-19 16:03:07 +01:00
|
|
|
if (sub === undefined) {
|
|
|
|
// This isn't a stream we know about, so ignore it.
|
|
|
|
blueslip.warn("Update for an unknown subscription", {stream_id: stream_id,
|
2018-05-06 21:43:17 +02:00
|
|
|
property: property,
|
|
|
|
value: value});
|
2017-03-19 16:03:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (property) {
|
|
|
|
case 'color':
|
|
|
|
stream_color.update_stream_color(sub, value, {update_historical: true});
|
|
|
|
break;
|
|
|
|
case 'in_home_view':
|
2019-05-21 10:41:53 +02:00
|
|
|
stream_muting.update_is_muted(sub, !value);
|
2017-03-19 16:03:07 +01:00
|
|
|
break;
|
|
|
|
case 'desktop_notifications':
|
|
|
|
case 'audible_notifications':
|
2017-08-17 16:55:32 +02:00
|
|
|
case 'push_notifications':
|
2017-11-21 05:58:26 +01:00
|
|
|
case 'email_notifications':
|
2019-06-14 19:29:48 +02:00
|
|
|
update_stream_setting(sub, value, property);
|
2017-11-21 05:58:26 +01:00
|
|
|
break;
|
2017-03-19 16:03:07 +01:00
|
|
|
case 'name':
|
|
|
|
subs.update_stream_name(sub, value);
|
|
|
|
break;
|
|
|
|
case 'description':
|
2019-05-07 08:21:21 +02:00
|
|
|
subs.update_stream_description(sub, value, other_values.rendered_description);
|
2017-03-19 16:03:07 +01:00
|
|
|
break;
|
|
|
|
case 'email_address':
|
|
|
|
sub.email_address = value;
|
|
|
|
break;
|
|
|
|
case 'pin_to_top':
|
2019-06-14 19:29:48 +02:00
|
|
|
update_stream_setting(sub, value, property);
|
2017-03-19 16:03:07 +01:00
|
|
|
stream_list.refresh_pinned_or_unpinned_stream(sub);
|
|
|
|
break;
|
2019-05-02 19:43:27 +02:00
|
|
|
case 'invite_only':
|
|
|
|
subs.update_stream_privacy(sub, {
|
|
|
|
invite_only: value,
|
|
|
|
history_public_to_subscribers: other_values.history_public_to_subscribers,
|
|
|
|
});
|
|
|
|
break;
|
2019-11-26 02:37:12 +01:00
|
|
|
case 'wildcard_mentions_notify':
|
|
|
|
update_stream_setting(sub, value, property);
|
|
|
|
break;
|
2020-02-04 21:50:55 +01:00
|
|
|
case 'stream_post_policy':
|
|
|
|
subs.update_stream_post_policy(sub, value);
|
2019-05-02 19:43:27 +02:00
|
|
|
break;
|
2017-03-19 16:03:07 +01:00
|
|
|
default:
|
|
|
|
blueslip.warn("Unexpected subscription property type", {property: property,
|
|
|
|
value: value});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-22 07:31:58 +01:00
|
|
|
// Add yourself to a stream we already know about client-side.
|
|
|
|
// It's likely we should be passing in the full sub object from the caller/backend,
|
|
|
|
// but for now we just pass in the subscribers and color (things likely to be different).
|
|
|
|
exports.mark_subscribed = function (sub, subscribers, color) {
|
2017-03-19 16:47:30 +01:00
|
|
|
if (sub === undefined) {
|
|
|
|
blueslip.error('Undefined sub passed to mark_subscribed');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sub.subscribed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-22 07:31:58 +01:00
|
|
|
// If the backend sent us a color, use that
|
2018-11-10 01:57:10 +01:00
|
|
|
if (color !== undefined && sub.color !== color) {
|
2017-03-22 07:31:58 +01:00
|
|
|
sub.color = color;
|
2018-11-10 01:57:10 +01:00
|
|
|
stream_color.update_stream_color(sub, color, {update_historical: true});
|
2017-03-22 07:31:58 +01:00
|
|
|
} else if (sub.color === undefined) {
|
|
|
|
// If the backend didn't, and we have a color already, send
|
|
|
|
// the backend that color. It's not clear this code path is
|
|
|
|
// needed.
|
2017-03-22 07:36:45 +01:00
|
|
|
blueslip.warn("Frontend needed to pick a color in mark_subscribed");
|
2018-11-28 23:12:40 +01:00
|
|
|
color = color_data.pick_color();
|
2017-03-22 07:31:58 +01:00
|
|
|
subs.set_color(sub.stream_id, color);
|
|
|
|
}
|
2017-03-19 16:47:30 +01:00
|
|
|
stream_data.subscribe_myself(sub);
|
|
|
|
if (subscribers) {
|
2017-10-07 16:00:39 +02:00
|
|
|
stream_data.set_subscribers(sub, subscribers);
|
2017-03-19 16:47:30 +01:00
|
|
|
}
|
2018-03-10 02:59:13 +01:00
|
|
|
stream_data.update_calculated_fields(sub);
|
2017-03-19 16:47:30 +01:00
|
|
|
|
2017-10-18 08:36:56 +02:00
|
|
|
if (overlays.streams_open()) {
|
2017-10-24 07:43:00 +02:00
|
|
|
subs.update_settings_for_subscribed(sub);
|
2017-10-18 08:36:56 +02:00
|
|
|
}
|
2017-03-19 16:47:30 +01:00
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
if (narrow_state.is_for_stream_id(sub.stream_id)) {
|
2017-03-19 16:47:30 +01:00
|
|
|
current_msg_list.update_trailing_bookend();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update unread counts as the new stream in sidebar might
|
|
|
|
// need its unread counts re-calculated
|
2017-03-19 22:43:38 +01:00
|
|
|
message_util.do_unread_count_updates(message_list.all.all_messages());
|
2017-03-19 16:47:30 +01:00
|
|
|
|
|
|
|
$(document).trigger($.Event('subscription_add_done.zulip', {sub: sub}));
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.mark_unsubscribed = function (sub) {
|
|
|
|
if (sub === undefined) {
|
|
|
|
// We don't know about this stream
|
|
|
|
return;
|
|
|
|
} else if (sub.subscribed) {
|
|
|
|
stream_data.unsubscribe_myself(sub);
|
2018-03-10 02:59:13 +01:00
|
|
|
stream_data.update_calculated_fields(sub);
|
2017-10-24 07:43:00 +02:00
|
|
|
if (overlays.streams_open()) {
|
|
|
|
subs.update_settings_for_unsubscribed(sub);
|
|
|
|
}
|
2017-03-19 16:47:30 +01:00
|
|
|
} else {
|
|
|
|
// Already unsubscribed
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-25 15:25:31 +02:00
|
|
|
if (narrow_state.is_for_stream_id(sub.stream_id)) {
|
2017-03-19 16:47:30 +01:00
|
|
|
current_msg_list.update_trailing_bookend();
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).trigger($.Event('subscription_remove_done.zulip', {sub: sub}));
|
|
|
|
};
|
|
|
|
|
2018-08-04 19:44:31 +02:00
|
|
|
exports.remove_deactivated_user_from_all_streams = function (user_id) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const all_subs = stream_data.get_unsorted_subs();
|
2018-08-04 19:44:31 +02:00
|
|
|
|
|
|
|
_.each(all_subs, function (sub) {
|
|
|
|
if (stream_data.is_user_subscribed(sub.name, user_id)) {
|
|
|
|
stream_data.remove_subscriber(sub.name, user_id);
|
|
|
|
subs.rerender_subscriptions_settings(sub);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-03-19 16:47:30 +01:00
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.stream_events = exports;
|