mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-06-04 08:54:02 -04: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
src/views/messages
|
@ -118,19 +118,21 @@ var Messages = React.createClass({
|
||||||
},
|
},
|
||||||
filterMessages: function (messages, typesAllowed, unreadCount) {
|
filterMessages: function (messages, typesAllowed, unreadCount) {
|
||||||
var filteredMessages = [];
|
var filteredMessages = [];
|
||||||
for (var i in messages) {
|
if (typesAllowed.length > 0) {
|
||||||
// check to see if the position of the message in the list is earlier
|
for (var i in messages) {
|
||||||
// than the unread count. If it is, then the message is totally unread.
|
// check to see if the position of the message in the list is earlier
|
||||||
messages[i].unread = false;
|
// than the unread count. If it is, then the message is totally unread.
|
||||||
if (i < unreadCount) messages[i].unread = true;
|
messages[i].unread = false;
|
||||||
|
if (i < unreadCount) messages[i].unread = true;
|
||||||
|
|
||||||
if (typesAllowed.length > 0) {
|
|
||||||
if (typesAllowed.indexOf(messages[i].type) > -1) {
|
if (typesAllowed.indexOf(messages[i].type) > -1) {
|
||||||
filteredMessages.push(messages[i]);
|
filteredMessages.push(messages[i]);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
// if empty, then we're looking at all messages, so just like add the message
|
} else {
|
||||||
filteredMessages.push(messages[i]);
|
filteredMessages = messages;
|
||||||
|
for (var j = 0; j < unreadCount; j++) {
|
||||||
|
filteredMessages[j].unread = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredMessages;
|
return filteredMessages;
|
||||||
|
|
|
@ -43,7 +43,7 @@ var SocialMessagesList = React.createClass({
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getComponentForMessage: function (message) {
|
getComponentForMessage: function (message) {
|
||||||
var className = (message.unread) ? 'mod-unread' : '';
|
var className = (message.unread === true) ? 'mod-unread' : '';
|
||||||
var key = message.type + '_' + message.id;
|
var key = message.type + '_' + message.id;
|
||||||
|
|
||||||
switch (message.type) {
|
switch (message.type) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue