don’t iterate over list if no filter applied

thanks @chrisgarrity !
This commit is contained in:
Matthew Taylor 2017-09-19 17:11:46 -04:00
parent 8c631b40d9
commit a9cb7bbd99
2 changed files with 12 additions and 10 deletions

View file

@ -118,19 +118,21 @@ var Messages = React.createClass({
},
filterMessages: function (messages, typesAllowed, unreadCount) {
var filteredMessages = [];
for (var i in messages) {
// check to see if the position of the message in the list is earlier
// than the unread count. If it is, then the message is totally unread.
messages[i].unread = false;
if (i < unreadCount) messages[i].unread = true;
if (typesAllowed.length > 0) {
for (var i in messages) {
// check to see if the position of the message in the list is earlier
// than the unread count. If it is, then the message is totally unread.
messages[i].unread = false;
if (i < unreadCount) messages[i].unread = true;
if (typesAllowed.length > 0) {
if (typesAllowed.indexOf(messages[i].type) > -1) {
filteredMessages.push(messages[i]);
}
} else {
// if empty, then we're looking at all messages, so just like add the message
filteredMessages.push(messages[i]);
}
} else {
filteredMessages = messages;
for (var j = 0; j < unreadCount; j++) {
filteredMessages[j].unread = true;
}
}
return filteredMessages;

View file

@ -43,7 +43,7 @@ var SocialMessagesList = React.createClass({
};
},
getComponentForMessage: function (message) {
var className = (message.unread) ? 'mod-unread' : '';
var className = (message.unread === true) ? 'mod-unread' : '';
var key = message.type + '_' + message.id;
switch (message.type) {