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

@@ -799,10 +799,10 @@ with_overrides(function (override) {
override('stream_list.update_streams_sidebar', noop);
global.with_stub(function (stub) {
override('unread_ops.process_read_messages_event', noop);
override('ui.remove_message', stub.f);
override('ui.remove_messages', stub.f);
dispatch(event);
const args = stub.get_args('message_id');
assert_same(args.message_id, 1337);
const args = stub.get_args('message_ids');
assert_same(args.message_ids, [1337]);
});
global.with_stub(function (stub) {
override('unread_ops.process_read_messages_event', stub.f);

View File

@@ -37,12 +37,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
stream_list.update_streams_sidebar();
}
// TODO: Do this as a bulk process.
// We may need to change narrow too,
// but that maybe confusing to users.
for (const msg_id of msg_ids) {
ui.remove_message(msg_id);
}
ui.remove_messages(msg_ids);
break;
}

View File

@@ -114,16 +114,20 @@ 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;
}
for (const message_id of message_ids) {
const row = list.get_row(message_id);
if (row !== undefined) {
list.remove_and_rerender([{id: message_id}]);
msg_ids_to_rerender.push({id: message_id});
}
}
list.remove_and_rerender(msg_ids_to_rerender);
}
};
exports.show_failed_message_success = function (message_id) {