Render just one message when editing and updating

(imported from commit 5b28e96e9d410faf9b33a5b0a1b4423191e8de58)
This commit is contained in:
Leo Franchi 2014-02-11 10:19:42 -05:00 committed by Jessica McKellar
parent b4e4a98de6
commit 305cf30c50
3 changed files with 32 additions and 7 deletions

View File

@ -191,9 +191,9 @@ exports.edit_locally = function edit_locally(message, raw_content, new_topic) {
message.content = exports.apply_markdown(raw_content);
// We don't handle unread counts since local messages must be sent by us
home_msg_list.rerender();
home_msg_list.view.rerender_message(message);
if (current_msg_list === narrowed_msg_list) {
narrowed_msg_list.rerender();
narrowed_msg_list.view().rerender_message(message);
}
stream_list.update_streams_sidebar();
};
@ -219,6 +219,7 @@ exports.reify_message_id = function reify_message_id(local_id, server_id) {
exports.process_from_server = function process_from_server(messages) {
var updated = false;
var locally_processed_ids = [];
var msgs_to_rerender = [];
messages = _.filter(messages, function (message) {
// In case we get the sent message before we get the send ACK, reify here
exports.reify_message_id(message.local_id, message.id);
@ -246,6 +247,7 @@ exports.process_from_server = function process_from_server(messages) {
updated = true;
}
}
msgs_to_rerender.push(client_message);
locally_processed_ids.push(client_message.id);
compose.report_as_received(client_message);
delete waiting_for_ack[client_message.id];
@ -255,10 +257,9 @@ exports.process_from_server = function process_from_server(messages) {
});
if (updated) {
// TODO just rerender the message, not the whole list
home_msg_list.rerender();
home_msg_list.view.rerender_messages(msgs_to_rerender);
if (current_msg_list === narrowed_msg_list) {
narrowed_msg_list.rerender();
narrowed_msg_list.view().rerender_messages(msgs_to_rerender);
}
} else {
_.each(locally_processed_ids, function (id) {

View File

@ -583,6 +583,27 @@ MessageListView.prototype = {
}
},
rerender_message: function MessageListView__rerender_message(message) {
var row = this.get_row(message.id);
if (row === undefined) {
blueslip.error("Cannot rerender a message that's not in this list!");
return;
}
// Re-render just this one message
var rendered_msg = $(templates.render('single_message', message));
this._rows[message.id] = rendered_msg;
row.replaceWith(rendered_msg);
},
rerender_messages: function MessageListView__rerender_messages(messages) {
var self = this;
_.each(messages, function (message) {
self.rerender_message(message);
});
},
append: function MessageListView__append(messages, messages_are_new) {
var cur_window_size = this._render_win_end - this._render_win_start;
if (cur_window_size < this._RENDER_WINDOW_SIZE) {

View File

@ -214,11 +214,14 @@ function maybe_add_narrowed_messages(messages, msg_list, messages_are_new) {
}
exports.update_messages = function update_messages(events) {
var msgs_to_rerender = [];
_.each(events, function (event) {
var msg = stored_messages[event.message_id];
if (msg === undefined) {
return;
}
msgs_to_rerender.push(msg);
msg.alerted = event.flags.indexOf("has_alert_word") !== -1;
msg.mentioned = event.flags.indexOf("mentioned") !== -1 ||
@ -268,9 +271,9 @@ exports.update_messages = function update_messages(events) {
alert_words.process_message(msg);
});
home_msg_list.rerender();
home_msg_list.view.rerender_messages(msgs_to_rerender);
if (current_msg_list === narrowed_msg_list) {
narrowed_msg_list.rerender();
narrowed_msg_list.view().rerender_messages(msgs_to_rerender);
}
unread.update_unread_counts();
stream_list.update_streams_sidebar();