Extract stream_events.js

This commit is contained in:
Steve Howell 2017-03-19 08:03:07 -07:00 committed by Tim Abbott
parent cfd1e8cbc3
commit 1d7d6869c9
7 changed files with 82 additions and 70 deletions

View File

@ -41,6 +41,7 @@
"modals": false, "modals": false,
"subs": false, "subs": false,
"stream_muting": false, "stream_muting": false,
"stream_events": false,
"timerender": false, "timerender": false,
"message_live_update": false, "message_live_update": false,
"message_edit": false, "message_edit": false,

View File

@ -633,7 +633,7 @@ with_overrides(function (override) {
var event = event_fixtures.stream; var event = event_fixtures.stream;
global.with_stub(function (stub) { global.with_stub(function (stub) {
override('subs.update_subscription_properties', stub.f); override('stream_events.update_property', stub.f);
override('admin.update_default_streams_table', noop); override('admin.update_default_streams_table', noop);
dispatch(event); dispatch(event);
var args = stub.get_args('stream_id', 'property', 'value'); var args = stub.get_args('stream_id', 'property', 'value');
@ -700,7 +700,7 @@ with_overrides(function (override) {
event = event_fixtures.subscription__update; event = event_fixtures.subscription__update;
global.with_stub(function (stub) { global.with_stub(function (stub) {
override('subs.update_subscription_properties', stub.f); override('stream_events.update_property', stub.f);
dispatch(event); dispatch(event);
var args = stub.get_args('stream_id', 'property', 'value'); var args = stub.get_args('stream_id', 'property', 'value');
assert_same(args.stream_id, event.stream_id); assert_same(args.stream_id, event.stream_id);

View File

@ -46,8 +46,8 @@ var setup = function (results) {
throw Error('update error'); throw Error('update error');
}, },
}); });
set_global('subs', { set_global('stream_events', {
update_subscription_properties: function () { update_property: function () {
throw Error('subs update error'); throw Error('subs update error');
}, },
}); });

View File

@ -161,7 +161,7 @@ function dispatch_normal_event(event) {
case 'stream': case 'stream':
if (event.op === 'update') { if (event.op === 'update') {
// Legacy: Stream properties are still managed by subs.js on the client side. // Legacy: Stream properties are still managed by subs.js on the client side.
subs.update_subscription_properties( stream_events.update_property(
event.stream_id, event.stream_id,
event.property, event.property,
event.value event.value
@ -229,7 +229,7 @@ function dispatch_normal_event(event) {
subs.mark_sub_unsubscribed(sub); subs.mark_sub_unsubscribed(sub);
}); });
} else if (event.op === 'update') { } else if (event.op === 'update') {
subs.update_subscription_properties( stream_events.update_property(
event.stream_id, event.stream_id,
event.property, event.property,
event.value event.value

View File

@ -0,0 +1,70 @@
var stream_events = (function () {
var exports = {};
function update_stream_desktop_notifications(sub, value) {
var desktop_notifications_checkbox = $(".subscription_settings[data-stream-id='" + sub.stream_id + "'] #sub_desktop_notifications_setting .sub_setting_control");
desktop_notifications_checkbox.prop('checked', value);
sub.desktop_notifications = value;
}
function update_stream_audible_notifications(sub, value) {
var audible_notifications_checkbox = $(".subscription_settings[data-stream-id='" + sub.stream_id + "'] #sub_audible_notifications_setting .sub_setting_control");
audible_notifications_checkbox.prop('checked', value);
sub.audible_notifications = value;
}
function update_stream_pin(sub, value) {
var pin_checkbox = $('#pinstream-' + sub.stream_id);
pin_checkbox.prop('checked', value);
sub.pin_to_top = value;
}
exports.update_property = function (stream_id, property, value) {
var sub = stream_data.get_sub_by_id(stream_id);
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,
property: property,
value: value});
return;
}
switch (property) {
case 'color':
stream_color.update_stream_color(sub, value, {update_historical: true});
break;
case 'in_home_view':
stream_muting.update_in_home_view(sub, value);
break;
case 'desktop_notifications':
update_stream_desktop_notifications(sub, value);
break;
case 'audible_notifications':
update_stream_audible_notifications(sub, value);
break;
case 'name':
subs.update_stream_name(sub, value);
break;
case 'description':
subs.update_stream_description(sub, value);
break;
case 'email_address':
sub.email_address = value;
break;
case 'pin_to_top':
update_stream_pin(sub, value);
stream_list.refresh_pinned_or_unpinned_stream(sub);
break;
default:
blueslip.warn("Unexpected subscription property type", {property: property,
value: value});
}
};
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = stream_events;
}

View File

@ -134,25 +134,7 @@ exports.toggle_pin_to_top_stream = function (sub) {
set_stream_property(sub, 'pin_to_top', !sub.pin_to_top); set_stream_property(sub, 'pin_to_top', !sub.pin_to_top);
}; };
function update_stream_desktop_notifications(sub, value) { exports.update_stream_name = function (sub, new_name) {
var desktop_notifications_checkbox = $(".subscription_settings[data-stream-id='" + sub.stream_id + "'] #sub_desktop_notifications_setting .sub_setting_control");
desktop_notifications_checkbox.prop('checked', value);
sub.desktop_notifications = value;
}
function update_stream_audible_notifications(sub, value) {
var audible_notifications_checkbox = $(".subscription_settings[data-stream-id='" + sub.stream_id + "'] #sub_audible_notifications_setting .sub_setting_control");
audible_notifications_checkbox.prop('checked', value);
sub.audible_notifications = value;
}
function update_stream_pin(sub, value) {
var pin_checkbox = $('#pinstream-' + sub.stream_id);
pin_checkbox.prop('checked', value);
sub.pin_to_top = value;
}
function update_stream_name(sub, new_name) {
// Rename the stream internally. // Rename the stream internally.
stream_data.rename_sub(sub, new_name); stream_data.rename_sub(sub, new_name);
var stream_id = sub.stream_id; var stream_id = sub.stream_id;
@ -171,9 +153,9 @@ function update_stream_name(sub, new_name) {
// Update the message feed. // Update the message feed.
message_live_update.update_stream_name(stream_id, new_name); message_live_update.update_stream_name(stream_id, new_name);
} };
function update_stream_description(sub, description) { exports.update_stream_description = function (sub, description) {
sub.description = description; sub.description = description;
// Update stream row // Update stream row
@ -184,7 +166,7 @@ function update_stream_description(sub, description) {
var stream_settings = settings_for_sub(sub); var stream_settings = settings_for_sub(sub);
stream_settings.find('input.description').val(description); stream_settings.find('input.description').val(description);
stream_settings.find('.stream-description-editable').text(description); stream_settings.find('.stream-description-editable').text(description);
} };
function stream_desktop_notifications_clicked(e) { function stream_desktop_notifications_clicked(e) {
var sub = get_sub_for_target(e.target); var sub = get_sub_for_target(e.target);
@ -780,48 +762,6 @@ exports.close = function () {
subs.remove_miscategorized_streams(); subs.remove_miscategorized_streams();
}; };
exports.update_subscription_properties = function (stream_id, property, value) {
var sub = stream_data.get_sub_by_id(stream_id);
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,
property: property,
value: value});
return;
}
switch (property) {
case 'color':
stream_color.update_stream_color(sub, value, {update_historical: true});
break;
case 'in_home_view':
stream_muting.update_in_home_view(sub, value);
break;
case 'desktop_notifications':
update_stream_desktop_notifications(sub, value);
break;
case 'audible_notifications':
update_stream_audible_notifications(sub, value);
break;
case 'name':
update_stream_name(sub, value);
break;
case 'description':
update_stream_description(sub, value);
break;
case 'email_address':
sub.email_address = value;
break;
case 'pin_to_top':
update_stream_pin(sub, value);
stream_list.refresh_pinned_or_unpinned_stream(sub);
break;
default:
blueslip.warn("Unexpected subscription property type", {property: property,
value: value});
}
};
function ajaxSubscribe(stream) { function ajaxSubscribe(stream) {
// Subscribe yourself to a single stream. // Subscribe yourself to a single stream.
var true_stream_name; var true_stream_name;

View File

@ -844,6 +844,7 @@ JS_SPECS = {
'js/stream_color.js', 'js/stream_color.js',
'js/stream_data.js', 'js/stream_data.js',
'js/stream_muting.js', 'js/stream_muting.js',
'js/stream_events.js',
'js/subs.js', 'js/subs.js',
'js/message_edit.js', 'js/message_edit.js',
'js/condense.js', 'js/condense.js',