message list: Update `MessageListData` API by extracting `reorder_messages`.

`change_message_id` in `message_list_data.js` is only called from
one place, the `change_message_id` function in `message_list.js`.
This commit is contained in:
Ryan Rehman 2020-07-05 00:15:29 +05:30 committed by Tim Abbott
parent 66dc712830
commit 7a8ebfb5eb
1 changed files with 29 additions and 26 deletions

View File

@ -502,8 +502,6 @@ MessageListData.prototype = {
change_message_id: function (old_id, new_id, opts) {
// Update our local cache that uses the old id to the new id
function message_sort_func(a, b) {return a.id - b.id;}
if (this._hash.has(old_id)) {
const msg = this._hash.get(old_id);
this._hash.delete(old_id);
@ -523,9 +521,15 @@ MessageListData.prototype = {
this._selected_id = new_id;
}
setTimeout(() => {
this.reorder_messages(new_id, opts);
}, 0);
},
reorder_messages: function (new_id, opts) {
function message_sort_func(a, b) {return a.id - b.id;}
// If this message is now out of order, re-order and re-render
const self = this;
setTimeout(() => {
const current_message = self._hash.get(new_id);
const index = self._items.indexOf(current_message);
@ -551,7 +555,6 @@ MessageListData.prototype = {
opts.re_render();
}
}, 0);
},
get_last_message_sent_by_me: function () {