app/selectors/post_list.js
// day indicators and an optional new message indicator.
day indicators and an optional new message indicator.
day indicators and an optional new message indicator .
function makePreparePostIdsForPostList() {
    const getMyPosts = makeGetPostsForIds();
    return createIdsSelector(
        (state, props) => getMyPosts(state, props.postIds),
        (state, props) => props.lastViewedAt,
        getCurrentUserId,
        shouldShowJoinLeaveMessages,
        (posts, lastViewedAt, currentUserId, showJoinLeave) => {
            const out = [];
            let lastDate = null;
            let addedNewMessagesIndicator = false;
            const filterOptions = {showJoinLeave};
            for (const post of posts) {
                if (post.state === Posts.POST_DELETED && post.user_id === currentUserId) {
                    continue;
                }
                if (shouldFilterPost(post, filterOptions)) {
                    continue;
                }
                if (lastViewedAt && !addedNewMessagesIndicator) {
                    const postIsUnread = post.create_at > lastViewedAt;
                    if (postIsUnread) {
                        out.push(START_OF_NEW_MESSAGES);
                        addedNewMessagesIndicator = true;
                    }
                }
                const postDate = new Date(post.create_at);
                if (lastDate && lastDate.toDateString() !== postDate.toDateString()) {
                    out.push(DATE_LINE + lastDate.toDateString());
                }
                lastDate = postDate;
                out.push(post.id);
            }
            if (lastDate) {
                out.push(DATE_LINE + lastDate.toDateString());
            }
            return out;
        }
    );
}
function makePreparePostIdsForPostList ( ) { const getMyPosts = makeGetPostsForIds ( ) ; return createIdsSelector ( ( state , props ) => getMyPosts ( state , props . postIds ) , ( state , props ) => props . lastViewedAt , getCurrentUserId , shouldShowJoinLeaveMessages , ( posts , lastViewedAt , currentUserId , showJoinLeave ) => { const out = [ ] ; let lastDate = null ; let addedNewMessagesIndicator = false ; const filterOptions = { showJoinLeave } ; for ( const post of posts ) { if ( post . state === Posts . POST_DELETED && post . user_id === currentUserId ) { continue ; } if ( shouldFilterPost ( post , filterOptions ) ) { continue ; } if ( lastViewedAt && ! addedNewMessagesIndicator ) { const postIsUnread = post . create_at > lastViewedAt ; if ( postIsUnread ) { out . push ( START_OF_NEW_MESSAGES ) ; addedNewMessagesIndicator = true ; } } const postDate = new Date ( post . create_at ) ; if ( lastDate && lastDate . toDateString ( ) !== postDate . toDateString ( ) ) { out . push ( DATE_LINE + lastDate . toDateString ( ) ) ; } lastDate = postDate ; out . push ( post . id ) ; } if ( lastDate ) { out . push ( DATE_LINE + lastDate . toDateString ( ) ) ; } return out ; } ) ; }
day indicators and an optional new message indicator.
day indicators and an optional new message indicator .
// Remember that we're iterating through the posts from newest to oldest // Filter out join/leave messages if necessary // Only add the new messages line if a lastViewedAt time is set // Push on a date header if the last post was on a different day than the current one // Push on the date header for the oldest post