mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	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:
		@@ -34,6 +34,7 @@
 | 
			
		||||
        "compose_fade": false,
 | 
			
		||||
        "subs": false,
 | 
			
		||||
        "timerender": false,
 | 
			
		||||
        "message_live_update": false,
 | 
			
		||||
        "message_edit": false,
 | 
			
		||||
        "reload": false,
 | 
			
		||||
        "composebox_typeahead": false,
 | 
			
		||||
 
 | 
			
		||||
@@ -555,13 +555,12 @@ exports.MessageList.prototype = {
 | 
			
		||||
        return item_list[cur_idx];
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    change_display_recipient: function MessageList_change_display_recipient(old_recipient,
 | 
			
		||||
                                                                            new_recipient) {
 | 
			
		||||
        // This method only works for streams.
 | 
			
		||||
    update_stream_name: function MessageList_update_stream_name(stream_id,
 | 
			
		||||
                                                                new_stream_name) {
 | 
			
		||||
        _.each(this._items, function (item) {
 | 
			
		||||
            if (item.display_recipient === old_recipient) {
 | 
			
		||||
                item.display_recipient = new_recipient;
 | 
			
		||||
                item.stream = new_recipient;
 | 
			
		||||
            if (item.stream_id && (item.stream_id === stream_id)) {
 | 
			
		||||
                item.display_recipient = new_stream_name;
 | 
			
		||||
                item.stream = new_stream_name;
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
        this.view.rerender_the_whole_thing();
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										17
									
								
								static/js/message_live_update.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								static/js/message_live_update.js
									
									
									
									
									
										Normal 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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -177,7 +177,7 @@ function update_stream_pin(sub, 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.
 | 
			
		||||
    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);
 | 
			
		||||
 | 
			
		||||
    // Update the message feed.
 | 
			
		||||
    _.each([home_msg_list, current_msg_list, message_list.all], function (list) {
 | 
			
		||||
        list.change_display_recipient(old_name, new_name);
 | 
			
		||||
    });
 | 
			
		||||
    message_live_update.update_stream_name(stream_id, new_name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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);
 | 
			
		||||
        break;
 | 
			
		||||
    case 'name':
 | 
			
		||||
        update_stream_name(sub.stream_id, sub.name, value);
 | 
			
		||||
        update_stream_name(sub.stream_id, value);
 | 
			
		||||
        break;
 | 
			
		||||
    case 'description':
 | 
			
		||||
        update_stream_description(sub, value);
 | 
			
		||||
 
 | 
			
		||||
@@ -793,6 +793,7 @@ JS_SPECS = {
 | 
			
		||||
            'js/filter.js',
 | 
			
		||||
            'js/message_list_view.js',
 | 
			
		||||
            'js/message_list.js',
 | 
			
		||||
            'js/message_live_update.js',
 | 
			
		||||
            'js/narrow.js',
 | 
			
		||||
            'js/reload.js',
 | 
			
		||||
            'js/compose_fade.js',
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user