mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-57885: Do not mark channel as read on tab unload (#26811)
This was spurious code left from old times. It's not needed now, and it was causing a race condition with the server side where we were setting the status to offline on websocket disconnect. So if this request reached the server after the status was set to offline, the status would reset to online. https://mattermost.atlassian.net/browse/MM-57885 ```release-note Fixed a bug where status would incorrectly get stuck to online after user closes the tab. ```
This commit is contained in:
parent
20825101a4
commit
acfbcb92f6
@ -5,7 +5,7 @@ import {connect} from 'react-redux';
|
|||||||
import {bindActionCreators} from 'redux';
|
import {bindActionCreators} from 'redux';
|
||||||
import type {Dispatch} 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 {autoUpdateTimezone} from 'mattermost-redux/actions/timezone';
|
||||||
import {getChannel, getCurrentChannelId, isManuallyUnread} from 'mattermost-redux/selectors/entities/channels';
|
import {getChannel, getCurrentChannelId, isManuallyUnread} from 'mattermost-redux/selectors/entities/channels';
|
||||||
import {getLicense, getConfig} from 'mattermost-redux/selectors/entities/general';
|
import {getLicense, getConfig} from 'mattermost-redux/selectors/entities/general';
|
||||||
@ -60,7 +60,6 @@ function mapDispatchToProps(dispatch: Dispatch) {
|
|||||||
actions: bindActionCreators({
|
actions: bindActionCreators({
|
||||||
autoUpdateTimezone,
|
autoUpdateTimezone,
|
||||||
getChannelURLAction,
|
getChannelURLAction,
|
||||||
markChannelAsViewedOnServer,
|
|
||||||
updateApproximateViewTime,
|
updateApproximateViewTime,
|
||||||
}, dispatch),
|
}, dispatch),
|
||||||
};
|
};
|
||||||
|
@ -12,13 +12,24 @@ import BrowserStore from 'stores/browser_store';
|
|||||||
import LoggedIn from 'components/logged_in/logged_in';
|
import LoggedIn from 'components/logged_in/logged_in';
|
||||||
import type {Props} 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', () => ({
|
jest.mock('actions/websocket_actions.jsx', () => ({
|
||||||
initialize: jest.fn(),
|
initialize: jest.fn(),
|
||||||
|
close: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
BrowserStore.signalLogin = jest.fn();
|
BrowserStore.signalLogin = jest.fn();
|
||||||
|
|
||||||
describe('components/logged_in/LoggedIn', () => {
|
describe('components/logged_in/LoggedIn', () => {
|
||||||
|
const originalFetch = global.fetch;
|
||||||
|
beforeAll(() => {
|
||||||
|
global.fetch = jest.fn();
|
||||||
|
});
|
||||||
|
afterAll(() => {
|
||||||
|
global.fetch = originalFetch;
|
||||||
|
});
|
||||||
|
|
||||||
const children = <span>{'Test'}</span>;
|
const children = <span>{'Test'}</span>;
|
||||||
const baseProps: Props = {
|
const baseProps: Props = {
|
||||||
currentUser: {} as UserProfile,
|
currentUser: {} as UserProfile,
|
||||||
@ -26,7 +37,6 @@ describe('components/logged_in/LoggedIn', () => {
|
|||||||
actions: {
|
actions: {
|
||||||
autoUpdateTimezone: jest.fn(),
|
autoUpdateTimezone: jest.fn(),
|
||||||
getChannelURLAction: jest.fn(),
|
getChannelURLAction: jest.fn(),
|
||||||
markChannelAsViewedOnServer: jest.fn(),
|
|
||||||
updateApproximateViewTime: jest.fn(),
|
updateApproximateViewTime: jest.fn(),
|
||||||
},
|
},
|
||||||
isCurrentChannelManuallyUnread: false,
|
isCurrentChannelManuallyUnread: false,
|
||||||
@ -180,4 +190,18 @@ describe('components/logged_in/LoggedIn', () => {
|
|||||||
shallow(<LoggedIn {...props}>{children}</LoggedIn>);
|
shallow(<LoggedIn {...props}>{children}</LoggedIn>);
|
||||||
expect(obj.emitBrowserFocus).toBeCalledTimes(1);
|
expect(obj.emitBrowserFocus).toBeCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not make viewChannel call on unload', () => {
|
||||||
|
const props = {
|
||||||
|
...baseProps,
|
||||||
|
mfaRequired: false,
|
||||||
|
showTermsOfService: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
renderWithContext(<LoggedIn {...props}>{children}</LoggedIn>);
|
||||||
|
expect(screen.getByText('Test')).toBeInTheDocument();
|
||||||
|
|
||||||
|
fireEvent(window, new Event('beforeunload'));
|
||||||
|
expect(fetch).not.toHaveBeenCalledWith('/api/v4/channels/members/me/view');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -36,7 +36,6 @@ export type Props = {
|
|||||||
actions: {
|
actions: {
|
||||||
autoUpdateTimezone: (deviceTimezone: string) => void;
|
autoUpdateTimezone: (deviceTimezone: string) => void;
|
||||||
getChannelURLAction: (channelId: string, teamId: string, url: string) => void;
|
getChannelURLAction: (channelId: string, teamId: string, url: string) => void;
|
||||||
markChannelAsViewedOnServer: (channelId: string) => void;
|
|
||||||
updateApproximateViewTime: (channelId: string) => void;
|
updateApproximateViewTime: (channelId: string) => void;
|
||||||
};
|
};
|
||||||
showTermsOfService: boolean;
|
showTermsOfService: boolean;
|
||||||
@ -192,7 +191,6 @@ export default class LoggedIn extends React.PureComponent<Props> {
|
|||||||
window.removeEventListener('beforeunload', this.handleBeforeUnload);
|
window.removeEventListener('beforeunload', this.handleBeforeUnload);
|
||||||
if (document.cookie.indexOf('MMUSERID=') > -1 && this.props.currentChannelId && !this.props.isCurrentChannelManuallyUnread) {
|
if (document.cookie.indexOf('MMUSERID=') > -1 && this.props.currentChannelId && !this.props.isCurrentChannelManuallyUnread) {
|
||||||
this.props.actions.updateApproximateViewTime(this.props.currentChannelId);
|
this.props.actions.updateApproximateViewTime(this.props.currentChannelId);
|
||||||
this.props.actions.markChannelAsViewedOnServer(this.props.currentChannelId);
|
|
||||||
}
|
}
|
||||||
WebSocketActions.close();
|
WebSocketActions.close();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user