Use stream id to live-update messages for name changes.

When we change a stream name, we now use the stream id as the
key to find messages we need to live update.  This eliminates
some possible race conditions from two users renaming a stream.

This commit introduces message_live_update.js.

The new call stack is this:

    subs.update_subscription_properties
    subs.update_stream_name
    message_live_update.update_stream_name
    message_list.update_stream_name
This commit is contained in:
Steve Howell 2017-01-05 08:34:27 -08:00 committed by Tim Abbott
parent 99b5c00ec1
commit 90fa797f9b
5 changed files with 27 additions and 11 deletions

View File

@ -34,6 +34,7 @@
"compose_fade": false, "compose_fade": false,
"subs": false, "subs": false,
"timerender": false, "timerender": false,
"message_live_update": false,
"message_edit": false, "message_edit": false,
"reload": false, "reload": false,
"composebox_typeahead": false, "composebox_typeahead": false,

View File

@ -555,13 +555,12 @@ exports.MessageList.prototype = {
return item_list[cur_idx]; return item_list[cur_idx];
}, },
change_display_recipient: function MessageList_change_display_recipient(old_recipient, update_stream_name: function MessageList_update_stream_name(stream_id,
new_recipient) { new_stream_name) {
// This method only works for streams.
_.each(this._items, function (item) { _.each(this._items, function (item) {
if (item.display_recipient === old_recipient) { if (item.stream_id && (item.stream_id === stream_id)) {
item.display_recipient = new_recipient; item.display_recipient = new_stream_name;
item.stream = new_recipient; item.stream = new_stream_name;
} }
}); });
this.view.rerender_the_whole_thing(); this.view.rerender_the_whole_thing();

View File

@ -0,0 +1,17 @@
var message_live_update = (function () {
var exports = {};
exports.update_stream_name = function (stream_id, new_name) {
_.each([home_msg_list, current_msg_list, message_list.all], function (list) {
list.update_stream_name(stream_id, new_name);
});
};
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = message_live_update;
}

View File

@ -177,7 +177,7 @@ function update_stream_pin(sub, value) {
sub.pin_to_top = value; sub.pin_to_top = value;
} }
function update_stream_name(stream_id, old_name, new_name) { function update_stream_name(stream_id, new_name) {
// Rename the stream internally. // Rename the stream internally.
var sub = stream_data.rename_sub(stream_id, new_name); var sub = stream_data.rename_sub(stream_id, new_name);
@ -195,9 +195,7 @@ function update_stream_name(stream_id, old_name, new_name) {
sub_row.attr("data-stream-name", new_name); sub_row.attr("data-stream-name", new_name);
// Update the message feed. // Update the message feed.
_.each([home_msg_list, current_msg_list, message_list.all], function (list) { message_live_update.update_stream_name(stream_id, new_name);
list.change_display_recipient(old_name, new_name);
});
} }
function update_stream_description(sub, description) { function update_stream_description(sub, description) {
@ -659,7 +657,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.stream_id, sub.name, value); update_stream_name(sub.stream_id, value);
break; break;
case 'description': case 'description':
update_stream_description(sub, value); update_stream_description(sub, value);

View File

@ -793,6 +793,7 @@ JS_SPECS = {
'js/filter.js', 'js/filter.js',
'js/message_list_view.js', 'js/message_list_view.js',
'js/message_list.js', 'js/message_list.js',
'js/message_live_update.js',
'js/narrow.js', 'js/narrow.js',
'js/reload.js', 'js/reload.js',
'js/compose_fade.js', 'js/compose_fade.js',