message_events: Fix live update of message edit history.

This commit adds code to live update the message edit history.
Message edit history is fetched and rendered again if the edit
history modal is open.

This also adds 'data-message-id' attribute to 'message-history'
when opening history modal element which is used for checking
whether the history modal opened is of the message which is
edited.

Fixes #15051.
This commit is contained in:
sahil839 2020-05-23 22:37:31 +05:30 committed by Tim Abbott
parent 3aa74b67a0
commit 2af4ef6c6d
3 changed files with 15 additions and 4 deletions

View File

@ -7,6 +7,7 @@ zrequire('stream_data');
zrequire('stream_topic_history'); zrequire('stream_topic_history');
zrequire('unread'); zrequire('unread');
set_global('$', global.make_zjquery());
set_global('alert_words', {}); set_global('alert_words', {});
set_global('condense', {}); set_global('condense', {});
set_global('current_msg_list', {}); set_global('current_msg_list', {});

View File

@ -768,9 +768,7 @@ exports.edit_last_sent_message = function () {
}); });
}; };
exports.show_history = function (message) { exports.fetch_and_render_message_history = function (message) {
$('#message-history').html('');
$('#message-edit-history').modal("show");
channel.get({ channel.get({
url: "/json/messages/" + message.id + "/history", url: "/json/messages/" + message.id + "/history",
data: {message_id: JSON.stringify(message.id)}, data: {message_id: JSON.stringify(message.id)},
@ -816,7 +814,7 @@ exports.show_history = function (message) {
content_edit_history.push(item); content_edit_history.push(item);
} }
$('#message-history').attr('data-message-id', message.id);
$('#message-history').html(render_message_edit_history({ $('#message-history').html(render_message_edit_history({
edited_messages: content_edit_history, edited_messages: content_edit_history,
})); }));
@ -828,6 +826,12 @@ exports.show_history = function (message) {
}); });
}; };
exports.show_history = function (message) {
$('#message-history').html('');
$('#message-edit-history').modal("show");
exports.fetch_and_render_message_history(message);
};
function hide_delete_btn_show_spinner(deleting) { function hide_delete_btn_show_spinner(deleting) {
if (deleting) { if (deleting) {
$('do_delete_message_button').attr('disabled', 'disabled'); $('do_delete_message_button').attr('disabled', 'disabled');

View File

@ -319,6 +319,12 @@ exports.update_messages = function update_messages(events) {
recent_senders.process_topic_edit(...args); recent_senders.process_topic_edit(...args);
recent_topics.process_topic_edit(...args); recent_topics.process_topic_edit(...args);
} }
// Rerender "Message edit history" if it was open to the edited message.
if ($('#message-edit-history').hasClass('in') &&
msg.id === parseInt($('#message-history').attr('data-message-id'), 10)) {
message_edit.fetch_and_render_message_history(msg);
}
} }
// If a topic was edited, we re-render the whole view to get any // If a topic was edited, we re-render the whole view to get any