mirror of https://github.com/zulip/zulip.git
Add message_list.remove_and_rerender
(imported from commit 68da0ad74f797fae3257577bbf415fd1fe9488a6)
This commit is contained in:
parent
76892c52aa
commit
685ab1a583
|
@ -406,6 +406,32 @@ MessageList.prototype = {
|
|||
this.view.rerender_the_whole_thing();
|
||||
},
|
||||
|
||||
remove_and_rerender: function MessageList_remove_and_rerender(messages) {
|
||||
var self = this;
|
||||
_.each(messages, function (message) {
|
||||
var stored_message = self._hash[message.id];
|
||||
if (stored_message !== undefined) {
|
||||
delete self._hash[stored_message];
|
||||
}
|
||||
});
|
||||
|
||||
var msg_ids_to_remove = {};
|
||||
_.each(messages, function (message) {
|
||||
msg_ids_to_remove[message.id] = true;
|
||||
});
|
||||
this._items = _.filter(this._items, function (message) {
|
||||
return !msg_ids_to_remove.hasOwnProperty(message.id);
|
||||
});
|
||||
if (this.muting_enabled) {
|
||||
this._all_items = _.filter(this._all_items, function (message) {
|
||||
return !msg_ids_to_remove.hasOwnProperty(message.id);
|
||||
});
|
||||
}
|
||||
|
||||
this.view.rerender_the_whole_thing();
|
||||
this.select_id(this.selected_id(), {use_closest: true, empty_ok: true});
|
||||
},
|
||||
|
||||
show_edit_message: function MessageList_show_edit_message(row, edit_obj) {
|
||||
row.find(".message_edit_form").empty().append(edit_obj.form);
|
||||
row.find(".message_content").hide();
|
||||
|
|
|
@ -96,8 +96,14 @@ var MessageList = require('js/message_list');
|
|||
list.append(new_messages, true);
|
||||
assert.equal(list.last().id, 90);
|
||||
|
||||
|
||||
list.view.clear_table = function () {};
|
||||
|
||||
list.remove_and_rerender([{id: 60}]);
|
||||
var removed = list.all().filter(function (msg) {
|
||||
return msg.id !== 60;
|
||||
});
|
||||
assert.deepEqual(list.all(), removed);
|
||||
|
||||
list.clear();
|
||||
assert.deepEqual(list.all(), []);
|
||||
|
||||
|
|
Loading…
Reference in New Issue