diff --git a/webapp/channels/src/actions/channel_actions.test.ts b/webapp/channels/src/actions/channel_actions.test.ts index 499a1c10d2..5917dee97a 100644 --- a/webapp/channels/src/actions/channel_actions.test.ts +++ b/webapp/channels/src/actions/channel_actions.test.ts @@ -2,7 +2,6 @@ // See LICENSE.txt for license information. import { - searchMoreChannels, addUsersToChannel, openDirectChannelToUserId, openGroupChannelToUserIds, @@ -142,24 +141,6 @@ describe('Actions.Channel', () => { expect(loadProfilesForSidebar).toHaveBeenCalledTimes(1); }); - test('searchMoreChannels', async () => { - const testStore = await mockStore(initialState); - - const expectedActions = [{ - type: 'MOCK_SEARCH_CHANNELS', - data: [{ - id: 'channel-id', - name: 'channel-name', - display_name: 'Channel', - delete_at: 0, - type: 'O', - }], - }]; - - await testStore.dispatch(searchMoreChannels('', false, true)); - expect(testStore.getActions()).toEqual(expectedActions); - }); - test('addUsersToChannel', async () => { const testStore = await mockStore(initialState); diff --git a/webapp/channels/src/actions/channel_actions.ts b/webapp/channels/src/actions/channel_actions.ts index 41610c81f0..c577d1f567 100644 --- a/webapp/channels/src/actions/channel_actions.ts +++ b/webapp/channels/src/actions/channel_actions.ts @@ -11,7 +11,6 @@ import {PreferenceTypes} from 'mattermost-redux/action_types'; import * as ChannelActions from 'mattermost-redux/actions/channels'; import {savePreferences} from 'mattermost-redux/actions/preferences'; import {getChannelByName, getUnreadChannelIds, getChannel} from 'mattermost-redux/selectors/entities/channels'; -import {getMyChannelMemberships} from 'mattermost-redux/selectors/entities/common'; import {getCurrentTeamUrl, getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; import type {NewActionFuncAsync} from 'mattermost-redux/types/actions'; @@ -96,26 +95,6 @@ export function loadChannelsForCurrentUser(): NewActionFuncAsync { }; } -export function searchMoreChannels(term: string, showArchivedChannels: boolean, hideJoinedChannels: boolean): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - const state = getState(); - const teamId = getCurrentTeamId(state); - - if (!teamId) { - throw new Error('No team id'); - } - - const {data, error} = await dispatch(ChannelActions.searchChannels(teamId, term, showArchivedChannels)); - if (data) { - const myMembers = getMyChannelMemberships(state); - const channels = hideJoinedChannels ? (data as Channel[]).filter((channel) => !myMembers[channel.id]) : data; - return {data: channels}; - } - - return {error}; - }; -} - export function autocompleteChannels(term: string, success: (channels: Channel[]) => void, error?: (err: ServerError) => void): NewActionFuncAsync { return async (dispatch, getState) => { const state = getState(); diff --git a/webapp/channels/src/actions/global_actions.tsx b/webapp/channels/src/actions/global_actions.tsx index 5909ce3f88..04cd0136bb 100644 --- a/webapp/channels/src/actions/global_actions.tsx +++ b/webapp/channels/src/actions/global_actions.tsx @@ -28,7 +28,6 @@ import type {NewActionFuncAsync, ThunkActionFunc} from 'mattermost-redux/types/a import {calculateUnreadCount} from 'mattermost-redux/utils/channel_utils'; import {handleNewPost} from 'actions/post_actions'; -import {stopPeriodicStatusUpdates} from 'actions/status_actions'; import {loadProfilesForSidebar} from 'actions/user_actions'; import {clearUserCookie} from 'actions/views/cookie'; import {close as closeLhs} from 'actions/views/lhs'; @@ -188,25 +187,6 @@ export function sendEphemeralPost(message: string, channelId?: string, parentId? }; } -export function sendGenericPostMessage(message: string, channelId?: string, parentId?: string, userId?: string): NewActionFuncAsync { // HARRISONTODO unused - return (doDispatch, doGetState) => { - const timestamp = Utils.getTimestamp(); - const post = { - id: Utils.generateId(), - user_id: userId || '0', - channel_id: channelId || getCurrentChannelId(doGetState()), - message, - type: PostTypes.SYSTEM_GENERIC, - create_at: timestamp, - update_at: timestamp, - root_id: parentId || '', - props: {}, - } as Post; - - return doDispatch(handleNewPost(post)); - }; -} - export function sendAddToChannelEphemeralPost(user: UserProfile, addedUsername: string, addedUserId: string, channelId: string, postRootId = '', timestamp: number) { const post = { id: Utils.generateId(), @@ -271,7 +251,6 @@ export function emitUserLoggedOutEvent(redirectTo = '/', shouldSignalLogout = tr BrowserStore.signalLogout(); } - stopPeriodicStatusUpdates(); WebsocketActions.close(); clearUserCookie(); diff --git a/webapp/channels/src/actions/marketplace.ts b/webapp/channels/src/actions/marketplace.ts index f42ccc8afb..f89274eee6 100644 --- a/webapp/channels/src/actions/marketplace.ts +++ b/webapp/channels/src/actions/marketplace.ts @@ -23,24 +23,6 @@ import type {GlobalState} from 'types/store'; import {doAppSubmit, openAppsModal, postEphemeralCallResponseForContext} from './apps'; -export function fetchRemoteListing(): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - const state = getState(); - const filter = getFilter(state); - - try { - const plugins = await Client4.getRemoteMarketplacePlugins(filter); - dispatch({ - type: ActionTypes.RECEIVED_MARKETPLACE_PLUGINS, - plugins, - }); - return {data: plugins}; - } catch (error: any) { - return {error}; - } - }; -} - // fetchPlugins fetches the latest marketplace plugins and apps, subject to any existing search filter. export function fetchListing(localOnly = false): NewActionFuncAsync, GlobalState> { return async (dispatch, getState) => { diff --git a/webapp/channels/src/actions/status_actions.ts b/webapp/channels/src/actions/status_actions.ts index 9f7791fb65..7831110e4b 100644 --- a/webapp/channels/src/actions/status_actions.ts +++ b/webapp/channels/src/actions/status_actions.ts @@ -8,12 +8,10 @@ import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels' import {getPostsInCurrentChannel} from 'mattermost-redux/selectors/entities/posts'; import {getDirectShowPreferences} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {NewActionFunc, ThunkActionFunc} from 'mattermost-redux/types/actions'; +import type {NewActionFunc} from 'mattermost-redux/types/actions'; import {loadCustomEmojisForCustomStatusesByUserIds} from 'actions/emoji_actions'; -import {Constants} from 'utils/constants'; - import type {GlobalState} from 'types/store'; export function loadStatusesForChannelAndSidebar(): NewActionFunc { @@ -115,22 +113,3 @@ export function loadProfilesMissingStatus(users: UserProfile[]): NewActionFunc { return {data: true}; }; } - -let intervalId: NodeJS.Timeout; - -export function startPeriodicStatusUpdates(): ThunkActionFunc { // HARRISONTODO unused - return (dispatch) => { - clearInterval(intervalId); - - intervalId = setInterval( - () => { - dispatch(loadStatusesForChannelAndSidebar()); - }, - Constants.STATUS_INTERVAL, - ); - }; -} - -export function stopPeriodicStatusUpdates() { // HARRISONTODO used but does nothing - clearInterval(intervalId); -} diff --git a/webapp/channels/src/actions/storage.test.ts b/webapp/channels/src/actions/storage.test.ts index 63b40d2916..1db8ddab93 100644 --- a/webapp/channels/src/actions/storage.test.ts +++ b/webapp/channels/src/actions/storage.test.ts @@ -10,26 +10,6 @@ describe('Actions.Storage', () => { store = await configureStore(); }); - it('setItem', async () => { - store.dispatch(Actions.setItem('test', 'value')); - - expect(store.getState().storage.storage.unknown_test.value).toBe('value'); - expect(typeof store.getState().storage.storage.unknown_test.timestamp).not.toBe('undefined'); - }); - - it('removeItem', async () => { - store.dispatch(Actions.setItem('test1', 'value1')); - store.dispatch(Actions.setItem('test2', 'value2')); - - expect(store.getState().storage.storage.unknown_test1.value).toBe('value1'); - expect(store.getState().storage.storage.unknown_test2.value).toBe('value2'); - - store.dispatch(Actions.removeItem('test1')); - - expect(typeof store.getState().storage.storage.unknown_test1).toBe('undefined'); - expect(store.getState().storage.storage.unknown_test2.value).toBe('value2'); - }); - it('setGlobalItem', async () => { store.dispatch(Actions.setGlobalItem('test', 'value')); diff --git a/webapp/channels/src/actions/storage.ts b/webapp/channels/src/actions/storage.ts index a72a082f1b..954f9cc465 100644 --- a/webapp/channels/src/actions/storage.ts +++ b/webapp/channels/src/actions/storage.ts @@ -1,34 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import type {NewActionFunc} from 'mattermost-redux/types/actions'; - import {StorageTypes} from 'utils/constants'; -import {getPrefix} from 'utils/storage_utils'; - -export function setItem(name: string, value: string): NewActionFunc { - return (dispatch, getState) => { - const state = getState(); - const prefix = getPrefix(state); - dispatch({ - type: StorageTypes.SET_ITEM, - data: {prefix, name, value, timestamp: new Date()}, - }); - return {data: true}; - }; -} - -export function removeItem(name: string): NewActionFunc { // HARRISONTODO unused - return (dispatch, getState) => { - const state = getState(); - const prefix = getPrefix(state); - dispatch({ - type: StorageTypes.REMOVE_ITEM, - data: {prefix, name}, - }); - return {data: true}; - }; -} export function setGlobalItem(name: string, value: any) { return { diff --git a/webapp/channels/src/actions/user_actions.test.ts b/webapp/channels/src/actions/user_actions.test.ts index cf7e257912..894be793dd 100644 --- a/webapp/channels/src/actions/user_actions.test.ts +++ b/webapp/channels/src/actions/user_actions.test.ts @@ -174,16 +174,6 @@ describe('Actions.User', () => { } as GlobalState['views'], } as GlobalState; - test('loadProfilesAndStatusesInChannel', async () => { - const testStore = mockStore(initialState); - await testStore.dispatch(UserActions.loadProfilesAndStatusesInChannel('channel_1', 0, 60, 'status', {})); - const actualActions = testStore.getActions(); - expect(actualActions[0].args).toEqual(['channel_1', 0, 60, 'status', {}]); - expect(actualActions[0].type).toEqual('MOCK_GET_PROFILES_IN_CHANNEL'); - expect(actualActions[1].args).toEqual([['user_1']]); - expect(actualActions[1].type).toEqual('MOCK_GET_STATUSES_BY_ID'); - }); - test('loadProfilesAndTeamMembers', async () => { const expectedActions = [{type: 'MOCK_GET_PROFILES_IN_TEAM', args: ['team_1', 0, 60, '', {}]}]; diff --git a/webapp/channels/src/actions/user_actions.ts b/webapp/channels/src/actions/user_actions.ts index cdb393704b..ca95950e48 100644 --- a/webapp/channels/src/actions/user_actions.ts +++ b/webapp/channels/src/actions/user_actions.ts @@ -40,16 +40,6 @@ export const queue = new PQueue({concurrency: 4}); const dispatch = store.dispatch; const getState = store.getState; -export function loadProfilesAndStatusesInChannel(channelId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE, sort = '', options = {}): NewActionFuncAsync { // HARRISONTODO unused - return async (doDispatch) => { - const {data} = await doDispatch(UserActions.getProfilesInChannel(channelId, page, perPage, sort, options)); - if (data) { - doDispatch(loadStatusesForProfilesList(data)); - } - return {data: true}; - }; -} - export function loadProfilesAndReloadTeamMembers(page: number, perPage: number, teamId: string, options = {}): NewActionFuncAsync { return async (doDispatch, doGetState) => { const newTeamId = teamId || getCurrentTeamId(doGetState()); diff --git a/webapp/channels/src/actions/views/channel_sidebar.ts b/webapp/channels/src/actions/views/channel_sidebar.ts index 7f15dc03ee..7c23fb2453 100644 --- a/webapp/channels/src/actions/views/channel_sidebar.ts +++ b/webapp/channels/src/actions/views/channel_sidebar.ts @@ -175,13 +175,6 @@ export function multiSelectChannelAdd(channelId: string): NewActionFunc { diff --git a/webapp/channels/src/actions/views/create_comment.test.jsx b/webapp/channels/src/actions/views/create_comment.test.jsx index aeaf8c9bc3..90368d61c6 100644 --- a/webapp/channels/src/actions/views/create_comment.test.jsx +++ b/webapp/channels/src/actions/views/create_comment.test.jsx @@ -3,7 +3,6 @@ import { addMessageIntoHistory, - moveHistoryIndexBack, } from 'mattermost-redux/actions/posts'; import {Posts} from 'mattermost-redux/constants'; @@ -14,7 +13,6 @@ import {setGlobalItem, actionOnGlobalItemsWithPrefix} from 'actions/storage'; import { clearCommentDraftUploads, updateCommentDraft, - makeOnMoveHistoryIndex, submitPost, submitCommand, makeOnSubmit, @@ -217,47 +215,6 @@ describe('rhs view actions', () => { }); }); - describe('makeOnMoveHistoryIndex', () => { - beforeAll(() => { - jest.useFakeTimers(); - jest.setSystemTime(42); - }); - - afterAll(() => { - jest.useRealTimers(); - }); - - test('it moves comment history index back', () => { - const onMoveHistoryIndex = makeOnMoveHistoryIndex(rootId, -1); - - store.dispatch(onMoveHistoryIndex()); - - const testStore = mockStore(initialState); - - testStore.dispatch(moveHistoryIndexBack(Posts.MESSAGE_TYPES.COMMENT)); - - expect(store.getActions()).toEqual( - expect.arrayContaining(testStore.getActions()), - ); - }); - - test('it stores history message in draft', (done) => { - const onMoveHistoryIndex = makeOnMoveHistoryIndex(rootId, -1); - - store.dispatch(onMoveHistoryIndex()); - - const testStore = mockStore(initialState); - - testStore.dispatch(updateCommentDraft(rootId, {message: 'test message', channelId, rootId, fileInfos: [], uploadsInProgress: []})); - - expect(store.getActions()).toEqual( - expect.arrayContaining(testStore.getActions()), - ); - - done(); - }); - }); - describe('submitPost', () => { const draft = {message: '', channelId, rootId, fileInfos: []}; diff --git a/webapp/channels/src/actions/views/create_comment.tsx b/webapp/channels/src/actions/views/create_comment.tsx index 342c720037..6e16d0e0bc 100644 --- a/webapp/channels/src/actions/views/create_comment.tsx +++ b/webapp/channels/src/actions/views/create_comment.tsx @@ -5,14 +5,10 @@ import type {Post} from '@mattermost/types/posts'; import { addMessageIntoHistory, - moveHistoryIndexBack, - moveHistoryIndexForward, } from 'mattermost-redux/actions/posts'; -import {Posts} from 'mattermost-redux/constants'; import {createSelector} from 'mattermost-redux/selectors/create_selector'; import {getCustomEmojisByName} from 'mattermost-redux/selectors/entities/emojis'; import { - makeGetMessageInHistoryItem, getPost, makeGetPostIdsForThread, } from 'mattermost-redux/selectors/entities/posts'; @@ -26,7 +22,6 @@ import {runMessageWillBePostedHooks, runSlashCommandWillBePostedHooks} from 'act import * as PostActions from 'actions/post_actions'; import {actionOnGlobalItemsWithPrefix} from 'actions/storage'; import {updateDraft, removeDraft} from 'actions/views/drafts'; -import {getPostDraft} from 'selectors/rhs'; import {Constants, StoragePrefixes} from 'utils/constants'; import EmojiMap from 'utils/emoji_map'; @@ -52,28 +47,6 @@ export function updateCommentDraft(rootId: string, draft?: PostDraft, save = fal return updateDraft(key, draft ?? null, rootId, save); } -export function makeOnMoveHistoryIndex(rootId: string, direction: number): () => NewActionFunc { // HARRISONTODO unused - const getMessageInHistory = makeGetMessageInHistoryItem(Posts.MESSAGE_TYPES.COMMENT as 'comment'); - - return () => (dispatch, getState) => { - const draft = getPostDraft(getState(), StoragePrefixes.COMMENT_DRAFT, rootId); - if (draft.message !== '' && draft.message !== getMessageInHistory(getState())) { - return {data: true}; - } - - if (direction === -1) { - dispatch(moveHistoryIndexBack(Posts.MESSAGE_TYPES.COMMENT as 'comment')); - } else if (direction === 1) { - dispatch(moveHistoryIndexForward(Posts.MESSAGE_TYPES.COMMENT as 'comment')); - } - - const nextMessageInHistory = getMessageInHistory(getState()); - - dispatch(updateCommentDraft(rootId, {...draft, message: nextMessageInHistory})); - return {data: true}; - }; -} - export function submitPost(channelId: string, rootId: string, draft: PostDraft): NewActionFuncAsync { return async (dispatch, getState) => { const state = getState(); diff --git a/webapp/channels/src/actions/views/rhs.ts b/webapp/channels/src/actions/views/rhs.ts index 245c56cc7d..305576397c 100644 --- a/webapp/channels/src/actions/views/rhs.ts +++ b/webapp/channels/src/actions/views/rhs.ts @@ -123,10 +123,6 @@ export function selectPostFromRightHandSideSearch(post: Post) { return selectPostFromRightHandSideSearchWithPreviousState(post); } -export function selectPostCardFromRightHandSideSearch(post: Post) { // HARRISONTODO unused - return selectPostCardFromRightHandSideSearchWithPreviousState(post); -} - export function selectPostFromRightHandSideSearchByPostId(postId: string): NewActionFuncAsync { return async (dispatch, getState) => { const post = getPost(getState(), postId); @@ -526,17 +522,6 @@ export function toggleRhsExpanded() { }; } -export function selectPostAndParentChannel(post: Post): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - const channel = getChannelSelector(getState(), post.channel_id); - if (!channel) { - await dispatch(getChannel(post.channel_id)); - } - dispatch(selectPost(post)); - return {data: true}; - }; -} - export function selectPost(post: Post) { return { type: ActionTypes.SELECT_POST, diff --git a/webapp/channels/src/packages/mattermost-redux/src/action_types/admin.ts b/webapp/channels/src/packages/mattermost-redux/src/action_types/admin.ts index 40e77ec7d5..2ca42aecdb 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/action_types/admin.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/action_types/admin.ts @@ -31,7 +31,6 @@ export default keyMirror({ RECEIVED_SYSTEM_ANALYTICS: null, RECEIVED_TEAM_ANALYTICS: null, RECEIVED_USER_ACCESS_TOKEN: null, - RECEIVED_USER_ACCESS_TOKENS: null, RECEIVED_USER_ACCESS_TOKENS_FOR_USER: null, RECEIVED_PLUGINS: null, RECEIVED_PLUGIN_STATUSES: null, diff --git a/webapp/channels/src/packages/mattermost-redux/src/action_types/channels.ts b/webapp/channels/src/packages/mattermost-redux/src/action_types/channels.ts index 658ee8eeed..6501b90ebb 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/action_types/channels.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/action_types/channels.ts @@ -16,10 +16,6 @@ export default keyMirror({ CREATE_CHANNEL_SUCCESS: null, CREATE_CHANNEL_FAILURE: null, - UPDATE_CHANNEL_REQUEST: null, - UPDATE_CHANNEL_SUCCESS: null, - UPDATE_CHANNEL_FAILURE: null, - DELETE_CHANNEL_SUCCESS: null, UNARCHIVED_CHANNEL_SUCCESS: null, @@ -61,8 +57,6 @@ export default keyMirror({ RECEIVED_CHANNEL_DELETED: null, RECEIVED_CHANNEL_UNARCHIVED: null, RECEIVED_LAST_VIEWED_AT: null, - UPDATE_CHANNEL_HEADER: null, - UPDATE_CHANNEL_PURPOSE: null, CHANNEL_MEMBER_ADDED: null, CHANNEL_MEMBER_REMOVED: null, diff --git a/webapp/channels/src/packages/mattermost-redux/src/action_types/general.ts b/webapp/channels/src/packages/mattermost-redux/src/action_types/general.ts index 2def5ef180..ee5b8fbefe 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/action_types/general.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/action_types/general.ts @@ -12,8 +12,6 @@ export default keyMirror({ CLIENT_LICENSE_RECEIVED: null, CLIENT_LICENSE_RESET: null, - RECEIVED_DATA_RETENTION_POLICY: null, - LOG_CLIENT_ERROR_REQUEST: null, LOG_CLIENT_ERROR_SUCCESS: null, LOG_CLIENT_ERROR_FAILURE: null, @@ -26,7 +24,6 @@ export default keyMirror({ SET_CONFIG_AND_LICENSE: null, - WARN_METRICS_STATUS_RECEIVED: null, WARN_METRIC_STATUS_RECEIVED: null, WARN_METRIC_STATUS_REMOVED: null, diff --git a/webapp/channels/src/packages/mattermost-redux/src/action_types/posts.ts b/webapp/channels/src/packages/mattermost-redux/src/action_types/posts.ts index 730ed804cb..7581af82e0 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/action_types/posts.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/action_types/posts.ts @@ -42,10 +42,8 @@ export default keyMirror({ POST_REMOVED: null, RECEIVED_FOCUSED_POST: null, - RECEIVED_POST_SELECTED: null, RECEIVED_EDIT_POST: null, RECEIVED_REACTION: null, - RECEIVED_REACTIONS: null, REACTION_DELETED: null, ADD_MESSAGE_INTO_HISTORY: null, diff --git a/webapp/channels/src/packages/mattermost-redux/src/action_types/search.ts b/webapp/channels/src/packages/mattermost-redux/src/action_types/search.ts index 4115759382..d3288d590e 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/action_types/search.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/action_types/search.ts @@ -17,7 +17,6 @@ export default keyMirror({ SEARCH_PINNED_POSTS_REQUEST: null, SEARCH_PINNED_POSTS_SUCCESS: null, SEARCH_PINNED_POSTS_FAILURE: null, - REMOVE_SEARCH_PINNED_POSTS: null, RECEIVED_SEARCH_POSTS: null, RECEIVED_SEARCH_FILES: null, RECEIVED_SEARCH_FLAGGED_POSTS: null, @@ -25,5 +24,4 @@ export default keyMirror({ RECEIVED_SEARCH_TERM: null, REMOVE_SEARCH_POSTS: null, REMOVE_SEARCH_FILES: null, - REMOVE_SEARCH_TERM: null, }); diff --git a/webapp/channels/src/packages/mattermost-redux/src/action_types/teams.ts b/webapp/channels/src/packages/mattermost-redux/src/action_types/teams.ts index 39d0e883e2..d9c48f4d92 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/action_types/teams.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/action_types/teams.ts @@ -20,10 +20,6 @@ export default keyMirror({ GET_TEAM_MEMBERS_SUCCESS: null, GET_TEAM_MEMBERS_FAILURE: null, - JOIN_TEAM_REQUEST: null, - JOIN_TEAM_SUCCESS: null, - JOIN_TEAM_FAILURE: null, - TEAM_INVITE_INFO_REQUEST: null, TEAM_INVITE_INFO_SUCCESS: null, TEAM_INVITE_INFO_FAILURE: null, diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts index fabb687a63..5fd5e80c07 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts @@ -28,14 +28,6 @@ import {insertMultipleWithoutDuplicates, insertWithoutDuplicates, removeItem} fr import {General} from '../constants'; -export function expandCategory(categoryId: string) { // HARRISONTODO unused - return setCategoryCollapsed(categoryId, false); -} - -export function collapseCategory(categoryId: string) { // HARRISONTODO unused - return setCategoryCollapsed(categoryId, true); -} - export function setCategoryCollapsed(categoryId: string, collapsed: boolean) { return patchCategory(categoryId, { collapsed, diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/channels.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/channels.test.ts index 6145dc0d0a..8724bc1bb7 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/channels.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/channels.test.ts @@ -8,7 +8,6 @@ import type {IncomingWebhook, OutgoingWebhook} from '@mattermost/types/integrati import {UserTypes} from 'mattermost-redux/action_types'; import * as Actions from 'mattermost-redux/actions/channels'; import {createIncomingHook, createOutgoingHook} from 'mattermost-redux/actions/integrations'; -import {addUserToTeam} from 'mattermost-redux/actions/teams'; import {getProfilesByIds, loadMe} from 'mattermost-redux/actions/users'; import {Client4} from 'mattermost-redux/client'; import {getPreferenceKey} from 'mattermost-redux/utils/preference_utils'; @@ -249,31 +248,6 @@ describe('Actions.Channels', () => { expect(profilesInChannel[created.id].has(user2.id)).toBeTruthy(); }); - it('updateChannel', async () => { - const channel = { - ...TestHelper.basicChannel!, - purpose: 'This is to test redux', - header: 'MM with Redux', - }; - - nock(Client4.getBaseRoute()). - put(`/channels/${channel.id}`). - reply(200, channel); - - await store.dispatch(Actions.updateChannel(channel)); - - const updateRequest = store.getState().requests.channels.updateChannel; - if (updateRequest.status === RequestStatus.FAILURE) { - throw new Error(JSON.stringify(updateRequest.error)); - } - - const {channels} = store.getState().entities.channels; - const channelId = Object.keys(channels)[0]; - expect(channelId).toBeTruthy(); - expect(channels[channelId]).toBeTruthy(); - expect(channels[channelId].header).toEqual('MM with Redux'); - }); - it('patchChannel', async () => { const channel = { header: 'MM with Redux2', @@ -285,11 +259,6 @@ describe('Actions.Channels', () => { await store.dispatch(Actions.patchChannel(TestHelper.basicChannel!.id, channel)); - const updateRequest = store.getState().requests.channels.updateChannel; - if (updateRequest.status === RequestStatus.FAILURE) { - throw new Error(JSON.stringify(updateRequest.error)); - } - const {channels} = store.getState().entities.channels; const channelId = Object.keys(channels)[0]; expect(channelId).toBeTruthy(); @@ -307,11 +276,6 @@ describe('Actions.Channels', () => { await store.dispatch(Actions.updateChannelPrivacy(publicChannel.id, General.PRIVATE_CHANNEL)); - const updateRequest = store.getState().requests.channels.updateChannel; - if (updateRequest.status === RequestStatus.FAILURE) { - throw new Error(JSON.stringify(updateRequest.error)); - } - const {channels} = store.getState().entities.channels; const channelId = Object.keys(channels)[0]; expect(channelId).toBeTruthy(); @@ -1460,70 +1424,6 @@ describe('Actions.Channels', () => { expect(stats[channelId].member_count >= 1).toBeTruthy(); }); - it('updateChannelMemberRoles', async () => { - nock(Client4.getBaseRoute()). - post('/users'). - reply(201, TestHelper.fakeUserWithId()); - - const user = await TestHelper.basicClient4!.createUser(TestHelper.fakeUser(), '', ''); - - nock(Client4.getTeamsRoute()). - post(`/${TestHelper.basicChannel!.id}/members`). - reply(201, {team_id: TestHelper.basicTeam!.id, roles: 'channel_user', user_id: user.id}); - - await store.dispatch(addUserToTeam(TestHelper.basicTeam!.id, user.id)); - nock(Client4.getBaseRoute()). - post(`/channels/${TestHelper.basicChannel!.id}/members`). - reply(201, {channel_id: TestHelper.basicChannel!.id, roles: 'channel_user', user_id: user.id}); - - await store.dispatch(Actions.addChannelMember(TestHelper.basicChannel!.id, user.id)); - - const roles = General.CHANNEL_USER_ROLE + ' ' + General.CHANNEL_ADMIN_ROLE; - - nock(Client4.getBaseRoute()). - put(`/channels/${TestHelper.basicChannel!.id}/members/${user.id}/roles`). - reply(200, {roles}); - await store.dispatch(Actions.updateChannelMemberRoles(TestHelper.basicChannel!.id, user.id, roles)); - - const members = store.getState().entities.channels.membersInChannel; - - expect(members[TestHelper.basicChannel!.id]).toBeTruthy(); - expect(members[TestHelper.basicChannel!.id][user.id]).toBeTruthy(); - expect(members[TestHelper.basicChannel!.id][user.id].roles === roles).toBeTruthy(); - }); - - it('updateChannelHeader', async () => { - nock(Client4.getBaseRoute()). - get(`/channels/${TestHelper.basicChannel!.id}`). - reply(200, TestHelper.basicChannel!); - - await store.dispatch(Actions.getChannel(TestHelper.basicChannel!.id)); - - const header = 'this is an updated test header'; - - await store.dispatch(Actions.updateChannelHeader(TestHelper.basicChannel!.id, header)); - - const {channels} = store.getState().entities.channels; - const channel = channels[TestHelper.basicChannel!.id]; - expect(channel).toBeTruthy(); - expect(channel.header).toEqual(header); - }); - - it('updateChannelPurpose', async () => { - nock(Client4.getBaseRoute()). - get(`/channels/${TestHelper.basicChannel!.id}`). - reply(200, TestHelper.basicChannel!); - - await store.dispatch(Actions.getChannel(TestHelper.basicChannel!.id)); - - const purpose = 'this is an updated test purpose'; - await store.dispatch(Actions.updateChannelPurpose(TestHelper.basicChannel!.id, purpose)); - const {channels} = store.getState().entities.channels; - const channel = channels[TestHelper.basicChannel!.id]; - expect(channel).toBeTruthy(); - expect(channel.purpose).toEqual(purpose); - }); - describe('leaveChannel', () => { const team = TestHelper.fakeTeam(); const user = TestHelper.fakeUserWithId(); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts index ee56003a03..cc767bc748 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts @@ -256,114 +256,36 @@ export function createGroupChannel(userIds: string[]): NewActionFuncAsync): NewActionFuncAsync { - return async (dispatch, getState) => { - dispatch({type: ChannelTypes.UPDATE_CHANNEL_REQUEST, data: null}); - - let updated; - try { - updated = await Client4.patchChannel(channelId, patch); - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - - dispatch({type: ChannelTypes.UPDATE_CHANNEL_FAILURE, error}); - dispatch(logError(error)); - return {error}; - } - dispatch(batchActions([ - { - type: ChannelTypes.RECEIVED_CHANNEL, - data: updated, - }, - { - type: ChannelTypes.UPDATE_CHANNEL_SUCCESS, - }, - ])); - - return {data: updated}; - }; -} - -export function updateChannel(channel: Channel): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - dispatch({type: ChannelTypes.UPDATE_CHANNEL_REQUEST, data: null}); - - let updated; - try { - updated = await Client4.updateChannel(channel); - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - - dispatch({type: ChannelTypes.UPDATE_CHANNEL_FAILURE, error}); - dispatch(logError(error)); - return {error}; - } - - dispatch(batchActions([ - { - type: ChannelTypes.RECEIVED_CHANNEL, - data: updated, - }, - { - type: ChannelTypes.UPDATE_CHANNEL_SUCCESS, - }, - ])); - - return {data: updated}; - }; + return bindClientFunc({ + clientFunc: Client4.patchChannel, + onSuccess: [ChannelTypes.RECEIVED_CHANNEL], + params: [channelId, patch], + }); } export function updateChannelPrivacy(channelId: string, privacy: string): NewActionFuncAsync { - return async (dispatch, getState) => { - dispatch({type: ChannelTypes.UPDATE_CHANNEL_REQUEST, data: null}); - - let updatedChannel; - try { - updatedChannel = await Client4.updateChannelPrivacy(channelId, privacy); - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - - dispatch({type: ChannelTypes.UPDATE_CHANNEL_FAILURE, error}); - dispatch(logError(error)); - return {error}; - } - - dispatch(batchActions([ - { - type: ChannelTypes.RECEIVED_CHANNEL, - data: updatedChannel, - }, - { - type: ChannelTypes.UPDATE_CHANNEL_SUCCESS, - }, - ])); - - return {data: updatedChannel}; - }; + return bindClientFunc({ + clientFunc: Client4.updateChannelPrivacy, + onSuccess: [ChannelTypes.RECEIVED_CHANNEL], + params: [channelId, privacy], + }); } export function convertGroupMessageToPrivateChannel(channelID: string, teamID: string, displayName: string, name: string): NewActionFuncAsync { return async (dispatch, getState) => { - dispatch({type: ChannelTypes.UPDATE_CHANNEL_REQUEST, data: null}); - let updatedChannel; try { updatedChannel = await Client4.convertGroupMessageToPrivateChannel(channelID, teamID, displayName, name); } catch (error) { forceLogoutIfNecessary(error, dispatch, getState); - dispatch({type: ChannelTypes.UPDATE_CHANNEL_FAILURE, error}); dispatch(logError(error)); return {error}; } - dispatch(batchActions([ - { - type: ChannelTypes.RECEIVED_CHANNEL, - data: updatedChannel, - }, - { - type: ChannelTypes.UPDATE_CHANNEL_SUCCESS, - }, - ])); + dispatch({ + type: ChannelTypes.RECEIVED_CHANNEL, + data: updatedChannel, + }); // move the channel from direct message category to the default "channels" category const channelsCategory = getCategoryInTeamByType(getState(), teamID, CategoryTypes.CHANNELS); @@ -1136,60 +1058,6 @@ export function removeChannelMember(channelId: string, userId: string): NewActio }; } -export function updateChannelMemberRoles(channelId: string, userId: string, roles: string): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - try { - await Client4.updateChannelMemberRoles(channelId, userId, roles); - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - dispatch(logError(error)); - return {error}; - } - - const membersInChannel = getState().entities.channels.membersInChannel[channelId]; - if (membersInChannel && membersInChannel[userId]) { - dispatch({ - type: ChannelTypes.RECEIVED_CHANNEL_MEMBER, - data: {...membersInChannel[userId], roles}, - }); - } - - return {data: true}; - }; -} - -export function updateChannelHeader(channelId: string, header: string): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch) => { - Client4.trackEvent('action', 'action_channels_update_header', {channel_id: channelId}); - - dispatch({ - type: ChannelTypes.UPDATE_CHANNEL_HEADER, - data: { - channelId, - header, - }, - }); - - return {data: true}; - }; -} - -export function updateChannelPurpose(channelId: string, purpose: string): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch) => { - Client4.trackEvent('action', 'action_channels_update_purpose', {channel_id: channelId}); - - dispatch({ - type: ChannelTypes.UPDATE_CHANNEL_PURPOSE, - data: { - channelId, - purpose, - }, - }); - - return {data: true}; - }; -} - export function markChannelAsRead(channelId: string, skipUpdateViewTime = false): NewActionFunc { return (dispatch, getState) => { if (skipUpdateViewTime) { @@ -1494,7 +1362,6 @@ export default { selectChannel, createChannel, createDirectChannel, - updateChannel, patchChannel, updateChannelNotifyProps, getChannel, @@ -1513,8 +1380,6 @@ export default { getChannelStats, addChannelMember, removeChannelMember, - updateChannelHeader, - updateChannelPurpose, markChannelAsRead, favoriteChannel, unfavoriteChannel, diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/general.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/general.test.ts index 248b9923fa..4d3795c5aa 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/general.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/general.test.ts @@ -64,58 +64,6 @@ describe('Actions.General', () => { expect(serverVersion).toEqual(version); }); - it('getDataRetentionPolicy', async () => { - const responseData = { - message_deletion_enabled: true, - file_deletion_enabled: false, - message_retention_cutoff: Date.now(), - file_retention_cutoff: 0, - }; - - nock(Client4.getBaseRoute()). - get('/data_retention/policy'). - query(true). - reply(200, responseData); - - await store.dispatch(Actions.getDataRetentionPolicy()); - await TestHelper.wait(100); - const {dataRetentionPolicy} = store.getState().entities.general; - expect(dataRetentionPolicy).toEqual(responseData); - }); - - it('getWarnMetricsStatus', async () => { - const responseData = { - metric1: true, - metric2: false, - }; - - nock(Client4.getBaseRoute()). - get('/warn_metrics/status'). - query(true). - reply(200, responseData); - - await store.dispatch(Actions.getWarnMetricsStatus()); - const {warnMetricsStatus} = store.getState().entities.general; - expect(warnMetricsStatus.metric1).toEqual(true); - expect(warnMetricsStatus.metric2).toEqual(false); - }); - - it('getFirstAdminVisitMarketplaceStatus', async () => { - const responseData = { - name: 'FirstAdminVisitMarketplace', - value: 'false', - }; - - nock(Client4.getPluginsRoute()). - get('/marketplace/first_admin_visit'). - query(true). - reply(200, responseData); - - await store.dispatch(Actions.getFirstAdminVisitMarketplaceStatus()); - const {firstAdminVisitMarketplaceStatus} = store.getState().entities.general; - expect(firstAdminVisitMarketplaceStatus).toEqual(false); - }); - it('setFirstAdminVisitMarketplaceStatus', async () => { nock(Client4.getPluginsRoute()). post('/marketplace/first_admin_visit'). diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts index 80436d07c7..9dfb78650e 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts @@ -1,8 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {batchActions} from 'redux-batched-actions'; - import {LogLevel} from '@mattermost/types/client4'; import type {SystemSetting} from '@mattermost/types/general'; @@ -33,29 +31,6 @@ export function getClientConfig(): NewActionFuncAsync { }; } -export function getDataRetentionPolicy(): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - let data; - try { - data = await Client4.getDataRetentionPolicy(); - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - dispatch({ - type: GeneralTypes.RECEIVED_DATA_RETENTION_POLICY, - error, - }); - dispatch(logError(error)); - return {error}; - } - - dispatch(batchActions([ - {type: GeneralTypes.RECEIVED_DATA_RETENTION_POLICY, data}, - ])); - - return {data}; - }; -} - export function getLicenseConfig() { return bindClientFunc({ clientFunc: Client4.getClientLicenseOld, @@ -90,21 +65,6 @@ export function setUrl(url: string) { return true; } -export function getWarnMetricsStatus(): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - let data; - try { - data = await Client4.getWarnMetricsStatus(); - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - return {error}; - } - dispatch({type: GeneralTypes.WARN_METRICS_STATUS_RECEIVED, data}); - - return {data}; - }; -} - export function setFirstAdminVisitMarketplaceStatus(): NewActionFuncAsync { return async (dispatch) => { try { @@ -118,22 +78,6 @@ export function setFirstAdminVisitMarketplaceStatus(): NewActionFuncAsync { }; } -export function getFirstAdminVisitMarketplaceStatus(): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - let data; - try { - data = await Client4.getFirstAdminVisitMarketplaceStatus(); - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - return {error}; - } - - data = JSON.parse(data.value); - dispatch({type: GeneralTypes.FIRST_ADMIN_VISIT_MARKETPLACE_STATUS_RECEIVED, data}); - return {data}; - }; -} - // accompanying "set" happens as part of Client4.completeSetup export function getFirstAdminSetupComplete(): NewActionFuncAsync { return async (dispatch, getState) => { @@ -153,11 +97,8 @@ export function getFirstAdminSetupComplete(): NewActionFuncAsync export default { getClientConfig, - getDataRetentionPolicy, getLicenseConfig, logClientError, setServerVersion, setUrl, - getWarnMetricsStatus, - getFirstAdminVisitMarketplaceStatus, }; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/posts.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/posts.test.ts index 2daa4709f2..6bd5ab6e4f 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/posts.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/posts.test.ts @@ -1277,46 +1277,6 @@ describe('Actions.Posts', () => { expect(!reactions[TestHelper.basicUser!.id + '-' + emojiName]).toBeTruthy(); }); - it('getReactionsForPost', async () => { - const {dispatch, getState} = store; - - TestHelper.mockLogin(); - store.dispatch({ - type: UserTypes.LOGIN_SUCCESS, - }); - await store.dispatch(loadMe()); - - nock(Client4.getBaseRoute()). - post('/posts'). - reply(201, TestHelper.fakePostWithId(TestHelper.basicChannel!.id)); - const post1 = await Client4.createPost( - TestHelper.fakePost(TestHelper.basicChannel!.id), - ); - - const emojiName = '+1'; - - nock(Client4.getBaseRoute()). - post('/reactions'). - reply(201, {user_id: TestHelper.basicUser!.id, post_id: post1.id, emoji_name: emojiName, create_at: 1508168444721}); - await dispatch(Actions.addReaction(post1.id, emojiName)); - - dispatch({ - type: PostTypes.REACTION_DELETED, - data: {user_id: TestHelper.basicUser!.id, post_id: post1.id, emoji_name: emojiName}, - }); - - nock(Client4.getBaseRoute()). - get(`/posts/${post1.id}/reactions`). - reply(200, [{user_id: TestHelper.basicUser!.id, post_id: post1.id, emoji_name: emojiName, create_at: 1508168444721}]); - await dispatch(Actions.getReactionsForPost(post1.id)); - - const state = getState(); - const reactions = state.entities.posts.reactions[post1.id]; - - expect(reactions).toBeTruthy(); - expect(reactions[TestHelper.basicUser!.id + '-' + emojiName]).toBeTruthy(); - }); - it('getCustomEmojiForReaction', async () => { const testImageData = fs.createReadStream('src/packages/mattermost-redux/test/assets/images/test.png'); const {dispatch, getState} = store; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/posts.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/posts.ts index cafa67a01f..f21cd72e69 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/posts.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/posts.ts @@ -6,16 +6,14 @@ import {batchActions} from 'redux-batched-actions'; import type {Channel, ChannelUnread} from '@mattermost/types/channels'; import type {FetchPaginatedThreadOptions} from '@mattermost/types/client4'; -import type {ServerError} from '@mattermost/types/errors'; import type {Group} from '@mattermost/types/groups'; import type {Post, PostList, PostAcknowledgement} from '@mattermost/types/posts'; -import type {Reaction} from '@mattermost/types/reactions'; import type {GlobalState} from '@mattermost/types/store'; import type {UserProfile} from '@mattermost/types/users'; import {PostTypes, ChannelTypes, FileTypes, IntegrationTypes} from 'mattermost-redux/action_types'; import {selectChannel} from 'mattermost-redux/actions/channels'; -import {systemEmojis, getCustomEmojiByName, getCustomEmojisByName} from 'mattermost-redux/actions/emojis'; +import {systemEmojis, getCustomEmojiByName} from 'mattermost-redux/actions/emojis'; import {searchGroups} from 'mattermost-redux/actions/groups'; import {bindClientFunc, forceLogoutIfNecessary} from 'mattermost-redux/actions/helpers'; import { @@ -657,58 +655,6 @@ export function getCustomEmojiForReaction(name: string): NewActionFuncAsync { }; } -export function getReactionsForPost(postId: string): ThunkActionFunc> { // HARRISONTODO unused - return async (dispatch, getState) => { - let reactions; - try { - reactions = await Client4.getReactionsForPost(postId); - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - dispatch(logError(error)); - return {error}; - } - - if (reactions && reactions.length > 0) { - const nonExistentEmoji = getState().entities.emojis.nonExistentEmoji; - const customEmojisByName = selectCustomEmojisByName(getState()); - const emojisToLoad = new Set(); - - reactions.forEach((r: Reaction) => { - const name = r.emoji_name; - - if (systemEmojis.has(name)) { - // It's a system emoji, go the next match - return; - } - - if (nonExistentEmoji.has(name)) { - // We've previously confirmed this is not a custom emoji - return; - } - - if (customEmojisByName.has(name)) { - // We have the emoji, go to the next match - return; - } - - emojisToLoad.add(name); - }); - - dispatch(getCustomEmojisByName(Array.from(emojisToLoad))); - } - - dispatch(batchActions([ - { - type: PostTypes.RECEIVED_REACTIONS, - data: reactions, - postId, - }, - ])); - - return reactions; - }; -} - export function flagPost(postId: string): NewActionFuncAsync { return async (dispatch, getState) => { const {currentUserId} = getState().entities.users; @@ -1251,13 +1197,6 @@ export function removePost(post: ExtendedPost): NewActionFunc { }; } -export function selectPost(postId: string) { // HARRISONTODO unused - return { - type: PostTypes.RECEIVED_POST_SELECTED, - data: postId, - }; -} - export function moveThread(postId: string, channelId: string): NewActionFuncAsync { return async (dispatch, getState) => { try { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.test.ts index afdad89fab..ce1c53202c 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.test.ts @@ -11,7 +11,6 @@ import type {Theme} from 'mattermost-redux/selectors/entities/preferences'; import TestHelper from '../../test/test_helper'; import configureStore from '../../test/test_store'; -import {Preferences} from '../constants'; const OK_RESPONSE = {status: 'OK'}; @@ -191,72 +190,6 @@ describe('Actions.Preferences', () => { expect(!myPreferences['test--test3']).toBeTruthy(); }); - it('makeDirectChannelVisibleIfNecessary', async () => { - const user = TestHelper.basicUser!; - - nock(Client4.getBaseRoute()). - post('/users'). - reply(201, TestHelper.fakeUserWithId()); - const user2 = await TestHelper.createClient4().createUser(TestHelper.fakeUser(), '', ''); - - TestHelper.mockLogin(); - store.dispatch({ - type: UserTypes.LOGIN_SUCCESS, - }); - await store.dispatch(loadMe()); - - // Test that a new preference is created if none exists - nock(Client4.getUsersRoute()). - put(`/${TestHelper.basicUser!.id}/preferences`). - reply(200, OK_RESPONSE); - await store.dispatch(Actions.makeDirectChannelVisibleIfNecessary(user2.id)); - - let state = store.getState(); - let myPreferences = state.entities.preferences.myPreferences; - let preference = myPreferences[`${Preferences.CATEGORY_DIRECT_CHANNEL_SHOW}--${user2.id}`]; - - // preference for showing direct channel doesn't exist - expect(preference).toBeTruthy(); - - // preference for showing direct channel is not true - expect(preference.value).toBe('true'); - - // Test that nothing changes if the preference already exists and is true - nock(Client4.getUsersRoute()). - put(`/${TestHelper.basicUser!.id}/preferences`). - reply(200, OK_RESPONSE); - await store.dispatch(Actions.makeDirectChannelVisibleIfNecessary(user2.id)); - - const state2 = store.getState(); - - // store should not change since direct channel is already visible - expect(state).toEqual(state2); - - // Test that the preference is updated if it already exists and is false - nock(Client4.getUsersRoute()). - put(`/${TestHelper.basicUser!.id}/preferences`). - reply(200, OK_RESPONSE); - store.dispatch(Actions.savePreferences(user.id, [{ - ...preference, - value: 'false', - }])); - - nock(Client4.getUsersRoute()). - put(`/${TestHelper.basicUser!.id}/preferences`). - reply(200, OK_RESPONSE); - await store.dispatch(Actions.makeDirectChannelVisibleIfNecessary(user2.id)); - - state = store.getState(); - myPreferences = state.entities.preferences.myPreferences; - preference = myPreferences[`${Preferences.CATEGORY_DIRECT_CHANNEL_SHOW}--${user2.id}`]; - - // preference for showing direct channel doesn't exist - expect(preference).toBeTruthy(); - - // preference for showing direct channel is not true - expect(preference.value).toEqual('true'); - }); - it('saveTheme', async () => { const user = TestHelper.basicUser!; const team = TestHelper.basicTeam!; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.ts index 6691d02e73..76dfc40e7d 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.ts @@ -11,9 +11,7 @@ import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; import type {NewActionFuncAsync, ThunkActionFunc} from 'mattermost-redux/types/actions'; import {getPreferenceKey} from 'mattermost-redux/utils/preference_utils'; -import {getChannelAndMyMember, getMyChannelMember} from './channels'; import {bindClientFunc} from './helpers'; -import {getProfilesByIds, getProfilesInChannel} from './users'; import {Preferences} from '../constants'; @@ -50,60 +48,6 @@ export function getMyPreferences() { }); } -export function makeDirectChannelVisibleIfNecessary(otherUserId: string): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - const state = getState(); - const myPreferences = getMyPreferencesSelector(state); - const currentUserId = getCurrentUserId(state); - - let preference = myPreferences[getPreferenceKey(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, otherUserId)]; - - if (!preference || preference.value === 'false') { - preference = { - user_id: currentUserId, - category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, - name: otherUserId, - value: 'true', - }; - dispatch(getProfilesByIds([otherUserId])); - dispatch(savePreferences(currentUserId, [preference])); - } - - return {data: true}; - }; -} - -export function makeGroupMessageVisibleIfNecessary(channelId: string): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - const state = getState(); - const myPreferences = getMyPreferencesSelector(state); - const currentUserId = getCurrentUserId(state); - const {channels} = state.entities.channels; - - let preference = myPreferences[getPreferenceKey(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, channelId)]; - - if (!preference || preference.value === 'false') { - preference = { - user_id: currentUserId, - category: Preferences.CATEGORY_GROUP_CHANNEL_SHOW, - name: channelId, - value: 'true', - }; - - if (channels[channelId]) { - dispatch(getMyChannelMember(channelId)); - } else { - dispatch(getChannelAndMyMember(channelId)); - } - - dispatch(getProfilesInChannel(channelId, 0)); - dispatch(savePreferences(currentUserId, [preference])); - } - - return {data: true}; - }; -} - export function setActionsMenuInitialisationState(initializationState: Record): ThunkActionFunc { return async (dispatch, getState) => { const state = getState(); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/search.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/search.test.ts index a4700e6d60..280b2cdd22 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/search.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/search.test.ts @@ -61,13 +61,9 @@ describe('Actions.Search', () => { await dispatch(Actions.searchPosts(TestHelper.basicTeam!.id, search1, false, false)); let state = getState(); - let {recent, results} = state.entities.search; + let {results} = state.entities.search; const {posts} = state.entities.posts; let current = state.entities.search.current[TestHelper.basicTeam!.id]; - expect(recent[TestHelper.basicTeam!.id]).toBeTruthy(); - let searchIsPresent = recent[TestHelper.basicTeam!.id].findIndex((r: {terms: string}) => r.terms === search1); - expect(searchIsPresent !== -1).toBeTruthy(); - expect(Object.keys(recent[TestHelper.basicTeam!.id]).length).toEqual(1); expect(results.length).toEqual(1); expect(posts[results[0]]).toBeTruthy(); expect(!current.isEnd).toBeTruthy(); @@ -80,60 +76,9 @@ describe('Actions.Search', () => { await dispatch(Actions.searchPostsWithParams(TestHelper.basicTeam!.id, {terms: search1, page: 1} as SearchParameter)); state = getState(); current = state.entities.search.current[TestHelper.basicTeam!.id]; - recent = state.entities.search.recent; results = state.entities.search.results; - expect(recent[TestHelper.basicTeam!.id]).toBeTruthy(); - searchIsPresent = recent[TestHelper.basicTeam!.id].findIndex((r: {terms: string}) => r.terms === search1); - expect(searchIsPresent !== -1).toBeTruthy(); - expect(Object.keys(recent[TestHelper.basicTeam!.id]).length).toEqual(1); expect(results.length).toEqual(1); expect(current.isEnd).toBeTruthy(); - - // DISABLED - // Test for posts from a user in a channel - //const search2 = `from: ${TestHelper.basicUser.username} in: ${TestHelper.basicChannel.name}`; - - //nock(Client4.getTeamsRoute(), `/${TestHelper.basicTeam.id}/posts/search`). - //post(`/${TestHelper.basicTeam.id}/posts/search`). - //reply(200, {order: [post1.id, post2.id, TestHelper.basicPost.id], posts: {[post1.id]: post1, [TestHelper.basicPost.id]: TestHelper.basicPost, [post2.id]: post2}}); - //nock(Client4.getChannelsRoute()). - //get(`/${TestHelper.basicChannel.id}/members/me`). - //reply(201, {user_id: TestHelper.basicUser.id, channel_id: TestHelper.basicChannel.id}); - // - //await dispatch(Actions.searchPosts( - //TestHelper.basicTeam.id, - //search2 - //)); - // - //state = getState(); - //recent = state.entities.search.recent; - //results = state.entities.search.results; - //searchIsPresent = recent[TestHelper.basicTeam.id].findIndex((r) => r.terms === search1); - //expect(searchIsPresent !== -1).toBeTruthy(); - //expect(Object.keys(recent[TestHelper.basicTeam.id]).length).toEqual(2); - //expect(results.length).toEqual(3); - - // Clear posts from the search store - //await dispatch(Actions.clearSearch()); - //state = getState(); - //recent = state.entities.search.recent; - //results = state.entities.search.results; - //searchIsPresent = recent[TestHelper.basicTeam.id].findIndex((r) => r.terms === search1); - //expect(searchIsPresent !== -1).toBeTruthy(); - //expect(Object.keys(recent[TestHelper.basicTeam.id]).length).toEqual(2); - //expect(results.length).toEqual(0); - - // Clear a recent term - //await dispatch(Actions.removeSearchTerms(TestHelper.basicTeam.id, search2)); - //state = getState(); - //recent = state.entities.search.recent; - //results = state.entities.search.results; - //searchIsPresent = recent[TestHelper.basicTeam.id].findIndex((r) => r.terms === search1); - //expect(searchIsPresent !== -1).toBeTruthy(); - //searchIsPresent = recent[TestHelper.basicTeam.id].findIndex((r) => r.terms === search2); - //expect(searchIsPresent === -1).toBeTruthy(); - //expect(Object.keys(recent[TestHelper.basicTeam.id]).length).toEqual(1); - //expect(results.length).toEqual(0); }); it('Perform Files Search', async () => { @@ -153,16 +98,12 @@ describe('Actions.Search', () => { get(`/${TestHelper.basicChannel!.id}/members/me`). reply(201, {user_id: TestHelper.basicUser!.id, channel_id: TestHelper.basicChannel!.id}); - await dispatch(Actions.searchFiles(TestHelper.basicTeam!.id, search1, false, false)); + await dispatch(Actions.searchFilesWithParams(TestHelper.basicTeam!.id, {terms: search1, is_or_search: false, include_deleted_channels: false, page: 0, per_page: Actions.WEBAPP_SEARCH_PER_PAGE})); let state = getState(); - let {recent, fileResults} = state.entities.search; + let {fileResults} = state.entities.search; const {filesFromSearch} = state.entities.files; let current = state.entities.search.current[TestHelper.basicTeam!.id]; - expect(recent[TestHelper.basicTeam!.id]).toBeTruthy(); - let searchIsPresent = recent[TestHelper.basicTeam!.id].findIndex((r: {terms: string}) => r.terms === search1); - expect(searchIsPresent !== -1).toBeTruthy(); - expect(Object.keys(recent[TestHelper.basicTeam!.id]).length).toEqual(1); expect(fileResults.length).toEqual(1); expect(filesFromSearch[fileResults[0]]).toBeTruthy(); expect(!current.isFilesEnd).toBeTruthy(); @@ -175,12 +116,7 @@ describe('Actions.Search', () => { await dispatch(Actions.searchFilesWithParams(TestHelper.basicTeam!.id, {terms: search1, page: 1} as SearchParameter)); state = getState(); current = state.entities.search.current[TestHelper.basicTeam!.id]; - recent = state.entities.search.recent; fileResults = state.entities.search.fileResults; - expect(recent[TestHelper.basicTeam!.id]).toBeTruthy(); - searchIsPresent = recent[TestHelper.basicTeam!.id].findIndex((r: {terms: string}) => r.terms === search1); - expect(searchIsPresent !== -1).toBeTruthy(); - expect(Object.keys(recent[TestHelper.basicTeam!.id]).length).toEqual(1); expect(fileResults.length).toEqual(1); expect(current.isFilesEnd).toBeTruthy(); }); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/search.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/search.ts index 620bd57fd1..70f8b3c324 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/search.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/search.ts @@ -19,7 +19,7 @@ import {receivedFiles} from './files'; import {forceLogoutIfNecessary} from './helpers'; import {getMentionsAndStatusesForPosts, receivedPosts} from './posts'; -const WEBAPP_SEARCH_PER_PAGE = 20; +export const WEBAPP_SEARCH_PER_PAGE = 20; export function getMissingChannelsFromPosts(posts: PostList['posts']): ThunkActionFunc { return async (dispatch, getState) => { @@ -182,10 +182,6 @@ export function searchFilesWithParams(teamId: string, params: SearchParameter): }; } -export function searchFiles(teamId: string, terms: string, isOrSearch: boolean, includeDeletedChannels: boolean) { // HARRISONTODO unused - return searchFilesWithParams(teamId, {terms, is_or_search: isOrSearch, include_deleted_channels: includeDeletedChannels, page: 0, per_page: WEBAPP_SEARCH_PER_PAGE}); -} - export function getMoreFilesForSearch(): NewActionFuncAsync { return async (dispatch, getState) => { const teamId = getCurrentTeamId(getState()); @@ -269,35 +265,7 @@ export function getPinnedPosts(channelId: string): NewActionFuncAsync { }; } -export function clearPinnedPosts(channelId: string): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch) => { - dispatch({ - type: SearchTypes.REMOVE_SEARCH_PINNED_POSTS, - data: { - channelId, - }, - }); - - return {data: true}; - }; -} - -export function removeSearchTerms(teamId: string, terms: string): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch) => { - dispatch({ - type: SearchTypes.REMOVE_SEARCH_TERM, - data: { - teamId, - terms, - }, - }); - - return {data: true}; - }; -} - export default { clearSearch, - removeSearchTerms, searchPosts, }; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts index 410627ff4e..2aa7fcc130 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts @@ -7,11 +7,11 @@ import nock from 'nock'; import type {Team} from '@mattermost/types/teams'; -import {GeneralTypes, UserTypes} from 'mattermost-redux/action_types'; +import {UserTypes} from 'mattermost-redux/action_types'; import * as Actions from 'mattermost-redux/actions/teams'; import {loadMe} from 'mattermost-redux/actions/users'; import {Client4} from 'mattermost-redux/client'; -import {General, RequestStatus} from 'mattermost-redux/constants'; +import {RequestStatus} from 'mattermost-redux/constants'; import TestHelper from '../../test/test_helper'; import configureStore from '../../test/test_store'; @@ -344,65 +344,6 @@ describe('Actions.Teams', () => { expect(patched.invite_id).toEqual(patchedInviteId); }); - it('Join Open Team', async () => { - const client = TestHelper.createClient4(); - - nock(Client4.getBaseRoute()). - post('/users'). - query(true). - reply(201, TestHelper.fakeUserWithId()); - const user = await client.createUser( - TestHelper.fakeUser(), - '', - '', - TestHelper.basicTeam!.invite_id, - ); - - nock(Client4.getBaseRoute()). - post('/users/login'). - reply(200, user); - await client.login(user.email, 'password1'); - - nock(Client4.getBaseRoute()). - post('/teams'). - reply(201, {...TestHelper.fakeTeamWithId(), allow_open_invite: true}); - const team = await client.createTeam({...TestHelper.fakeTeam(), allow_open_invite: true}); - - store.dispatch({type: GeneralTypes.RECEIVED_SERVER_VERSION, data: '4.0.0'}); - - nock(Client4.getBaseRoute()). - post('/teams/members/invite'). - query(true). - reply(201, {user_id: TestHelper.basicUser!.id, team_id: team.id}); - - nock(Client4.getBaseRoute()). - get(`/teams/${team.id}`). - reply(200, team); - - nock(Client4.getUserRoute('me')). - get('/teams/members'). - reply(200, [{user_id: TestHelper.basicUser!.id, roles: 'team_user', team_id: team.id}]); - - nock(Client4.getUserRoute('me')). - get('/teams/unread'). - query({params: {include_collapsed_threads: true}}). - reply(200, [{team_id: team.id, msg_count: 0, mention_count: 0}]); - - await store.dispatch(Actions.joinTeam(team.invite_id, team.id)); - - const state = store.getState(); - - const request = state.requests.teams.joinTeam; - - if (request.status !== RequestStatus.SUCCESS) { - throw new Error(JSON.stringify(request.error)); - } - - const {teams, myMembers} = state.entities.teams; - expect(teams[team.id]).toBeTruthy(); - expect(myMembers[team.id]).toBeTruthy(); - }); - it('getMyTeamMembers and getMyTeamUnreads', async () => { nock(Client4.getUserRoute('me')). get('/teams/members'). @@ -561,33 +502,6 @@ describe('Actions.Teams', () => { expect(members[TestHelper.basicTeam!.id][user.id]).toBeTruthy(); }); - it('addUsersToTeam', async () => { - nock(Client4.getBaseRoute()). - post('/users'). - reply(201, TestHelper.fakeUserWithId()); - const user = await TestHelper.basicClient4!.createUser(TestHelper.fakeUser(), '', ''); - - nock(Client4.getBaseRoute()). - post('/users'). - reply(201, TestHelper.fakeUserWithId()); - const user2 = await TestHelper.basicClient4!.createUser(TestHelper.fakeUser(), '', ''); - - nock(Client4.getTeamRoute(TestHelper.basicTeam!.id)). - post('/members/batch'). - reply(201, [{user_id: user.id, team_id: TestHelper.basicTeam!.id}, {user_id: user2.id, team_id: TestHelper.basicTeam!.id}]); - await store.dispatch(Actions.addUsersToTeam(TestHelper.basicTeam!.id, [user.id, user2.id])); - - const members = store.getState().entities.teams.membersInTeam; - const profilesInTeam = store.getState().entities.users.profilesInTeam; - - expect(members[TestHelper.basicTeam!.id]).toBeTruthy(); - expect(members[TestHelper.basicTeam!.id][user.id]).toBeTruthy(); - expect(members[TestHelper.basicTeam!.id][user2.id]).toBeTruthy(); - expect(profilesInTeam[TestHelper.basicTeam!.id]).toBeTruthy(); - expect(profilesInTeam[TestHelper.basicTeam!.id].has(user.id)).toBeTruthy(); - expect(profilesInTeam[TestHelper.basicTeam!.id].has(user2.id)).toBeTruthy(); - }); - describe('removeUserFromTeam', () => { const team = {id: 'team'}; const user = {id: 'user'}; @@ -684,31 +598,6 @@ describe('Actions.Teams', () => { }); }); - it('updateTeamMemberRoles', async () => { - nock(Client4.getBaseRoute()). - post('/users'). - reply(201, TestHelper.fakeUserWithId()); - const user = await TestHelper.basicClient4!.createUser(TestHelper.fakeUser(), '', ''); - - nock(Client4.getTeamRoute(TestHelper.basicTeam!.id)). - post('/members'). - reply(201, {user_id: user.id, team_id: TestHelper.basicTeam!.id}); - await store.dispatch(Actions.addUserToTeam(TestHelper.basicTeam!.id, user.id)); - - const roles = General.TEAM_USER_ROLE + ' ' + General.TEAM_ADMIN_ROLE; - - nock(Client4.getBaseRoute()). - put(`/teams/${TestHelper.basicTeam!.id}/members/${user.id}/roles`). - reply(200, {user_id: user.id, team_id: TestHelper.basicTeam!.id, roles}); - await store.dispatch(Actions.updateTeamMemberRoles(TestHelper.basicTeam!.id, user.id, roles.split(' '))); - - const members = store.getState().entities.teams.membersInTeam; - - expect(members[TestHelper.basicTeam!.id]).toBeTruthy(); - expect(members[TestHelper.basicTeam!.id][user.id]).toBeTruthy(); - expect(members[TestHelper.basicTeam!.id][user.id].roles).toEqual(roles.split(' ')); - }); - it('sendEmailInvitesToTeam', async () => { nock(Client4.getTeamRoute(TestHelper.basicTeam!.id)). post('/invite/email'). diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts index 525e9e498b..8423973ffa 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts @@ -16,8 +16,6 @@ import {loadRolesIfNeeded} from 'mattermost-redux/actions/roles'; import {getProfilesByIds, getStatusesByIds} from 'mattermost-redux/actions/users'; import {Client4} from 'mattermost-redux/client'; import {General} from 'mattermost-redux/constants'; -import {isCompatibleWithJoinViewTeamPermissions} from 'mattermost-redux/selectors/entities/general'; -import {isCollapsedThreadsEnabled} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; import type {ActionResult, DispatchFunc, GetStateFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; @@ -484,36 +482,6 @@ export function addUserToTeam(teamId: string, userId: string): NewActionFuncAsyn }; } -export function addUsersToTeam(teamId: string, userIds: string[]): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - let members; - try { - members = await Client4.addUsersToTeam(teamId, userIds); - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - dispatch(logError(error)); - return {error}; - } - - const profiles: Array> = []; - members.forEach((m: TeamMembership) => profiles.push({id: m.user_id})); - - dispatch(batchActions([ - { - type: UserTypes.RECEIVED_PROFILES_LIST_IN_TEAM, - data: profiles, - id: teamId, - }, - { - type: TeamTypes.RECEIVED_MEMBERS_IN_TEAM, - data: members, - }, - ])); - - return {data: members}; - }; -} - export function addUsersToTeamGracefully(teamId: string, userIds: string[]): NewActionFuncAsync { return async (dispatch, getState) => { let result: TeamMemberWithError[]; @@ -598,28 +566,6 @@ export function removeUserFromTeam(teamId: string, userId: string): NewActionFun }; } -export function updateTeamMemberRoles(teamId: string, userId: string, roles: string[]): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - try { - await Client4.updateTeamMemberRoles(teamId, userId, roles); - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - dispatch(logError(error)); - return {error}; - } - - const membersInTeam = getState().entities.teams.membersInTeam[teamId]; - if (membersInTeam && membersInTeam[userId]) { - dispatch({ - type: TeamTypes.RECEIVED_MEMBER_IN_TEAM, - data: {...membersInTeam[userId], roles}, - }); - } - - return {data: true}; - }; -} - export function sendEmailInvitesToTeam(teamId: string, emails: string[]) { return bindClientFunc({ clientFunc: Client4.sendEmailInvitesToTeam, @@ -707,37 +653,6 @@ export function checkIfTeamExists(teamName: string): NewActionFuncAsync }; } -export function joinTeam(inviteId: string, teamId: string): NewActionFuncAsync { // HARRISONTODO - return async (dispatch, getState) => { - dispatch({type: TeamTypes.JOIN_TEAM_REQUEST, data: null}); - - const state = getState(); - try { - if (isCompatibleWithJoinViewTeamPermissions(state)) { - const currentUserId = state.entities.users.currentUserId; - await Client4.addToTeam(teamId, currentUserId); - } else { - await Client4.joinTeam(inviteId); - } - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - dispatch({type: TeamTypes.JOIN_TEAM_FAILURE, error}); - dispatch(logError(error)); - return {error}; - } - - dispatch(getMyTeamUnreads(isCollapsedThreadsEnabled(state))); - - await Promise.all([ - dispatch(getTeam(teamId)), - dispatch(getMyTeamMembers()), - ]); - - dispatch({type: TeamTypes.JOIN_TEAM_SUCCESS, data: null}); - return {data: true}; - }; -} - export function setTeamIcon(teamId: string, imageData: File): NewActionFuncAsync { return async (dispatch) => { await Client4.setTeamIcon(teamId, imageData); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/users.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/users.test.ts index 2101a0d607..4840f8210e 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/users.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/users.test.ts @@ -208,9 +208,6 @@ describe('Actions.Users', () => { // channel stats is not empty expect(channels.stats).toEqual({}); - // selected post id is not empty - expect(posts.selectedPostId).toEqual(''); - // current focused post id is not empty expect(posts.currentFocusedPostId).toEqual(''); @@ -1243,43 +1240,6 @@ describe('Actions.Users', () => { expect(!userAccessTokens[data.id].token).toBeTruthy(); }); - it('getUserAccessTokens', async () => { - TestHelper.mockLogin(); - store.dispatch({ - type: UserTypes.LOGIN_SUCCESS, - }); - await store.dispatch(Actions.loadMe()); - - const currentUserId = store.getState().entities.users.currentUserId; - - nock(Client4.getBaseRoute()). - post(`/users/${currentUserId}/tokens`). - reply(201, {id: 'someid', token: 'sometoken', description: 'test token', user_id: currentUserId}); - - const {data} = await store.dispatch(Actions.createUserAccessToken(currentUserId, 'test token')); - - nock(Client4.getBaseRoute()). - get('/users/tokens'). - query(true). - reply(200, [{id: data.id, description: 'test token', user_id: currentUserId}]); - - await store.dispatch(Actions.getUserAccessTokens()); - - const {myUserAccessTokens} = store.getState().entities.users; - const {userAccessTokensByUser, userAccessTokens} = store.getState().entities.admin; - - expect(myUserAccessTokens).toBeTruthy(); - expect(myUserAccessTokens[data.id]).toBeTruthy(); - expect(!myUserAccessTokens[data.id].token).toBeTruthy(); - expect(userAccessTokensByUser).toBeTruthy(); - expect(userAccessTokensByUser[currentUserId]).toBeTruthy(); - expect(userAccessTokensByUser[currentUserId][data.id]).toBeTruthy(); - expect(!userAccessTokensByUser[currentUserId][data.id].token).toBeTruthy(); - expect(userAccessTokens).toBeTruthy(); - expect(userAccessTokens[data.id]).toBeTruthy(); - expect(!userAccessTokens[data.id].token).toBeTruthy(); - }); - it('getUserAccessTokensForUser', async () => { TestHelper.mockLogin(); store.dispatch({ diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts index 7688562801..6165493aea 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts @@ -872,45 +872,6 @@ export function searchProfiles(term: string, options: any = {}): NewActionFuncAs }; } -let statusIntervalId: NodeJS.Timeout|null; -export function startPeriodicStatusUpdates(): NewActionFuncAsync { // HARRISONTODO unused - return async (dispatch, getState) => { - if (statusIntervalId) { - clearInterval(statusIntervalId); - } - - statusIntervalId = setInterval( - () => { - const {statuses} = getState().entities.users; - - if (!statuses) { - return; - } - - const userIds = Object.keys(statuses); - if (!userIds.length) { - return; - } - - dispatch(getStatusesByIds(userIds)); - }, - General.STATUS_INTERVAL, - ); - - return {data: true}; - }; -} - -export function stopPeriodicStatusUpdates(): NewActionFuncAsync { // HARRISONTODO unused - return async () => { - if (statusIntervalId) { - clearInterval(statusIntervalId); - } - - return {data: true}; - }; -} - export function updateMe(user: Partial): NewActionFuncAsync { return async (dispatch) => { dispatch({type: UserTypes.UPDATE_ME_REQUEST, data: null}); @@ -1209,27 +1170,6 @@ export function getUserAccessToken(tokenId: string): NewActionFuncAsync { - let data; - - try { - data = await Client4.getUserAccessTokens(page, perPage); - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - dispatch(logError(error)); - return {error}; - } - - dispatch({ - type: AdminTypes.RECEIVED_USER_ACCESS_TOKENS, - data, - }); - - return {data}; - }; -} - export function getUserAccessTokensForUser(userId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): NewActionFuncAsync { return async (dispatch, getState) => { let data; @@ -1369,8 +1309,6 @@ export default { revokeSessionsForAllUsers, getUserAudits, searchProfiles, - startPeriodicStatusUpdates, - stopPeriodicStatusUpdates, updateMe, updateUserRoles, updateUserMfa, diff --git a/webapp/channels/src/packages/mattermost-redux/src/constants/general.ts b/webapp/channels/src/packages/mattermost-redux/src/constants/general.ts index 776620d9b2..1b55ad0554 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/constants/general.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/constants/general.ts @@ -13,7 +13,6 @@ export default { TEAMS_CHUNK_SIZE: 50, JOBS_CHUNK_SIZE: 50, SEARCH_TIMEOUT_MILLISECONDS: 100, - STATUS_INTERVAL: 60000, AUTOCOMPLETE_SPLIT_CHARACTERS: ['.', '-', '_'], OUT_OF_OFFICE: 'ooo', OFFLINE: 'offline', diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/admin.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/admin.ts index bcb96e44a0..8f056d2f3c 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/admin.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/admin.ts @@ -295,15 +295,6 @@ function userAccessTokens(state: Record = {}, action: A return {...state, ...nextState}; } - case AdminTypes.RECEIVED_USER_ACCESS_TOKENS: { - const nextState: any = {}; - - for (const uat of action.data) { - nextState[uat.id] = uat; - } - - return {...state, ...nextState}; - } case UserTypes.REVOKED_USER_ACCESS_TOKEN: { const nextState = {...state}; Reflect.deleteProperty(nextState, action.data); @@ -341,16 +332,6 @@ function userAccessTokensByUser(state: RelationOneToOne { }); }); - describe('UPDATE_CHANNEL_HEADER', () => { - test('should update channel header', () => { - const state = deepFreeze(channelsReducer({ - channels: { - channel1: { - id: 'channel1', - header: 'old', - }, - channel2: { - id: 'channel2', - }, - }, - }, {})); - - const nextState = channelsReducer(state, { - type: ChannelTypes.UPDATE_CHANNEL_HEADER, - data: { - channelId: 'channel1', - header: 'new', - }, - }); - - expect(nextState).not.toBe(state); - expect(nextState.channels.channel1).toEqual({ - id: 'channel1', - header: 'new', - }); - expect(nextState.channels.channel2).toBe(state.channels.channel2); - }); - - test('should do nothing for a channel that is not loaded', () => { - const state = deepFreeze(channelsReducer({ - channels: { - channel1: { - id: 'channel1', - header: 'old', - }, - channel2: { - id: 'channel2', - }, - }, - }, {})); - - const nextState = channelsReducer(state, { - type: ChannelTypes.UPDATE_CHANNEL_HEADER, - data: { - channelId: 'channel3', - header: 'new', - }, - }); - - expect(nextState).toBe(state); - }); - }); - - describe('UPDATE_CHANNEL_PURPOSE', () => { - test('should update channel purpose', () => { - const state = deepFreeze(channelsReducer({ - channels: { - channel1: { - id: 'channel1', - purpose: 'old', - }, - channel2: { - id: 'channel2', - }, - }, - }, {})); - - const nextState = channelsReducer(state, { - type: ChannelTypes.UPDATE_CHANNEL_PURPOSE, - data: { - channelId: 'channel1', - purpose: 'new', - }, - }); - - expect(nextState).not.toBe(state); - expect(nextState.channels.channel1).toEqual({ - id: 'channel1', - purpose: 'new', - }); - expect(nextState.channels.channel2).toBe(state.channels.channel2); - }); - - test('should do nothing for a channel that is not loaded', () => { - const state = deepFreeze(channelsReducer({ - channels: { - channel1: { - id: 'channel1', - header: 'old', - }, - channel2: { - id: 'channel2', - }, - }, - }, {})); - - const nextState = channelsReducer(state, { - type: ChannelTypes.UPDATE_CHANNEL_PURPOSE, - data: { - channelId: 'channel3', - purpose: 'new', - }, - }); - - expect(nextState).toBe(state); - }); - }); - describe('REMOVE_MEMBER_FROM_CHANNEL', () => { test('should remove the channel member', () => { const state = deepFreeze(channelsReducer({ diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/channels.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/channels.ts index 967931acdd..c746d15f65 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/channels.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/channels.ts @@ -147,36 +147,6 @@ function channels(state: IDMappedObjects = {}, action: AnyAction) { }, }; } - case ChannelTypes.UPDATE_CHANNEL_HEADER: { - const {channelId, header} = action.data; - - if (!state[channelId]) { - return state; - } - - return { - ...state, - [channelId]: { - ...state[channelId], - header, - }, - }; - } - case ChannelTypes.UPDATE_CHANNEL_PURPOSE: { - const {channelId, purpose} = action.data; - - if (!state[channelId]) { - return state; - } - - return { - ...state, - [channelId]: { - ...state[channelId], - purpose, - }, - }; - } case ChannelTypes.LEAVE_CHANNEL: { if (action.data) { const nextState = {...state}; diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/general.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/general.ts index 0fc765cdf7..0dc74509ea 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/general.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/general.ts @@ -23,17 +23,6 @@ function config(state: Partial = {}, action: AnyAction) { } } -function dataRetentionPolicy(state: any = {}, action: AnyAction) { - switch (action.type) { - case GeneralTypes.RECEIVED_DATA_RETENTION_POLICY: - return action.data; - case UserTypes.LOGOUT_SUCCESS: - return {}; - default: - return state; - } -} - function license(state: ClientLicense = {}, action: AnyAction) { switch (action.type) { case GeneralTypes.CLIENT_LICENSE_RECEIVED: @@ -61,8 +50,6 @@ function serverVersion(state = '', action: AnyAction) { function warnMetricsStatus(state: any = {}, action: AnyAction) { switch (action.type) { - case GeneralTypes.WARN_METRICS_STATUS_RECEIVED: - return action.data; case GeneralTypes.WARN_METRIC_STATUS_RECEIVED: { const nextState = {...state}; nextState[action.data.id] = action.data; @@ -102,7 +89,6 @@ function firstAdminCompleteSetup(state = false, action: AnyAction) { export default combineReducers({ config, - dataRetentionPolicy, license, serverVersion, warnMetricsStatus, diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.ts index 49d557d2bf..c17f50c9bf 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.ts @@ -1136,17 +1136,6 @@ export function postsInThread(state: RelationOneToMany = {}, action: } } -function selectedPostId(state = '', action: AnyAction) { - switch (action.type) { - case PostTypes.RECEIVED_POST_SELECTED: - return action.data; - case UserTypes.LOGOUT_SUCCESS: - return ''; - default: - return state; - } -} - export function postEditHistory(state: Post[] = [], action: AnyAction) { switch (action.type) { case PostTypes.RECEIVED_POST_HISTORY: @@ -1171,18 +1160,6 @@ function currentFocusedPostId(state = '', action: AnyAction) { export function reactions(state: RelationOneToOne> = {}, action: AnyAction) { switch (action.type) { - case PostTypes.RECEIVED_REACTIONS: { - const reactionsList = action.data; - const nextReactions: Record = {}; - reactionsList.forEach((reaction: Reaction) => { - nextReactions[reaction.user_id + '-' + reaction.emoji_name] = reaction; - }); - - return { - ...state, - [action.postId!]: nextReactions, - }; - } case PostTypes.RECEIVED_REACTION: { const reaction = action.data as Reaction; const nextReactions = {...(state[reaction.post_id] || {})}; @@ -1588,9 +1565,6 @@ export default function reducer(state: Partial = {}, action: AnyActi // with no guaranteed order postsInThread: postsInThread(state.postsInThread, action, state.posts!), - // The current selected post - selectedPostId: selectedPostId(state.selectedPostId, action), - // The post history of selected post postEditHistory: postEditHistory(state.postEditHistory, action), @@ -1616,7 +1590,6 @@ export default function reducer(state: Partial = {}, action: AnyActi if (state.posts === nextState.posts && state.postsInChannel === nextState.postsInChannel && state.postsInThread === nextState.postsInThread && state.pendingPostIds === nextState.pendingPostIds && - state.selectedPostId === nextState.selectedPostId && state.postEditHistory === nextState.postEditHistory && state.currentFocusedPostId === nextState.currentFocusedPostId && state.reactions === nextState.reactions && diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/search.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/search.ts index e7686fb0fb..89389cf199 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/search.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/search.ts @@ -6,7 +6,6 @@ import {combineReducers} from 'redux'; import type {Post} from '@mattermost/types/posts'; import type {PreferenceType} from '@mattermost/types/preferences'; -import type {Search} from '@mattermost/types/search'; import {PostTypes, PreferenceTypes, SearchTypes, UserTypes} from 'mattermost-redux/action_types'; import {Preferences} from 'mattermost-redux/constants'; @@ -196,61 +195,6 @@ function pinned(state: Record = {}, action: AnyAction) { return removePinnedPost(state, action.data); } - case SearchTypes.REMOVE_SEARCH_PINNED_POSTS: { - const {channelId} = action.data; - const nextState = {...state}; - if (nextState[channelId]) { - Reflect.deleteProperty(nextState, channelId); - return nextState; - } - - return state; - } - case UserTypes.LOGOUT_SUCCESS: - return {}; - - default: - return state; - } -} - -function recent(state: Record = {}, action: AnyAction) { - const {data, type} = action; - - switch (type) { - case SearchTypes.RECEIVED_SEARCH_TERM: { - const nextState = {...state}; - const {teamId, params} = data; - const {terms, isOrSearch} = params || {}; - const team = [...(nextState[teamId] || [])]; - const index = team.findIndex((r) => r.terms === terms); - if (index === -1) { - team.push({terms, isOrSearch}); - } else { - team[index] = {terms, isOrSearch}; - } - return { - ...nextState, - [teamId]: team, - }; - } - case SearchTypes.REMOVE_SEARCH_TERM: { - const nextState = {...state}; - const {teamId, terms} = data; - const team = [...(nextState[teamId] || [])]; - const index = team.findIndex((r) => r.terms === terms); - - if (index !== -1) { - team.splice(index, 1); - - return { - ...nextState, - [teamId]: team, - }; - } - - return nextState; - } case UserTypes.LOGOUT_SUCCESS: return {}; @@ -341,10 +285,6 @@ export default combineReducers({ // Object where every key is a post id mapping to an array of matched words in that post matches, - // Object where every key is a team composed with - // an object where the key is the term and the value indicates is "or" search - recent, - // Object holding the current searches for every team current, diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/requests/channels.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/requests/channels.ts index e37c622114..29743ffb94 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/requests/channels.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/requests/channels.ts @@ -30,16 +30,6 @@ function createChannel(state: RequestStatusType = initialRequestState(), action: ); } -function updateChannel(state: RequestStatusType = initialRequestState(), action: AnyAction): RequestStatusType { - return handleRequest( - ChannelTypes.UPDATE_CHANNEL_REQUEST, - ChannelTypes.UPDATE_CHANNEL_SUCCESS, - ChannelTypes.UPDATE_CHANNEL_FAILURE, - state, - action, - ); -} - function getChannels(state: RequestStatusType = initialRequestState(), action: AnyAction): RequestStatusType { return handleRequest( ChannelTypes.GET_CHANNELS_REQUEST, @@ -65,5 +55,4 @@ export default combineReducers({ getAllChannels, myChannels, createChannel, - updateChannel, }); diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/requests/teams.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/requests/teams.ts index da4c5073c2..6ef5e58352 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/requests/teams.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/requests/teams.ts @@ -30,18 +30,7 @@ function getTeams(state: RequestStatusType = initialRequestState(), action: AnyA ); } -function joinTeam(state: RequestStatusType = initialRequestState(), action: AnyAction): RequestStatusType { - return handleRequest( - TeamTypes.JOIN_TEAM_REQUEST, - TeamTypes.JOIN_TEAM_SUCCESS, - TeamTypes.JOIN_TEAM_FAILURE, - state, - action, - ); -} - export default combineReducers({ getTeams, getMyTeams, - joinTeam, }); diff --git a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/teams.test.ts b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/teams.test.ts index 9134919473..11ddb7d797 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/teams.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/teams.test.ts @@ -107,13 +107,6 @@ describe('Selectors.Teams', () => { expect(joinableTeams[1]).toBe(openTeams[1]); }); - it('getListableTeams', () => { - const openTeams = [team3, team4]; - const listableTeams = Selectors.getListableTeams(testState); - expect(listableTeams[0]).toBe(openTeams[0]); - expect(listableTeams[1]).toBe(openTeams[1]); - }); - it('getListedJoinableTeams', () => { const openTeams = [team4, team3]; const joinableTeams = Selectors.getSortedListableTeams(testState, 'en'); @@ -227,82 +220,6 @@ describe('Selectors.Teams', () => { expect(joinableTeams[3]).toBe(openTeams[1]); }); - it('getListableTeamsUsingPermissions', () => { - const privateTeams = [team1, team2]; - const openTeams = [team3, team4]; - let modifiedState = { - entities: { - ...testState.entities, - teams: { - ...testState.entities.teams, - myMembers: {}, - }, - roles: { - roles: { - system_user: { - ...testState.entities.roles.roles.system_user, - permissions: ['list_private_teams'], - }, - }, - }, - general: { - serverVersion: '5.10.0', - }, - }, - } as GlobalState; - let listableTeams = Selectors.getListableTeams(modifiedState); - expect(listableTeams[0]).toBe(privateTeams[0]); - expect(listableTeams[1]).toBe(privateTeams[1]); - - modifiedState = { - entities: { - ...testState.entities, - teams: { - ...testState.entities.teams, - myMembers: {}, - }, - roles: { - roles: { - system_user: { - permissions: ['list_public_teams'], - }, - }, - }, - general: { - serverVersion: '5.10.0', - }, - }, - } as GlobalState; - listableTeams = Selectors.getListableTeams(modifiedState); - expect(listableTeams[0]).toBe(openTeams[0]); - expect(listableTeams[1]).toBe(openTeams[1]); - - modifiedState = { - entities: { - ...testState.entities, - teams: { - ...testState.entities.teams, - myMembers: {}, - }, - roles: { - roles: { - system_user: { - permissions: ['list_public_teams', 'list_private_teams'], - }, - }, - }, - general: { - serverVersion: '5.10.0', - }, - }, - } as GlobalState; - listableTeams = Selectors.getListableTeams(modifiedState); - expect(listableTeams[0]).toBe(privateTeams[0]); - expect(listableTeams[1]).toBe(privateTeams[1]); - expect(listableTeams[2]).toBe(openTeams[0]); - expect(listableTeams[3]).toBe(openTeams[1]); - }); - it('getSortedListableTeamsUsingPermissions', () => { const privateTeams = [team2, team1]; const openTeams = [team4, team3]; diff --git a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/teams.ts b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/teams.ts index e6b75beff3..2339ef2d1b 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/teams.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/teams.ts @@ -226,15 +226,6 @@ export const getListableTeamIds: (state: GlobalState) => Array = cre }, ); -export const getListableTeams: (state: GlobalState) => Team[] = createSelector( - 'getListableTeams', - getTeams, - getListableTeamIds, - (teams, listableTeamIds) => { - return listableTeamIds.map((id) => teams[id]); - }, -); - export const getSortedListableTeams: (state: GlobalState, locale: string) => Team[] = createSelector( 'getSortedListableTeams', getTeams, diff --git a/webapp/channels/src/packages/mattermost-redux/src/store/initial_state.ts b/webapp/channels/src/packages/mattermost-redux/src/store/initial_state.ts index 33388b13a1..5c86e7468e 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/store/initial_state.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/store/initial_state.ts @@ -10,7 +10,6 @@ const state: GlobalState = { entities: { general: { config: {}, - dataRetentionPolicy: {}, license: {}, serverVersion: '', warnMetricsStatus: {}, @@ -75,7 +74,6 @@ const state: GlobalState = { postEditHistory: [], reactions: {}, openGraph: {}, - selectedPostId: '', currentFocusedPostId: '', messagesHistory: { messages: [], @@ -142,7 +140,6 @@ const state: GlobalState = { results: [], fileResults: [], current: {}, - recent: {}, matches: {}, flagged: [], pinned: {}, @@ -245,10 +242,6 @@ const state: GlobalState = { status: 'not_started', error: null, }, - updateChannel: { - status: 'not_started', - error: null, - }, }, general: { websocket: { @@ -279,10 +272,6 @@ const state: GlobalState = { status: 'not_started', error: null, }, - joinTeam: { - status: 'not_started', - error: null, - }, }, users: { login: { diff --git a/webapp/channels/src/packages/mattermost-redux/src/utils/post_list.test.ts b/webapp/channels/src/packages/mattermost-redux/src/utils/post_list.test.ts index 9df0bff0e3..fa5e87e388 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/utils/post_list.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/utils/post_list.test.ts @@ -762,7 +762,13 @@ describe('makeCombineUserActivityPosts', () => { ...state.entities, posts: { ...state.entities.posts, - selectedPostId: 'post2', + messagesHistory: { + messages: [], + index: { + post: 4, + comment: 3, + }, + }, }, }, }; diff --git a/webapp/channels/src/packages/mattermost-redux/src/utils/post_list.ts b/webapp/channels/src/packages/mattermost-redux/src/utils/post_list.ts index 318c37fdf6..fdd69897b0 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/utils/post_list.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/utils/post_list.ts @@ -58,7 +58,7 @@ export function makeFilterPostsAndAddSeparators() { (state: GlobalState, {postIds}: PostFilterOptions) => getPostsForIds(state, postIds), (state: GlobalState, {lastViewedAt}: PostFilterOptions) => lastViewedAt, (state: GlobalState, {indicateNewMessages}: PostFilterOptions) => indicateNewMessages, - (state) => state.entities.posts.selectedPostId, + () => '', // This previously returned state.entities.posts.selectedPostId which stopped being set at some point getCurrentUser, shouldShowJoinLeaveMessages, (posts, lastViewedAt, indicateNewMessages, selectedPostId, currentUser, showJoinLeave) => { diff --git a/webapp/channels/src/reducers/storage.test.ts b/webapp/channels/src/reducers/storage.test.ts index 484bbeda1d..d2bc89080c 100644 --- a/webapp/channels/src/reducers/storage.test.ts +++ b/webapp/channels/src/reducers/storage.test.ts @@ -10,26 +10,6 @@ type ReducerState = ReturnType; describe('Reducers.Storage', () => { const now = new Date(); - it('Storage.SET_ITEM', () => { - const nextState = storageReducer( - { - storage: {}, - } as ReducerState, - { - type: StorageTypes.SET_ITEM, - data: { - name: 'key', - prefix: 'user_id_', - value: 'value', - timestamp: now, - }, - }, - ); - expect(nextState.storage).toEqual({ - user_id_key: {value: 'value', timestamp: now}, - }); - }); - it('Storage.SET_GLOBAL_ITEM', () => { const nextState = storageReducer( { @@ -49,37 +29,6 @@ describe('Reducers.Storage', () => { }); }); - it('Storage.REMOVE_ITEM', () => { - let nextState = storageReducer( - { - storage: { - user_id_key: 'value', - }, - } as unknown as ReducerState, - { - type: StorageTypes.REMOVE_ITEM, - data: { - name: 'key', - prefix: 'user_id_', - }, - }, - ); - expect(nextState.storage).toEqual({}); - nextState = storageReducer( - { - storage: {}, - } as ReducerState, - { - type: StorageTypes.REMOVE_ITEM, - data: { - name: 'key', - prefix: 'user_id_', - }, - }, - ); - expect(nextState.storage).toEqual({}); - }); - it('Storage.REMOVE_GLOBAL_ITEM', () => { let nextState = storageReducer( { diff --git a/webapp/channels/src/reducers/storage.ts b/webapp/channels/src/reducers/storage.ts index 15301798a6..ed25fc7cd3 100644 --- a/webapp/channels/src/reducers/storage.ts +++ b/webapp/channels/src/reducers/storage.ts @@ -38,25 +38,6 @@ function storage(state: Record = {}, action: AnyAction) { return nextState; } - case StorageTypes.SET_ITEM: { - if (!state[action.data.prefix + action.data.name] || - !state[action.data.prefix + action.data.name].timestamp || - state[action.data.prefix + action.data.name].timestamp < action.data.timestamp - ) { - const nextState = {...state}; - nextState[action.data.prefix + action.data.name] = { - timestamp: action.data.timestamp, - value: action.data.value, - }; - return nextState; - } - return state; - } - case StorageTypes.REMOVE_ITEM: { - const nextState = {...state}; - Reflect.deleteProperty(nextState, action.data.prefix + action.data.name); - return nextState; - } case StorageTypes.SET_GLOBAL_ITEM: { if (!state[action.data.name] || !state[action.data.name].timestamp || diff --git a/webapp/channels/src/reducers/views/channel_sidebar.ts b/webapp/channels/src/reducers/views/channel_sidebar.ts index 3dbe67654d..24052fa69f 100644 --- a/webapp/channels/src/reducers/views/channel_sidebar.ts +++ b/webapp/channels/src/reducers/views/channel_sidebar.ts @@ -129,23 +129,10 @@ export function lastSelectedChannel(state = '', action: AnyAction): string { } } -function firstChannelName(state = '', action: AnyAction) { - switch (action.type) { - case ActionTypes.FIRST_CHANNEL_NAME: - return action.data; - - case UserTypes.LOGOUT_SUCCESS: - return ''; - default: - return state; - } -} - export default combineReducers({ unreadFilterEnabled, draggingState, newCategoryIds, multiSelectedChannelIds, lastSelectedChannel, - firstChannelName, }); diff --git a/webapp/channels/src/selectors/onboarding.ts b/webapp/channels/src/selectors/onboarding.ts index 96aa9d624a..6ec6afad53 100644 --- a/webapp/channels/src/selectors/onboarding.ts +++ b/webapp/channels/src/selectors/onboarding.ts @@ -26,12 +26,8 @@ const getFirstChannelNamePref = createSelector( }, ); -export function getFirstChannelNameViews(state: GlobalState) { - return state.views.channelSidebar.firstChannelName; -} - export function getFirstChannelName(state: GlobalState) { - return getFirstChannelNameViews(state) || getFirstChannelNamePref(state)?.value || ''; + return getFirstChannelNamePref(state)?.value || ''; } export function getShowLaunchingWorkspace(state: GlobalState) { diff --git a/webapp/channels/src/selectors/storage.test.ts b/webapp/channels/src/selectors/storage.test.ts index 0fb2b6c763..451c0739b3 100644 --- a/webapp/channels/src/selectors/storage.test.ts +++ b/webapp/channels/src/selectors/storage.test.ts @@ -3,8 +3,6 @@ import * as Selectors from 'selectors/storage'; -import {getPrefix} from 'utils/storage_utils'; - import type {GlobalState} from 'types/store'; describe('Selectors.Storage', () => { @@ -27,23 +25,9 @@ describe('Selectors.Storage', () => { }, } as unknown as GlobalState; - it('getPrefix', () => { - expect(getPrefix({} as GlobalState)).toEqual('unknown_'); - expect(getPrefix({entities: {}} as GlobalState)).toEqual('unknown_'); - expect(getPrefix({entities: {users: {currentUserId: 'not-exists'}}} as GlobalState)).toEqual('unknown_'); - expect(getPrefix({entities: {users: {currentUserId: 'not-exists', profiles: {}}}} as GlobalState)).toEqual('unknown_'); - expect(getPrefix({entities: {users: {currentUserId: 'exists', profiles: {exists: {id: 'user_id'}}}}} as unknown as GlobalState)).toEqual('user_id_'); - }); - it('makeGetGlobalItem', () => { expect(Selectors.makeGetGlobalItem('not-existing-global-item', undefined)(testState)).toEqual(undefined); expect(Selectors.makeGetGlobalItem('not-existing-global-item', 'default')(testState)).toEqual('default'); expect(Selectors.makeGetGlobalItem('global-item', undefined)(testState)).toEqual('global-item-value'); }); - - it('makeGetItem', () => { - expect(Selectors.makeGetItem('not-existing-item', undefined)(testState)).toEqual(undefined); - expect(Selectors.makeGetItem('not-existing-item', 'default')(testState)).toEqual('default'); - expect(Selectors.makeGetItem('item', undefined)(testState)).toEqual('item-value'); - }); }); diff --git a/webapp/channels/src/selectors/storage.ts b/webapp/channels/src/selectors/storage.ts index d5a20ae72f..00392ea7ed 100644 --- a/webapp/channels/src/selectors/storage.ts +++ b/webapp/channels/src/selectors/storage.ts @@ -1,8 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {getPrefix} from 'utils/storage_utils'; - import type {GlobalState} from 'types/store'; export const getGlobalItem = (state: GlobalState, name: string, defaultValue: T) => { @@ -11,16 +9,6 @@ export const getGlobalItem = (state: GlobalState, name: string, default return getItemFromStorage(storage, name, defaultValue); }; -export const getItem = (state: GlobalState, name: string, defaultValue: T) => { - return getGlobalItem(state, getPrefix(state) + name, defaultValue); -}; - -export const makeGetItem = (name: string, defaultValue: T) => { - return (state: GlobalState) => { - return getItem(state, name, defaultValue); - }; -}; - export const makeGetGlobalItem = (name: string, defaultValue: T) => { return (state: GlobalState) => { return getGlobalItem(state, name, defaultValue); diff --git a/webapp/channels/src/types/store/views.ts b/webapp/channels/src/types/store/views.ts index 1a61f3493b..e3bdcb8809 100644 --- a/webapp/channels/src/types/store/views.ts +++ b/webapp/channels/src/types/store/views.ts @@ -175,7 +175,6 @@ export type ViewsState = { newCategoryIds: string[]; multiSelectedChannelIds: string[]; lastSelectedChannel: string; - firstChannelName: string; }; statusDropdown: { diff --git a/webapp/channels/src/utils/constants.tsx b/webapp/channels/src/utils/constants.tsx index a26ddc7ae9..a1ce2264c7 100644 --- a/webapp/channels/src/utils/constants.tsx +++ b/webapp/channels/src/utils/constants.tsx @@ -11,6 +11,7 @@ import keyMirror from 'key-mirror'; import {CustomStatusDuration} from '@mattermost/types/users'; +import {Preferences as ReduxPreferences} from 'mattermost-redux/constants'; import Permissions from 'mattermost-redux/constants/permissions'; import * as PostListUtils from 'mattermost-redux/utils/post_list'; @@ -62,8 +63,8 @@ export const PreviousViewedTypes = { export const Preferences = { CATEGORY_CHANNEL_OPEN_TIME: 'channel_open_time', - CATEGORY_DIRECT_CHANNEL_SHOW: 'direct_channel_show', - CATEGORY_GROUP_CHANNEL_SHOW: 'group_channel_show', + CATEGORY_DIRECT_CHANNEL_SHOW: ReduxPreferences.CATEGORY_DIRECT_CHANNEL_SHOW, + CATEGORY_GROUP_CHANNEL_SHOW: ReduxPreferences.CATEGORY_GROUP_CHANNEL_SHOW, CATEGORY_DISPLAY_SETTINGS: 'display_settings', CATEGORY_SIDEBAR_SETTINGS: 'sidebar_settings', CATEGORY_ADVANCED_SETTINGS: 'advanced_settings', @@ -315,8 +316,6 @@ export const ActionTypes = keyMirror({ SUPPRESS_RHS: null, UNSUPPRESS_RHS: null, - FIRST_CHANNEL_NAME: null, - SET_EDIT_CHANNEL_MEMBERS: null, NEEDS_LOGGED_IN_LIMIT_REACHED_CHECK: null, @@ -883,8 +882,6 @@ export const SearchTypes = keyMirror({ }); export const StorageTypes = keyMirror({ - SET_ITEM: null, - REMOVE_ITEM: null, SET_GLOBAL_ITEM: null, REMOVE_GLOBAL_ITEM: null, ACTION_ON_GLOBAL_ITEMS_WITH_PREFIX: null, diff --git a/webapp/channels/src/utils/storage_utils.ts b/webapp/channels/src/utils/storage_utils.ts index 0535f02ff4..4900674b4f 100644 --- a/webapp/channels/src/utils/storage_utils.ts +++ b/webapp/channels/src/utils/storage_utils.ts @@ -1,23 +1,10 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import type {GlobalState} from '@mattermost/types/store'; - import type {DraftInfo} from 'types/store/draft'; import {StoragePrefixes} from './constants'; -export function getPrefix(state: GlobalState) { - if (state && state.entities && state.entities.users && state.entities.users.profiles) { - const user = state.entities.users.profiles[state.entities.users.currentUserId]; - if (user) { - return user.id + '_'; - } - } - - return 'unknown_'; -} - export function getDraftInfoFromKey(key: string, prefix: string): DraftInfo | null { const keyArr = key.split('_'); if (prefix === StoragePrefixes.DRAFT) { diff --git a/webapp/platform/types/src/general.ts b/webapp/platform/types/src/general.ts index 692eb0c455..86863ebb38 100644 --- a/webapp/platform/types/src/general.ts +++ b/webapp/platform/types/src/general.ts @@ -5,7 +5,6 @@ import {ClientConfig, ClientLicense, WarnMetricStatus} from './config'; export type GeneralState = { config: Partial; - dataRetentionPolicy: any; firstAdminVisitMarketplaceStatus: boolean; firstAdminCompleteSetup: boolean; license: ClientLicense; diff --git a/webapp/platform/types/src/posts.ts b/webapp/platform/types/src/posts.ts index b3495bf4e6..f02456e376 100644 --- a/webapp/platform/types/src/posts.ts +++ b/webapp/platform/types/src/posts.ts @@ -146,7 +146,6 @@ export type PostsState = { reactions: RelationOneToOne>; openGraph: RelationOneToOne>; pendingPostIds: string[]; - selectedPostId: string; postEditHistory: Post[]; currentFocusedPostId: string; messagesHistory: MessageHistory; @@ -221,4 +220,4 @@ export type PostInfo = { team_type: TeamType; team_display_name: string; has_joined_team: boolean; -} \ No newline at end of file +} diff --git a/webapp/platform/types/src/requests.ts b/webapp/platform/types/src/requests.ts index 735167b319..1db26cb668 100644 --- a/webapp/platform/types/src/requests.ts +++ b/webapp/platform/types/src/requests.ts @@ -12,7 +12,6 @@ export type ChannelsRequestsStatuses = { getAllChannels: RequestStatusType; myChannels: RequestStatusType; createChannel: RequestStatusType; - updateChannel: RequestStatusType; }; export type GeneralRequestsStatuses = { @@ -32,7 +31,6 @@ export type ThreadsRequestStatuses = { export type TeamsRequestsStatuses = { getMyTeams: RequestStatusType; getTeams: RequestStatusType; - joinTeam: RequestStatusType; }; export type UsersRequestsStatuses = { diff --git a/webapp/platform/types/src/search.ts b/webapp/platform/types/src/search.ts index cb18f4933a..551f490f27 100644 --- a/webapp/platform/types/src/search.ts +++ b/webapp/platform/types/src/search.ts @@ -15,9 +15,6 @@ export type SearchState = { isSearchingTerm: boolean; isSearchGettingMore: boolean; isLimitedResults: number; - recent: { - [x: string]: Search[]; - }; matches: { [x: string]: string[]; };