diff --git a/webapp/channels/src/components/logged_in/index.ts b/webapp/channels/src/components/logged_in/index.ts index ebb093311f..3cb7f3120d 100644 --- a/webapp/channels/src/components/logged_in/index.ts +++ b/webapp/channels/src/components/logged_in/index.ts @@ -5,7 +5,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; import type {Dispatch} from 'redux'; -import {markChannelAsViewedOnServer, updateApproximateViewTime} from 'mattermost-redux/actions/channels'; +import {updateApproximateViewTime} from 'mattermost-redux/actions/channels'; import {autoUpdateTimezone} from 'mattermost-redux/actions/timezone'; import {getChannel, getCurrentChannelId, isManuallyUnread} from 'mattermost-redux/selectors/entities/channels'; import {getLicense, getConfig} from 'mattermost-redux/selectors/entities/general'; @@ -60,7 +60,6 @@ function mapDispatchToProps(dispatch: Dispatch) { actions: bindActionCreators({ autoUpdateTimezone, getChannelURLAction, - markChannelAsViewedOnServer, updateApproximateViewTime, }, dispatch), }; diff --git a/webapp/channels/src/components/logged_in/logged_in.test.tsx b/webapp/channels/src/components/logged_in/logged_in.test.tsx index 7decebd8a5..13527b7599 100644 --- a/webapp/channels/src/components/logged_in/logged_in.test.tsx +++ b/webapp/channels/src/components/logged_in/logged_in.test.tsx @@ -12,13 +12,24 @@ import BrowserStore from 'stores/browser_store'; import LoggedIn from 'components/logged_in/logged_in'; import type {Props} from 'components/logged_in/logged_in'; +import {fireEvent, renderWithContext, screen} from 'tests/react_testing_utils'; + jest.mock('actions/websocket_actions.jsx', () => ({ initialize: jest.fn(), + close: jest.fn(), })); BrowserStore.signalLogin = jest.fn(); describe('components/logged_in/LoggedIn', () => { + const originalFetch = global.fetch; + beforeAll(() => { + global.fetch = jest.fn(); + }); + afterAll(() => { + global.fetch = originalFetch; + }); + const children = {'Test'}; const baseProps: Props = { currentUser: {} as UserProfile, @@ -26,7 +37,6 @@ describe('components/logged_in/LoggedIn', () => { actions: { autoUpdateTimezone: jest.fn(), getChannelURLAction: jest.fn(), - markChannelAsViewedOnServer: jest.fn(), updateApproximateViewTime: jest.fn(), }, isCurrentChannelManuallyUnread: false, @@ -180,4 +190,18 @@ describe('components/logged_in/LoggedIn', () => { shallow({children}); expect(obj.emitBrowserFocus).toBeCalledTimes(1); }); + + it('should not make viewChannel call on unload', () => { + const props = { + ...baseProps, + mfaRequired: false, + showTermsOfService: false, + }; + + renderWithContext({children}); + expect(screen.getByText('Test')).toBeInTheDocument(); + + fireEvent(window, new Event('beforeunload')); + expect(fetch).not.toHaveBeenCalledWith('/api/v4/channels/members/me/view'); + }); }); diff --git a/webapp/channels/src/components/logged_in/logged_in.tsx b/webapp/channels/src/components/logged_in/logged_in.tsx index 1dc253e602..bbed0befae 100644 --- a/webapp/channels/src/components/logged_in/logged_in.tsx +++ b/webapp/channels/src/components/logged_in/logged_in.tsx @@ -36,7 +36,6 @@ export type Props = { actions: { autoUpdateTimezone: (deviceTimezone: string) => void; getChannelURLAction: (channelId: string, teamId: string, url: string) => void; - markChannelAsViewedOnServer: (channelId: string) => void; updateApproximateViewTime: (channelId: string) => void; }; showTermsOfService: boolean; @@ -192,7 +191,6 @@ export default class LoggedIn extends React.PureComponent { window.removeEventListener('beforeunload', this.handleBeforeUnload); if (document.cookie.indexOf('MMUSERID=') > -1 && this.props.currentChannelId && !this.props.isCurrentChannelManuallyUnread) { this.props.actions.updateApproximateViewTime(this.props.currentChannelId); - this.props.actions.markChannelAsViewedOnServer(this.props.currentChannelId); } WebSocketActions.close(); };