[MM-54138] Remove code involving getRedirectLocation and state.entities.posts.expandedURLs (#24739)

This commit is contained in:
M-ZubairAhmed
2023-10-16 16:09:59 +05:30
committed by GitHub
parent d98dc31425
commit d557bd864f
10 changed files with 1 additions and 197 deletions

View File

@@ -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,

View File

@@ -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',

View File

@@ -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<any>;
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,
};

View File

@@ -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);
});
});

View File

@@ -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<MessageHistory> = {
}
}
export function expandedURLs(state: Record<string, string> = {}, 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<PostsState> = {}, 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<PostsState> = {}, 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;

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -61,7 +61,6 @@ const state: GlobalState = {
channelsMemberCount: {},
},
posts: {
expandedURLs: {},
posts: {},
postsReplies: {},
postsInChannel: {},

View File

@@ -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) => {

View File

@@ -148,7 +148,6 @@ export type PostsState = {
postEditHistory: Post[];
currentFocusedPostId: string;
messagesHistory: MessageHistory;
expandedURLs: Record<string, string>;
limitedViews: {
channels: Record<Channel['id'], number>;
threads: Record<Post['root_id'], number>;