From e1ee205b37c325734ce112d4421b76a7e0fc3de2 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Fri, 6 Nov 2020 21:06:57 +0100 Subject: [PATCH] MM-29929 Fix for unread messages toast on marking channel as unread (#7028) (#7032) * The initOffset we use for displaying toast should be only used mount as that is not a relative scroll position and is only set on mount * Changing this to show unread toast on all occasions of marking channel as unread other than channel at bottom (cherry picked from commit 92f5d86dd092d1495a98ce9297cea7be88f5f6fe) Co-authored-by: Sudheer --- components/toast_wrapper/toast_wrapper.jsx | 20 ++++++++++--------- .../toast_wrapper/toast_wrapper.test.jsx | 6 +++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/components/toast_wrapper/toast_wrapper.jsx b/components/toast_wrapper/toast_wrapper.jsx index fdaefcc4a7d5..fa0fec78e944 100644 --- a/components/toast_wrapper/toast_wrapper.jsx +++ b/components/toast_wrapper/toast_wrapper.jsx @@ -98,15 +98,17 @@ class ToastWrapper extends React.PureComponent { showMessageHistoryToast = props.initScrollOffsetFromBottom > THRESHOLD_FROM_BOTTOM || !props.atLatestPost; } - // show unread toast when a channel is marked as unread - if (props.channelMarkedAsUnread && !prevState.channelMarkedAsUnread && !prevState.showUnreadToast) { - showUnreadToast = props.initScrollOffsetFromBottom > THRESHOLD_FROM_BOTTOM; - } - - // show unread toast when a channel is remarked as unread using the change in lastViewedAt - // lastViewedAt changes only if a channel is remarked as unread in channelMarkedAsUnread state - if (props.channelMarkedAsUnread && props.lastViewedAt !== prevState.lastViewedAt) { - showUnreadToast = props.initScrollOffsetFromBottom > THRESHOLD_FROM_BOTTOM; + if (!props.atBottom) { + // show unread toast when a channel is marked as unread + if (props.channelMarkedAsUnread && !prevState.channelMarkedAsUnread && !prevState.showUnreadToast) { + showUnreadToast = true; + } + + // show unread toast when a channel is remarked as unread using the change in lastViewedAt + // lastViewedAt changes only if a channel is remarked as unread in channelMarkedAsUnread state + if (props.channelMarkedAsUnread && props.lastViewedAt !== prevState.lastViewedAt) { + showUnreadToast = true; + } } } diff --git a/components/toast_wrapper/toast_wrapper.test.jsx b/components/toast_wrapper/toast_wrapper.test.jsx index ceea3d3bd04d..8ad6cc4f7ae4 100644 --- a/components/toast_wrapper/toast_wrapper.test.jsx +++ b/components/toast_wrapper/toast_wrapper.test.jsx @@ -145,7 +145,7 @@ describe('components/ToastWrapper', () => { const wrapper = shallowWithIntl(); expect(wrapper.state('showUnreadToast')).toBe(false); wrapper.setProps({channelMarkedAsUnread: true, atBottom: false}); - expect(wrapper.state('showUnreadToast')).toBe(false); + expect(wrapper.state('showUnreadToast')).toBe(true); }); test('Should have unread toast channel is marked as unread again', () => { @@ -170,12 +170,12 @@ describe('components/ToastWrapper', () => { ], }); - expect(wrapper.state('showUnreadToast')).toBe(false); + expect(wrapper.state('showUnreadToast')).toBe(true); wrapper.setProps({atBottom: true}); expect(wrapper.state('showUnreadToast')).toBe(false); wrapper.setProps({atBottom: false}); wrapper.setProps({lastViewedAt: 12342}); - expect(wrapper.state('showUnreadToast')).toBe(false); + expect(wrapper.state('showUnreadToast')).toBe(true); }); test('Should have archive toast if channel is not atLatestPost and focusedPostId exists', () => {