diff --git a/webapp/channels/src/actions/status_actions.test.ts b/webapp/channels/src/actions/status_actions.test.ts index 61dcecb3d8..20d50398b2 100644 --- a/webapp/channels/src/actions/status_actions.test.ts +++ b/webapp/channels/src/actions/status_actions.test.ts @@ -87,26 +87,26 @@ describe('actions/status_actions', () => { test('load statuses with posts in channel and user in sidebar', () => { const state = cloneDeep(initialState); const testStore = mockStore(state); - testStore.dispatch(Actions.addVisibleUsersInCurrentChannelToStatusPoll()); + testStore.dispatch(Actions.addVisibleUsersInCurrentChannelAndSelfToStatusPoll()); expect(addUserIdsForStatusFetchingPoll).toHaveBeenCalled(); - expect(addUserIdsForStatusFetchingPoll).toHaveBeenCalledWith(['user_id2', 'user_id3']); + expect(addUserIdsForStatusFetchingPoll).toHaveBeenCalledWith(['user_id2', 'user_id3', 'current_user_id']); }); test('load statuses with empty channel and user in sidebar', () => { const state = cloneDeep(initialState); state.entities.channels.currentChannelId = 'channel_id2'; const testStore = mockStore(state); - testStore.dispatch(Actions.addVisibleUsersInCurrentChannelToStatusPoll()); - expect(addUserIdsForStatusFetchingPoll).toHaveBeenCalledWith(['user_id3']); + testStore.dispatch(Actions.addVisibleUsersInCurrentChannelAndSelfToStatusPoll()); + expect(addUserIdsForStatusFetchingPoll).toHaveBeenCalledWith(['user_id3', 'current_user_id']); }); - test('load statuses with empty channel and no users in sidebar', () => { + test('load statuses with empty channel and no users in sidebar, should only fetch current user\'s status', () => { const state = cloneDeep(initialState); state.entities.channels.currentChannelId = 'channel_id2'; state.entities.preferences.myPreferences = {}; const testStore = mockStore(state); - testStore.dispatch(Actions.addVisibleUsersInCurrentChannelToStatusPoll()); - expect(addUserIdsForStatusFetchingPoll).not.toHaveBeenCalled(); + testStore.dispatch(Actions.addVisibleUsersInCurrentChannelAndSelfToStatusPoll()); + expect(addUserIdsForStatusFetchingPoll).toHaveBeenCalledWith(['current_user_id']); }); }); diff --git a/webapp/channels/src/actions/status_actions.ts b/webapp/channels/src/actions/status_actions.ts index cf4b6d72a7..3935d3f413 100644 --- a/webapp/channels/src/actions/status_actions.ts +++ b/webapp/channels/src/actions/status_actions.ts @@ -17,10 +17,12 @@ import {loadCustomEmojisForCustomStatusesByUserIds} from 'actions/emoji_actions' import type {GlobalState} from 'types/store'; /** - * Adds all the visible users of the current channel i.e users who have recently posted in the current channel - * and users who have DMs open with the current user to the status pool for fetching their statuses. + * Adds the following users to the status pool for fetching their statuses: + * - All users of current channel with recent posts. + * - All users who have DMs open with the current user. + * - The current user. */ -export function addVisibleUsersInCurrentChannelToStatusPoll(): ActionFunc { +export function addVisibleUsersInCurrentChannelAndSelfToStatusPoll(): ActionFunc { return (dispatch, getState) => { const state = getState(); const currentUserId = getCurrentUserId(state); @@ -49,6 +51,9 @@ export function addVisibleUsersInCurrentChannelToStatusPoll(): ActionFunc 0) { diff --git a/webapp/channels/src/actions/websocket_actions.jsx b/webapp/channels/src/actions/websocket_actions.jsx index aaf8d9ece7..2b93208f68 100644 --- a/webapp/channels/src/actions/websocket_actions.jsx +++ b/webapp/channels/src/actions/websocket_actions.jsx @@ -246,7 +246,7 @@ export function reconnect() { const enabledUserStatuses = getIsUserStatusesConfigEnabled(state); if (enabledUserStatuses) { - dispatch(StatusActions.addVisibleUsersInCurrentChannelToStatusPoll()); + dispatch(StatusActions.addVisibleUsersInCurrentChannelAndSelfToStatusPoll()); } const crtEnabled = isCollapsedThreadsEnabled(state); diff --git a/webapp/channels/src/components/channel_layout/channel_controller.test.tsx b/webapp/channels/src/components/channel_layout/channel_controller.test.tsx index 8e35fa0c85..6f53beb10c 100644 --- a/webapp/channels/src/components/channel_layout/channel_controller.test.tsx +++ b/webapp/channels/src/components/channel_layout/channel_controller.test.tsx @@ -26,7 +26,7 @@ jest.mock('components/product_notices_modal', () => () =>
); jest.mock('plugins/pluggable', () => () =>
); jest.mock('actions/status_actions', () => ({ - addVisibleUsersInCurrentChannelToStatusPoll: jest.fn().mockImplementation(() => () => {}), + addVisibleUsersInCurrentChannelAndSelfToStatusPoll: jest.fn().mockImplementation(() => () => {}), })); jest.mock('mattermost-redux/selectors/entities/general', () => ({ @@ -50,7 +50,7 @@ describe('ChannelController', () => { jest.useFakeTimers(); }); - it('dispatches addVisibleUsersInCurrentChannelToStatusPoll when enableUserStatuses is true', () => { + it('dispatches addVisibleUsersInCurrentChannelAndSelfToStatusPoll when enableUserStatuses is true', () => { mockState.entities.general.config.EnableUserStatuses = 'true'; const store = mockStore(mockState); @@ -64,10 +64,10 @@ describe('ChannelController', () => { jest.advanceTimersByTime(Constants.STATUS_INTERVAL); }); - expect(actions.addVisibleUsersInCurrentChannelToStatusPoll).toHaveBeenCalled(); + expect(actions.addVisibleUsersInCurrentChannelAndSelfToStatusPoll).toHaveBeenCalled(); }); - it('does not dispatch addVisibleUsersInCurrentChannelToStatusPoll when enableUserStatuses is false', () => { + it('does not dispatch addVisibleUsersInCurrentChannelAndSelfToStatusPoll when enableUserStatuses is false', () => { const store = mockStore(mockState); mockState.entities.general.config.EnableUserStatuses = 'false'; @@ -81,7 +81,7 @@ describe('ChannelController', () => { jest.advanceTimersByTime(Constants.STATUS_INTERVAL); }); - expect(actions.addVisibleUsersInCurrentChannelToStatusPoll).not.toHaveBeenCalled(); + expect(actions.addVisibleUsersInCurrentChannelAndSelfToStatusPoll).not.toHaveBeenCalled(); }); }); diff --git a/webapp/channels/src/components/channel_layout/channel_controller.tsx b/webapp/channels/src/components/channel_layout/channel_controller.tsx index a1243f3965..7836c213ad 100644 --- a/webapp/channels/src/components/channel_layout/channel_controller.tsx +++ b/webapp/channels/src/components/channel_layout/channel_controller.tsx @@ -8,7 +8,7 @@ import {useDispatch, useSelector} from 'react-redux'; import {cleanUpStatusAndProfileFetchingPoll} from 'mattermost-redux/actions/status_profile_polling'; import {getIsUserStatusesConfigEnabled} from 'mattermost-redux/selectors/entities/common'; -import {addVisibleUsersInCurrentChannelToStatusPoll} from 'actions/status_actions'; +import {addVisibleUsersInCurrentChannelAndSelfToStatusPoll} from 'actions/status_actions'; import {makeAsyncComponent} from 'components/async_load'; import CenterChannel from 'components/channel_layout/center_channel'; @@ -51,11 +51,13 @@ export default function ChannelController(props: Props) { }; }, []); + // Starts a regular interval to fetch statuses of users. + // see function "addVisibleUsersInCurrentChannelAndSelfToStatusPoll" for more details on which user's statuses are fetched. useEffect(() => { let loadStatusesIntervalId: NodeJS.Timeout; if (enabledUserStatuses) { loadStatusesIntervalId = setInterval(() => { - dispatch(addVisibleUsersInCurrentChannelToStatusPoll()); + dispatch(addVisibleUsersInCurrentChannelAndSelfToStatusPoll()); }, Constants.STATUS_INTERVAL); } diff --git a/webapp/channels/src/components/team_controller/actions/index.ts b/webapp/channels/src/components/team_controller/actions/index.ts index 13e0d866fe..a7ad3fef1b 100644 --- a/webapp/channels/src/components/team_controller/actions/index.ts +++ b/webapp/channels/src/components/team_controller/actions/index.ts @@ -16,7 +16,7 @@ import {isCustomGroupsEnabled} from 'mattermost-redux/selectors/entities/prefere import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; import type {ActionFuncAsync} from 'mattermost-redux/types/actions'; -import {addVisibleUsersInCurrentChannelToStatusPoll} from 'actions/status_actions'; +import {addVisibleUsersInCurrentChannelAndSelfToStatusPoll} from 'actions/status_actions'; import {addUserToTeam} from 'actions/team_actions'; import LocalStorageStore from 'stores/local_storage_store'; @@ -41,7 +41,7 @@ export function initializeTeam(team: Team): ActionFuncAsync { const enabledUserStatuses = getIsUserStatusesConfigEnabled(state); if (enabledUserStatuses) { - dispatch(addVisibleUsersInCurrentChannelToStatusPoll()); + dispatch(addVisibleUsersInCurrentChannelAndSelfToStatusPoll()); } const license = getLicense(state);