ui: Upgrade remove_message to allow removing messages in bulk.

We simply pass the visible message ids to remove_and_rerender
which supports bulk delete operation.

This helps us avoid deleting messages in a loop which freezes the
UI for the duration of the loop.
This commit is contained in:
Aman Agrawal
2020-06-12 14:51:35 +05:30
committed by Tim Abbott
parent ccc0c8706c
commit 0cffaa7b5d
3 changed files with 12 additions and 13 deletions

View File

@@ -114,15 +114,19 @@ exports.show_message_failed = function (message_id, failed_msg) {
});
};
exports.remove_message = function (message_id) {
exports.remove_messages = function (message_ids) {
const msg_ids_to_rerender = [];
for (const list of [message_list.all, home_msg_list, message_list.narrowed]) {
if (list === undefined) {
continue;
}
const row = list.get_row(message_id);
if (row !== undefined) {
list.remove_and_rerender([{id: message_id}]);
for (const message_id of message_ids) {
const row = list.get_row(message_id);
if (row !== undefined) {
msg_ids_to_rerender.push({id: message_id});
}
}
list.remove_and_rerender(msg_ids_to_rerender);
}
};