mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 01:25:52 -05:00
don’t iterate over list if no filter applied
thanks @chrisgarrity !
This commit is contained in:
parent
8c631b40d9
commit
a9cb7bbd99
2 changed files with 12 additions and 10 deletions
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue