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 50fb6b29f5..2def5ef180 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 @@ -24,8 +24,6 @@ export default keyMirror({ WEBSOCKET_CLOSED: null, SET_CONNECTION_ID: null, - REDIRECT_LOCATION_SUCCESS: null, - REDIRECT_LOCATION_FAILURE: null, SET_CONFIG_AND_LICENSE: null, WARN_METRICS_STATUS_RECEIVED: null, 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 c46e21ff32..72a9ed0d79 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 @@ -3,7 +3,6 @@ import nock from 'nock'; -import {GeneralTypes} from 'mattermost-redux/action_types'; import * as Actions from 'mattermost-redux/actions/general'; import {Client4} from 'mattermost-redux/client'; @@ -101,44 +100,6 @@ describe('Actions.General', () => { expect(warnMetricsStatus.metric2).toEqual(false); }); - describe('getRedirectLocation', () => { - it('old server', async () => { - store.dispatch({type: GeneralTypes.RECEIVED_SERVER_VERSION, data: '5.0.0'}); - - const mock = nock(Client4.getBaseRoute()). - get('/redirect_location'). - reply(404); - - // Should return the original link - const result = await store.dispatch(Actions.getRedirectLocation('http://examp.le')); - expect(result.data).toEqual({location: 'http://examp.le'}); - - // Should not call the API on an old server - expect(mock.isDone()).toEqual(false); - }); - - it('should save the correct location', async () => { - store.dispatch({type: GeneralTypes.RECEIVED_SERVER_VERSION, data: '5.3.0'}); - - nock(Client4.getBaseRoute()). - get('/redirect_location'). - query({url: 'http://examp.le'}). - reply(200, '{"location": "https://example.com"}'); - - // Save the found URL if it finds one - await store.dispatch(Actions.getRedirectLocation('http://examp.le')); - - const existingURL = store.getState().entities.posts.expandedURLs['http://examp.le']; - expect(existingURL).toEqual('https://example.com'); - - // Save the found URL if it finds one - await store.dispatch(Actions.getRedirectLocation('http://nonexisting.url')); - - const nonexistingURL = store.getState().entities.posts.expandedURLs['http://nonexisting.url']; - expect(nonexistingURL).toEqual('http://nonexisting.url'); - }); - }); - it('getFirstAdminVisitMarketplaceStatus', async () => { const responseData = { name: 'FirstAdminVisitMarketplace', 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 604c1fe499..c4f9e63770 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts @@ -7,9 +7,7 @@ import {LogLevel} from '@mattermost/types/client4'; import {GeneralTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; -import {getServerVersion} from 'mattermost-redux/selectors/entities/general'; import type {GetStateFunc, DispatchFunc, ActionFunc} from 'mattermost-redux/types/actions'; -import {isMinimumServerVersion} from 'mattermost-redux/utils/helpers'; import {logError} from './errors'; import {bindClientFunc, forceLogoutIfNecessary} from './helpers'; @@ -91,29 +89,6 @@ export function setUrl(url: string) { return true; } -export function getRedirectLocation(url: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { - let pendingData: Promise; - if (isMinimumServerVersion(getServerVersion(getState()), 5, 3)) { - pendingData = Client4.getRedirectLocation(url); - } else { - pendingData = Promise.resolve({location: url}); - } - - let data; - try { - data = await pendingData; - } catch (error) { - forceLogoutIfNecessary(error, dispatch, getState); - dispatch({type: GeneralTypes.REDIRECT_LOCATION_FAILURE, data: {error, url}}); - return {error}; - } - - dispatch({type: GeneralTypes.REDIRECT_LOCATION_SUCCESS, data: {...data, url}}); - return {data}; - }; -} - export function getWarnMetricsStatus(): ActionFunc { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { let data; @@ -182,7 +157,6 @@ export default { logClientError, setServerVersion, setUrl, - getRedirectLocation, getWarnMetricsStatus, getFirstAdminVisitMarketplaceStatus, }; diff --git a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.test.ts b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.test.ts index 63e5ceeb9a..f05c831f1f 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/reducers/entities/posts.test.ts @@ -7,7 +7,6 @@ import type {Post, PostOrderBlock} from '@mattermost/types/posts'; import { ChannelTypes, - GeneralTypes, PostTypes, ThreadTypes, CloudTypes, @@ -4091,41 +4090,6 @@ describe('opengraph', () => { }); }); -describe('expandedURLs', () => { - it('should store the URLs on REDIRECT_LOCATION_SUCCESS', () => { - const state = deepFreeze({}); - const action = { - type: GeneralTypes.REDIRECT_LOCATION_SUCCESS, - data: { - url: 'a', - location: 'b', - }, - }; - - const nextState = reducers.expandedURLs(state, action); - expect(state).not.toEqual(nextState); - expect(nextState).toEqual({ - a: 'b', - }); - }); - - it('should store the non-expanded URL on REDIRECT_LOCATION_FAILURE', () => { - const state = deepFreeze({}); - const action = { - type: GeneralTypes.REDIRECT_LOCATION_FAILURE, - data: { - url: 'b', - }, - }; - - const nextState = reducers.expandedURLs(state, action); - expect(state).not.toEqual(nextState); - expect(nextState).toEqual({ - b: 'b', - }); - }); -}); - describe('removeNonRecentEmptyPostBlocks', () => { it('should filter empty blocks', () => { const blocks = [{ @@ -4433,23 +4397,4 @@ describe('limitedViews', () => { expect(nextState).toEqual(zeroState); }); }); - - it('makes no changes if events type is not listened to', () => { - const initialState = { - channels: { - channelId: 123, - }, - threads: { - rootId: 124, - }, - }; - const nextState = reducers.limitedViews(initialState, { - type: GeneralTypes.REDIRECT_LOCATION_FAILURE, - data: { - url: 'http://failed-location-failure.com', - }, - }); - - expect(nextState).toEqual(initialState); - }); }); 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 3cb18eff2f..9eac63b819 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 @@ -19,7 +19,7 @@ import type { RelationOneToMany, } from '@mattermost/types/utilities'; -import {ChannelTypes, GeneralTypes, PostTypes, UserTypes, ThreadTypes, CloudTypes} from 'mattermost-redux/action_types'; +import {ChannelTypes, PostTypes, UserTypes, ThreadTypes, CloudTypes} from 'mattermost-redux/action_types'; import {Posts} from 'mattermost-redux/constants'; import {PostTypes as PostConstant} from 'mattermost-redux/constants/posts'; import type {GenericAction} from 'mattermost-redux/types/actions'; @@ -1492,23 +1492,6 @@ function messagesHistory(state: Partial = { } } -export function expandedURLs(state: Record = {}, action: GenericAction) { - switch (action.type) { - case GeneralTypes.REDIRECT_LOCATION_SUCCESS: - return { - ...state, - [action.data.url]: action.data.location, - }; - case GeneralTypes.REDIRECT_LOCATION_FAILURE: - return { - ...state, - [action.data.url]: action.data.url, - }; - default: - return state; - } -} - export const zeroStateLimitedViews = { threads: {}, channels: {}, @@ -1621,9 +1604,6 @@ export default function reducer(state: Partial = {}, action: Generic // History of posts and comments messagesHistory: messagesHistory(state.messagesHistory, action), - - expandedURLs: expandedURLs(state.expandedURLs, action), - acknowledgements: acknowledgements(state.acknowledgements, action), // For cloud instances with a message limit, @@ -1642,7 +1622,6 @@ export default function reducer(state: Partial = {}, action: Generic state.acknowledgements === nextState.acknowledgements && state.openGraph === nextState.openGraph && state.messagesHistory === nextState.messagesHistory && - state.expandedURLs === nextState.expandedURLs && state.limitedViews === nextState.limitedViews) { // None of the children have changed so don't even let the parent object change return state; diff --git a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/posts.test.ts b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/posts.test.ts index c5c641cdd0..543dc8837b 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/posts.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/posts.test.ts @@ -2443,38 +2443,6 @@ describe('getCurrentUsersLatestPost', () => { }); }); -describe('getExpandedLink', () => { - it('should get the expanded link from the state', () => { - const state = { - entities: { - posts: { - expandedURLs: { - a: 'b', - c: 'd', - }, - }, - }, - } as unknown as GlobalState; - expect(Selectors.getExpandedLink(state, 'a')).toEqual('b'); - expect(Selectors.getExpandedLink(state, 'c')).toEqual('d'); - }); - - it('should return undefined if it is not saved', () => { - const state = { - entities: { - posts: { - expandedURLs: { - a: 'b', - c: 'd', - }, - }, - }, - } as unknown as GlobalState; - expect(Selectors.getExpandedLink(state, 'b')).toEqual(undefined); - expect(Selectors.getExpandedLink(state, '')).toEqual(undefined); - }); -}); - describe('makeGetProfilesForThread', () => { it('should return profiles for threads in the right order and exclude current user', () => { const getProfilesForThread = Selectors.makeGetProfilesForThread(); diff --git a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/posts.ts b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/posts.ts index 35574e8e7a..35d3c99ee6 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/posts.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/selectors/entities/posts.ts @@ -751,10 +751,6 @@ export const makeIsPostCommentMention = (): ((state: GlobalState, postId: Post[' ); }; -export function getExpandedLink(state: GlobalState, link: string): string { - return state.entities.posts.expandedURLs[link]; -} - export function getLimitedViews(state: GlobalState): GlobalState['entities']['posts']['limitedViews'] { return state.entities.posts.limitedViews; } 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 9a335e1078..7fb299611a 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 @@ -61,7 +61,6 @@ const state: GlobalState = { channelsMemberCount: {}, }, posts: { - expandedURLs: {}, posts: {}, postsReplies: {}, postsInChannel: {}, diff --git a/webapp/platform/client/src/client4.ts b/webapp/platform/client/src/client4.ts index b4c0e8ea40..102e743978 100644 --- a/webapp/platform/client/src/client4.ts +++ b/webapp/platform/client/src/client4.ts @@ -420,10 +420,6 @@ export default class Client4 { return `${this.getBaseRoute()}/schemes`; } - getRedirectLocationRoute() { - return `${this.getBaseRoute()}/redirect_location`; - } - getBotsRoute() { return `${this.getBaseRoute()}/bots`; } @@ -3683,17 +3679,6 @@ export default class Client4 { ); } - // Redirect Location - getRedirectLocation = (urlParam: string) => { - if (!urlParam.length) { - return Promise.resolve(); - } - const url = `${this.getRedirectLocationRoute()}${buildQueryString({url: urlParam})}`; - return this.doFetch<{ - location: string; - }>(url, {method: 'get'}); - }; - // Bot Routes createBot = (bot: Bot) => { diff --git a/webapp/platform/types/src/posts.ts b/webapp/platform/types/src/posts.ts index afd6383034..eda29f4cc9 100644 --- a/webapp/platform/types/src/posts.ts +++ b/webapp/platform/types/src/posts.ts @@ -148,7 +148,6 @@ export type PostsState = { postEditHistory: Post[]; currentFocusedPostId: string; messagesHistory: MessageHistory; - expandedURLs: Record; limitedViews: { channels: Record; threads: Record;