refactor: Extract MessageListView._put_row().

Saving row data in `_rows` is a very data-specific task,
unlike the rest of `_post_process`, plus extracting it
will help with unit testing.
This commit is contained in:
Steve Howell 2018-07-12 16:29:29 +00:00 committed by Tim Abbott
parent 3d853f9bf4
commit 6b2c291b4e
1 changed files with 13 additions and 5 deletions

View File

@ -393,6 +393,17 @@ MessageListView.prototype = {
return message_actions;
},
_put_row: function (dom_row) {
var row = $(dom_row);
// Save DOM elements by id into self._rows for O(1) lookup.
// These can be used by get_row later, which re-wraps them
// inside jQuery objects.
if (row.hasClass('message_row')) {
this._rows[row.attr('zid')] = dom_row;
}
},
_post_process: function ($message_rows) {
// $message_rows wraps one or more message rows
@ -403,6 +414,8 @@ MessageListView.prototype = {
var self = this;
_.each($message_rows, function (dom_row) {
self._put_row(dom_row);
var row = $(dom_row);
var content = row.find('.message_content');
@ -411,11 +424,6 @@ MessageListView.prototype = {
content.addClass('rtl');
}
// Save DOM elements by id into self._rows for O(1) lookup
if (row.hasClass('message_row')) {
self._rows[row.attr('zid')] = dom_row;
}
if (row.hasClass('mention')) {
row.find('.user-mention').each(function () {
// We give special highlights to the mention buttons