mirror of https://github.com/zulip/zulip.git
Clean up stream renaming in the JS code.
We now use stream_id as our key to rename streams, which should prevent a few race conditions long term. (We are still possibly contending with other events that use stream_name as a key, so this is not perfect.)
This commit is contained in:
parent
e1372ddf5d
commit
7509f73f02
|
@ -62,12 +62,6 @@ var stream_data = require('js/stream_data.js');
|
||||||
|
|
||||||
assert(stream_data.in_home_view('social'));
|
assert(stream_data.in_home_view('social'));
|
||||||
assert(!stream_data.in_home_view('denmark'));
|
assert(!stream_data.in_home_view('denmark'));
|
||||||
|
|
||||||
// Deleting a subscription makes you unsubscribed from the perspective of
|
|
||||||
// the client.
|
|
||||||
// Deleting a subscription is case-insensitive.
|
|
||||||
stream_data.delete_sub('SOCIAL');
|
|
||||||
assert(!stream_data.is_subscribed('social'));
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
(function test_get_by_id() {
|
(function test_get_by_id() {
|
||||||
|
@ -84,6 +78,11 @@ var stream_data = require('js/stream_data.js');
|
||||||
assert.equal(sub.color, 'red');
|
assert.equal(sub.color, 'red');
|
||||||
sub = stream_data.get_sub_by_id(id);
|
sub = stream_data.get_sub_by_id(id);
|
||||||
assert.equal(sub.color, 'red');
|
assert.equal(sub.color, 'red');
|
||||||
|
|
||||||
|
stream_data.rename_sub(id, 'Sweden');
|
||||||
|
sub = stream_data.get_sub_by_id(id);
|
||||||
|
assert.equal(sub.color, 'red');
|
||||||
|
assert.equal(sub.name, 'Sweden');
|
||||||
}());
|
}());
|
||||||
|
|
||||||
(function test_subscribers() {
|
(function test_subscribers() {
|
||||||
|
|
|
@ -20,6 +20,16 @@ exports.is_active = function (stream_name) {
|
||||||
return recent_topics.has(stream_name);
|
return recent_topics.has(stream_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.rename_sub = function (stream_id, new_name) {
|
||||||
|
var sub = subs_by_stream_id.get(stream_id);
|
||||||
|
var old_name = sub.name;
|
||||||
|
sub.name = new_name;
|
||||||
|
stream_info.del(old_name);
|
||||||
|
stream_info.set(new_name, sub);
|
||||||
|
|
||||||
|
return sub;
|
||||||
|
};
|
||||||
|
|
||||||
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([], {fold_case: true});
|
sub.subscribers = Dict.from_array([], {fold_case: true});
|
||||||
|
|
|
@ -524,8 +524,8 @@ exports.update_dom_with_unread_counts = function (counts) {
|
||||||
animate_mention_changes(counts.mentioned_message_count);
|
animate_mention_changes(counts.mentioned_message_count);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.rename_stream = function (sub) {
|
exports.rename_stream = function (sub, new_name) {
|
||||||
sub.sidebar_li = build_stream_sidebar_row(sub.name);
|
sub.sidebar_li = build_stream_sidebar_row(new_name);
|
||||||
exports.build_stream_list(); // big hammer
|
exports.build_stream_list(); // big hammer
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -150,15 +150,12 @@ function update_stream_pin(sub, value) {
|
||||||
sub.pin_to_top = value;
|
sub.pin_to_top = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_stream_name(sub, new_name) {
|
function update_stream_name(stream_id, old_name, new_name) {
|
||||||
// Rename the stream internally.
|
// Rename the stream internally.
|
||||||
var old_name = sub.name;
|
var sub = stream_data.rename_sub(stream_id, new_name);
|
||||||
stream_data.delete_sub(old_name);
|
|
||||||
sub.name = new_name;
|
|
||||||
stream_data.add_sub(new_name, sub);
|
|
||||||
|
|
||||||
// Update the left sidebar.
|
// Update the left sidebar.
|
||||||
stream_list.rename_stream(sub);
|
stream_list.rename_stream(sub, new_name);
|
||||||
|
|
||||||
// Update the subscriptions page
|
// Update the subscriptions page
|
||||||
var sub_settings_selector = '.stream-row[data-stream-id=' + sub.stream_id + ']';
|
var sub_settings_selector = '.stream-row[data-stream-id=' + sub.stream_id + ']';
|
||||||
|
@ -576,7 +573,7 @@ exports.update_subscription_properties = function (stream_name, property, value)
|
||||||
update_stream_audible_notifications(sub, value);
|
update_stream_audible_notifications(sub, value);
|
||||||
break;
|
break;
|
||||||
case 'name':
|
case 'name':
|
||||||
update_stream_name(sub, value);
|
update_stream_name(sub.stream_id, sub.name, value);
|
||||||
break;
|
break;
|
||||||
case 'description':
|
case 'description':
|
||||||
update_stream_description(sub, value);
|
update_stream_description(sub, value);
|
||||||
|
|
Loading…
Reference in New Issue