From 8c631b40d926bda5e0001695b35900322c84eb8f Mon Sep 17 00:00:00 2001 From: Matthew Taylor Date: Tue, 19 Sep 2017 10:13:52 -0400 Subject: [PATCH] add `unread` as a key/value on each message This fixes #1545 by adding unread as a key/value on each message during the filtering process. This means the unread count is always applied to the list of full messages, and never to a subset (as was happening before to cause #1545). --- src/views/messages/container.jsx | 23 +++++++++++++++++------ src/views/messages/presentation.jsx | 14 +++++--------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/views/messages/container.jsx b/src/views/messages/container.jsx index fbcf4e590..91ea7574c 100644 --- a/src/views/messages/container.jsx +++ b/src/views/messages/container.jsx @@ -116,10 +116,20 @@ var Messages = React.createClass({ ) ); }, - filterMessages: function (messages, typesAllowed) { + filterMessages: function (messages, typesAllowed, unreadCount) { var filteredMessages = []; for (var i in messages) { - if (typesAllowed.indexOf(messages[i].type) > -1) { + // 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]); } } @@ -131,10 +141,11 @@ var Messages = React.createClass({ loadMore = false; } - var messages = this.props.messages; - if (this.state.filterValues.length > 0) { - messages = this.filterMessages(messages, this.state.filterValues); - } + var messages = this.filterMessages( + this.props.messages, + this.state.filterValues, + this.props.numNewMessages + ); return( ; } }, - renderSocialMessages: function (messages, unreadCount) { + renderSocialMessages: function (messages) { var messageList = []; for (var i in messages) { - if (i <= unreadCount) { - messageList.push(this.getComponentForMessage(messages[i], true)); - } else { - messageList.push(this.getComponentForMessage(messages[i], false)); - } + messageList.push(this.getComponentForMessage(messages[i])); } return messageList; }, @@ -195,7 +191,7 @@ var SocialMessagesList = React.createClass({ , , this.renderLoadMore(this.props.loadMore) ] : []}