Skip to content

Commit

Permalink
MM-29929 Fix for unread messages toast on marking channel as unread (m…
Browse files Browse the repository at this point in the history
…attermost#7028)

* 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
  • Loading branch information
sudheerDev committed Nov 6, 2020
1 parent e56a42d commit 92f5d86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
20 changes: 11 additions & 9 deletions components/toast_wrapper/toast_wrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions components/toast_wrapper/toast_wrapper.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('components/ToastWrapper', () => {
const wrapper = shallowWithIntl(<ToastWrapper {...props}/>);
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', () => {
Expand All @@ -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', () => {
Expand Down

0 comments on commit 92f5d86

Please sign in to comment.