From e73ed03802790fbc0222d02f446ce8ee85435b41 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Fri, 8 Jun 2018 05:14:42 +0800 Subject: [PATCH] MM-10340 Fix "More New Messages Above" that appears on top of the channel after joining (#1710) * Replace "More New Messages Above" with "New Messages" that appears on top of the channel after joining Signed-off-by: Saturnino Abril * add conditions in adding entry of start of new messages in preparing post IDs for post list * remove post unread for user joinining the channel * refactor and remove unnecessary conditional check * fix and add test cases --- app/selectors/post_list.js | 10 +++++++--- app/selectors/post_list.test.js | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/selectors/post_list.js b/app/selectors/post_list.js index a8e7c447c..272903edb 100644 --- a/app/selectors/post_list.js +++ b/app/selectors/post_list.js @@ -65,9 +65,13 @@ export function makePreparePostIdsForPostList() { lastDate = postDate; } - // Only add the new messages line if a lastViewedAt time is set - const postIsUnread = post.create_at > lastViewedAt && post.user_id !== currentUser.id; - if (lastViewedAt !== null && !addedNewMessagesIndicator && postIsUnread && indicateNewMessages) { + if ( + lastViewedAt && + post.create_at > lastViewedAt && + post.user_id !== currentUser.id && + !addedNewMessagesIndicator && + indicateNewMessages + ) { out.push(START_OF_NEW_MESSAGES); addedNewMessagesIndicator = true; } diff --git a/app/selectors/post_list.test.js b/app/selectors/post_list.test.js index a5cd0b5e4..68d99bd2e 100644 --- a/app/selectors/post_list.test.js +++ b/app/selectors/post_list.test.js @@ -136,14 +136,27 @@ describe('Selectors.PostList', () => { const postIds = ['1010', '1005', '1000']; // Remember that we list the posts backwards - // Show new messages indicator before all posts + // Do not show new messages indicator before all posts let now = preparePostIdsForPostList(state, {postIds, lastViewedAt: 0, indicateNewMessages: true}); + assert.deepEqual(removeDateLines(now), ['1010', '1005', '1000']); + + now = preparePostIdsForPostList(state, {postIds, indicateNewMessages: true}); + assert.deepEqual(removeDateLines(now), ['1010', '1005', '1000']); + + now = preparePostIdsForPostList(state, {postIds, lastViewedAt: 999, indicateNewMessages: false}); + assert.deepEqual(removeDateLines(now), ['1010', '1005', '1000']); + + // Show new messages indicator before all posts + now = preparePostIdsForPostList(state, {postIds, lastViewedAt: 999, indicateNewMessages: true}); assert.deepEqual(removeDateLines(now), ['1010', '1005', '1000', START_OF_NEW_MESSAGES]); // Show indicator between posts now = preparePostIdsForPostList(state, {postIds, lastViewedAt: 1003, indicateNewMessages: true}); assert.deepEqual(removeDateLines(now), ['1010', '1005', START_OF_NEW_MESSAGES, '1000']); + now = preparePostIdsForPostList(state, {postIds, lastViewedAt: 1006, indicateNewMessages: true}); + assert.deepEqual(removeDateLines(now), ['1010', START_OF_NEW_MESSAGES, '1005', '1000']); + // Don't show indicator when all posts are read now = preparePostIdsForPostList(state, {postIds, lastViewedAt: 1020}); assert.deepEqual(removeDateLines(now), ['1010', '1005', '1000']);