From 9f8ff45eddcdf0f064e4e0f5865b1d678ca5f74f Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Fri, 8 Jan 2021 20:45:17 +0100 Subject: [PATCH] MM-31189 Revert New Messages toast PRs (#7292) (#7301) Automatic Merge --- components/toast_wrapper/toast_wrapper.jsx | 38 +++++++++---------- .../toast_wrapper/toast_wrapper.test.jsx | 19 +--------- 2 files changed, 18 insertions(+), 39 deletions(-) diff --git a/components/toast_wrapper/toast_wrapper.jsx b/components/toast_wrapper/toast_wrapper.jsx index fa0fec78e944..abfc4888c7a4 100644 --- a/components/toast_wrapper/toast_wrapper.jsx +++ b/components/toast_wrapper/toast_wrapper.jsx @@ -14,7 +14,6 @@ import Constants from 'utils/constants'; import {browserHistory} from 'utils/browser_history'; const TOAST_TEXT_COLLAPSE_WIDTH = 500; -const THRESHOLD_FROM_BOTTOM = 1000; const TOAST_REL_RANGES = [ RelativeRanges.TODAY_YESTERDAY, @@ -88,28 +87,25 @@ class ToastWrapper extends React.PureComponent { } else { unreadCount = prevState.unreadCountInChannel + props.newRecentMessagesCount; } - if (props.atBottom !== null) { - // show unread toast on mount when channel is not at bottom and unread count greater than 0 - if (typeof showUnreadToast === 'undefined') { - showUnreadToast = unreadCount > 0 && props.initScrollOffsetFromBottom > THRESHOLD_FROM_BOTTOM; - } - if (typeof showMessageHistoryToast === 'undefined' && props.focusedPostId !== '') { - showMessageHistoryToast = props.initScrollOffsetFromBottom > THRESHOLD_FROM_BOTTOM || !props.atLatestPost; - } + // show unread toast on mount when channel is not at bottom and unread count greater than 0 + if (typeof showUnreadToast === 'undefined' && props.atBottom !== null) { + showUnreadToast = unreadCount > 0 && !props.atBottom; + } - 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; - } - } + if (typeof showMessageHistoryToast === 'undefined' && props.focusedPostId !== '' && props.atBottom !== null) { + showMessageHistoryToast = props.initScrollOffsetFromBottom > 1000 || !props.atLatestPost; + } + + // show unread toast when a channel is marked as unread + if (props.channelMarkedAsUnread && !props.atBottom && !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 && !props.atBottom) { + showUnreadToast = true; } if (!showUnreadToast && unreadCount > 0 && !props.atBottom && (props.lastViewedBottom < props.latestPostTimeStamp)) { diff --git a/components/toast_wrapper/toast_wrapper.test.jsx b/components/toast_wrapper/toast_wrapper.test.jsx index 8ad6cc4f7ae4..40866915a4fa 100644 --- a/components/toast_wrapper/toast_wrapper.test.jsx +++ b/components/toast_wrapper/toast_wrapper.test.jsx @@ -88,28 +88,16 @@ describe('components/ToastWrapper', () => { }); describe('toasts state', () => { - test('Should have unread toast if unreadCount > 0 and initScrollOffsetFromBottom is greater than 1000', () => { + test('Should have unread toast if unreadCount > 0', () => { const props = { ...baseProps, unreadCountInChannel: 10, newRecentMessagesCount: 5, - initScrollOffsetFromBottom: 1100, }; const wrapper = shallowWithIntl(); expect(wrapper.state('showUnreadToast')).toBe(true); }); - test('Should have not have unread toast if initScrollOffsetFromBottom is less than 1000', () => { - const props = { - ...baseProps, - unreadCountInChannel: 10, - newRecentMessagesCount: 5, - initScrollOffsetFromBottom: 850, - }; - - const wrapper = shallowWithIntl(); - expect(wrapper.state('showUnreadToast')).toBe(false); - }); test('Should set state of have unread toast when atBottom changes from undefined', () => { const props = { @@ -117,7 +105,6 @@ describe('components/ToastWrapper', () => { unreadCountInChannel: 10, newRecentMessagesCount: 5, atBottom: null, - initScrollOffsetFromBottom: 1100, }; const wrapper = shallowWithIntl(); @@ -254,7 +241,6 @@ describe('components/ToastWrapper', () => { 'post4', 'post5', ], - initScrollOffsetFromBottom: 1220, }; const wrapper = shallowWithIntl(); @@ -312,7 +298,6 @@ describe('components/ToastWrapper', () => { 'post4', 'post5', ], - initScrollOffsetFromBottom: 1005, }; const wrapper = shallowWithIntl(); @@ -360,7 +345,6 @@ describe('components/ToastWrapper', () => { 'post4', 'post5', ], - initScrollOffsetFromBottom: 1500, }; const wrapper = shallowWithIntl(); @@ -421,7 +405,6 @@ describe('components/ToastWrapper', () => { ...baseProps, unreadCountInChannel: 10, newRecentMessagesCount: 5, - initScrollOffsetFromBottom: 1008, }; const updateToastStatus = baseProps.actions.updateToastStatus;