From d187399fcecb9f1390ec3f53d7b31d6e47ab5f1a Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Wed, 7 Feb 2018 09:25:05 -0500 Subject: [PATCH] ICU-653 Stopped filtering out join/leave messages about the current user (#1419) * ICU-653 Stopped filtering out join/leave messages about the current user * Switched redux back to master --- app/selectors/post_list.js | 18 +++++++-------- test/app/selectors/post_list.test.js | 34 +++++++++++++++++++++++++--- yarn.lock | 2 +- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/app/selectors/post_list.js b/app/selectors/post_list.js index 94e0187ff..37c8a672c 100644 --- a/app/selectors/post_list.js +++ b/app/selectors/post_list.js @@ -4,9 +4,9 @@ import {Posts, Preferences} from 'mattermost-redux/constants'; import {makeGetPostsForIds} from 'mattermost-redux/selectors/entities/posts'; import {getBool} from 'mattermost-redux/selectors/entities/preferences'; -import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; +import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; import {createIdsSelector} from 'mattermost-redux/utils/helpers'; -import {shouldFilterPost} from 'mattermost-redux/utils/post_utils'; +import {shouldFilterJoinLeavePost} from 'mattermost-redux/utils/post_utils'; export const DATE_LINE = 'date-'; export const START_OF_NEW_MESSAGES = 'start-of-new-messages'; @@ -26,10 +26,10 @@ export function makePreparePostIdsForPostList() { (state, props) => getMyPosts(state, props.postIds), (state, props) => props.lastViewedAt, (state, props) => props.indicateNewMessages, - getCurrentUserId, + getCurrentUser, shouldShowJoinLeaveMessages, - (posts, lastViewedAt, indicateNewMessages, currentUserId, showJoinLeave) => { - if (posts.length === 0) { + (posts, lastViewedAt, indicateNewMessages, currentUser, showJoinLeave) => { + if (posts.length === 0 || !currentUser) { return []; } @@ -38,18 +38,16 @@ export function makePreparePostIdsForPostList() { let lastDate = null; let addedNewMessagesIndicator = false; - const filterOptions = {showJoinLeave}; - // Iterating through the posts from oldest to newest for (let i = posts.length - 1; i >= 0; i--) { const post = posts[i]; - if (post.state === Posts.POST_DELETED && post.user_id === currentUserId) { + if (post.state === Posts.POST_DELETED && post.user_id === currentUser.id) { continue; } // Filter out join/leave messages if necessary - if (shouldFilterPost(post, filterOptions)) { + if (shouldFilterJoinLeavePost(post, showJoinLeave, currentUser.username)) { continue; } @@ -63,7 +61,7 @@ export function makePreparePostIdsForPostList() { } // Only add the new messages line if a lastViewedAt time is set - const postIsUnread = post.create_at > lastViewedAt && post.user_id !== currentUserId; + const postIsUnread = post.create_at > lastViewedAt && post.user_id !== currentUser.id; if (lastViewedAt !== null && !addedNewMessagesIndicator && postIsUnread && indicateNewMessages) { out.push(START_OF_NEW_MESSAGES); addedNewMessagesIndicator = true; diff --git a/test/app/selectors/post_list.test.js b/test/app/selectors/post_list.test.js index 18ddcd564..e7e58408a 100644 --- a/test/app/selectors/post_list.test.js +++ b/test/app/selectors/post_list.test.js @@ -29,7 +29,10 @@ describe('Selectors.PostList', () => { myPreferences: {} }, users: { - currentUserId: '1234' + currentUserId: '1234', + profiles: { + 1234: {id: '1234', username: 'user'} + } } } }; @@ -84,6 +87,25 @@ describe('Selectors.PostList', () => { now = preparePostIdsForPostList(state, {postIds, lastViewedAt, indicateNewMessages}); assert.deepEqual(removeDateLines(now), ['1001']); + + // always show join/leave posts for the current user + state = { + ...state, + entities: { + ...state.entities, + posts: { + ...state.entities.posts, + posts: { + ...state.entities.posts.posts, + 1002: {id: '1002', create_at: 1, type: Posts.POST_TYPES.JOIN_CHANNEL, props: {username: 'user'}} + } + } + } + }; + + now = preparePostIdsForPostList(state, {postIds, lastViewedAt, indicateNewMessages}); + + assert.deepEqual(removeDateLines(now), ['1002', '1001']); }); it('new messages indicator', () => { @@ -102,7 +124,10 @@ describe('Selectors.PostList', () => { myPreferences: {} }, users: { - currentUserId: '1234' + currentUserId: '1234', + profiles: { + 1234: {id: '1234', username: 'user'} + } } } }; @@ -149,7 +174,10 @@ describe('Selectors.PostList', () => { } }, users: { - currentUserId: '1234' + currentUserId: '1234', + profiles: { + 1234: {id: '1234', username: 'user'} + } } } }; diff --git a/yarn.lock b/yarn.lock index f0529af85..73e5df2db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3974,7 +3974,7 @@ makeerror@1.0.x: mattermost-redux@mattermost/mattermost-redux: version "1.1.0" - resolved "https://codeload.github.com/mattermost/mattermost-redux/tar.gz/7f2f352372a5ba587ed932c41eb550ba2cb1e94c" + resolved "https://codeload.github.com/mattermost/mattermost-redux/tar.gz/1e81d05145f439e3aedae779e6c749c2b93f0e08" dependencies: deep-equal "1.0.1" form-data "2.3.1"