* Revert "[MM-52547] Include current user profile in every redux action (#23219)" This reverts commita85c0b87b8. * Revert "[MM-52546] webapp/channels : Update current user and status on WebSocket reconnect (#23071)" This reverts commit6d3354266a.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3f7efe2df8
Коммит
f7e87bfe29
@@ -234,7 +234,7 @@ export function reconnect() {
|
||||
// we can request for getPosts again when socket is connected
|
||||
dispatch(getPosts(currentChannelId));
|
||||
}
|
||||
dispatch(StatusActions.loadStatusesForChannelAndSidebar());
|
||||
StatusActions.loadStatusesForChannelAndSidebar();
|
||||
|
||||
const crtEnabled = isCollapsedThreadsEnabled(state);
|
||||
dispatch(TeamActions.getMyTeamUnreads(crtEnabled, true));
|
||||
|
||||
@@ -35,6 +35,7 @@ import {getServerVersion} from 'mattermost-redux/selectors/entities/general';
|
||||
import {getCurrentUserId, getUsers} from 'mattermost-redux/selectors/entities/users';
|
||||
import {isCollapsedThreadsEnabled} from 'mattermost-redux/selectors/entities/preferences';
|
||||
|
||||
import {removeUserFromList} from 'mattermost-redux/utils/user_utils';
|
||||
import {isMinimumServerVersion} from 'mattermost-redux/utils/helpers';
|
||||
import {General} from 'mattermost-redux/constants';
|
||||
|
||||
@@ -214,10 +215,12 @@ export function getFilteredUsersStats(options: GetFilteredUsersStatsOpts = {}, u
|
||||
|
||||
export function getProfiles(page = 0, perPage: number = General.PROFILE_CHUNK_SIZE, options: any = {}): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
let profiles: UserProfile[];
|
||||
|
||||
try {
|
||||
profiles = await Client4.getProfiles(page, perPage, options);
|
||||
removeUserFromList(currentUserId, profiles);
|
||||
} catch (error) {
|
||||
forceLogoutIfNecessary(error, dispatch, getState);
|
||||
dispatch(logError(error));
|
||||
@@ -277,10 +280,12 @@ export function getMissingProfilesByUsernames(usernames: string[]): ActionFunc {
|
||||
|
||||
export function getProfilesByIds(userIds: string[], options?: any): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
let profiles: UserProfile[];
|
||||
|
||||
try {
|
||||
profiles = await Client4.getProfilesByIds(userIds, options);
|
||||
removeUserFromList(currentUserId, profiles);
|
||||
} catch (error) {
|
||||
forceLogoutIfNecessary(error, dispatch, getState);
|
||||
dispatch(logError(error));
|
||||
@@ -298,10 +303,12 @@ export function getProfilesByIds(userIds: string[], options?: any): ActionFunc {
|
||||
|
||||
export function getProfilesByUsernames(usernames: string[]): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
let profiles;
|
||||
|
||||
try {
|
||||
profiles = await Client4.getProfilesByUsernames(usernames);
|
||||
removeUserFromList(currentUserId, profiles);
|
||||
} catch (error) {
|
||||
forceLogoutIfNecessary(error, dispatch, getState);
|
||||
dispatch(logError(error));
|
||||
@@ -319,6 +326,7 @@ export function getProfilesByUsernames(usernames: string[]): ActionFunc {
|
||||
|
||||
export function getProfilesInTeam(teamId: string, page: number, perPage: number = General.PROFILE_CHUNK_SIZE, sort = '', options: any = {}): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
let profiles;
|
||||
|
||||
try {
|
||||
@@ -337,7 +345,7 @@ export function getProfilesInTeam(teamId: string, page: number, perPage: number
|
||||
},
|
||||
{
|
||||
type: UserTypes.RECEIVED_PROFILES_LIST,
|
||||
data: profiles,
|
||||
data: removeUserFromList(currentUserId, [...profiles]),
|
||||
},
|
||||
]));
|
||||
|
||||
@@ -407,6 +415,7 @@ export enum ProfilesInChannelSortBy {
|
||||
|
||||
export function getProfilesInChannel(channelId: string, page: number, perPage: number = General.PROFILE_CHUNK_SIZE, sort = '', options: {active?: boolean} = {}): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
let profiles;
|
||||
|
||||
try {
|
||||
@@ -425,7 +434,7 @@ export function getProfilesInChannel(channelId: string, page: number, perPage: n
|
||||
},
|
||||
{
|
||||
type: UserTypes.RECEIVED_PROFILES_LIST,
|
||||
data: profiles,
|
||||
data: removeUserFromList(currentUserId, [...profiles]),
|
||||
},
|
||||
]));
|
||||
|
||||
@@ -435,6 +444,7 @@ export function getProfilesInChannel(channelId: string, page: number, perPage: n
|
||||
|
||||
export function getProfilesInGroupChannels(channelsIds: string[]): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
let channelProfiles;
|
||||
|
||||
try {
|
||||
@@ -458,7 +468,7 @@ export function getProfilesInGroupChannels(channelsIds: string[]): ActionFunc {
|
||||
},
|
||||
{
|
||||
type: UserTypes.RECEIVED_PROFILES_LIST,
|
||||
data: profiles,
|
||||
data: removeUserFromList(currentUserId, [...profiles]),
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -472,6 +482,7 @@ export function getProfilesInGroupChannels(channelsIds: string[]): ActionFunc {
|
||||
|
||||
export function getProfilesNotInChannel(teamId: string, channelId: string, groupConstrained: boolean, page: number, perPage: number = General.PROFILE_CHUNK_SIZE): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
let profiles;
|
||||
|
||||
try {
|
||||
@@ -492,7 +503,7 @@ export function getProfilesNotInChannel(teamId: string, channelId: string, group
|
||||
},
|
||||
{
|
||||
type: UserTypes.RECEIVED_PROFILES_LIST,
|
||||
data: profiles,
|
||||
data: removeUserFromList(currentUserId, [...profiles]),
|
||||
},
|
||||
]));
|
||||
|
||||
@@ -553,6 +564,7 @@ export function updateMyTermsOfServiceStatus(termsOfServiceId: string, accepted:
|
||||
|
||||
export function getProfilesInGroup(groupId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE, sort = ''): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
let profiles;
|
||||
|
||||
try {
|
||||
@@ -571,7 +583,7 @@ export function getProfilesInGroup(groupId: string, page = 0, perPage: number =
|
||||
},
|
||||
{
|
||||
type: UserTypes.RECEIVED_PROFILES_LIST,
|
||||
data: profiles,
|
||||
data: removeUserFromList(currentUserId, [...profiles]),
|
||||
},
|
||||
]));
|
||||
|
||||
@@ -581,6 +593,7 @@ export function getProfilesInGroup(groupId: string, page = 0, perPage: number =
|
||||
|
||||
export function getProfilesNotInGroup(groupId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
let profiles;
|
||||
|
||||
try {
|
||||
@@ -599,7 +612,7 @@ export function getProfilesNotInGroup(groupId: string, page = 0, perPage: number
|
||||
},
|
||||
{
|
||||
type: UserTypes.RECEIVED_PROFILES_LIST,
|
||||
data: profiles,
|
||||
data: removeUserFromList(currentUserId, [...profiles]),
|
||||
},
|
||||
]));
|
||||
|
||||
@@ -831,6 +844,9 @@ export function autocompleteUsers(term: string, teamId = '', channelId = '', opt
|
||||
}): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
dispatch({type: UserTypes.AUTOCOMPLETE_USERS_REQUEST, data: null});
|
||||
|
||||
const {currentUserId} = getState().entities.users;
|
||||
|
||||
let data;
|
||||
try {
|
||||
data = await Client4.autocompleteUsers(term, teamId, channelId, options);
|
||||
@@ -845,6 +861,7 @@ export function autocompleteUsers(term: string, teamId = '', channelId = '', opt
|
||||
if (data.out_of_channel) {
|
||||
users = [...users, ...data.out_of_channel];
|
||||
}
|
||||
removeUserFromList(currentUserId, users);
|
||||
const actions: AnyAction[] = [{
|
||||
type: UserTypes.RECEIVED_PROFILES_LIST,
|
||||
data: users,
|
||||
@@ -887,6 +904,8 @@ export function autocompleteUsers(term: string, teamId = '', channelId = '', opt
|
||||
|
||||
export function searchProfiles(term: string, options: any = {}): ActionFunc {
|
||||
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
|
||||
const {currentUserId} = getState().entities.users;
|
||||
|
||||
let profiles;
|
||||
try {
|
||||
profiles = await Client4.searchUsers(term, options);
|
||||
@@ -896,7 +915,7 @@ export function searchProfiles(term: string, options: any = {}): ActionFunc {
|
||||
return {error};
|
||||
}
|
||||
|
||||
const actions: AnyAction[] = [{type: UserTypes.RECEIVED_PROFILES_LIST, data: profiles}];
|
||||
const actions: AnyAction[] = [{type: UserTypes.RECEIVED_PROFILES_LIST, data: removeUserFromList(currentUserId, [...profiles])}];
|
||||
|
||||
if (options.in_channel_id) {
|
||||
actions.push({
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
import {UserTypes, ChannelTypes} from 'mattermost-redux/action_types';
|
||||
import {GenericAction} from 'mattermost-redux/types/actions';
|
||||
import reducer from 'mattermost-redux/reducers/entities/users';
|
||||
|
||||
import {TestHelper} from 'utils/test_helper';
|
||||
|
||||
type ReducerState = ReturnType<typeof reducer>;
|
||||
|
||||
describe('Reducers.users', () => {
|
||||
@@ -676,35 +673,4 @@ describe('Reducers.users', () => {
|
||||
expect(newState.profilesNotInGroup).toEqual(expectedState.profilesNotInGroup);
|
||||
});
|
||||
});
|
||||
describe('profiles', () => {
|
||||
it('UserTypes.RECEIVED_PROFILES_LIST, should merge existing users with new ones', () => {
|
||||
const firstUser = TestHelper.getUserMock({id: 'first_user_id'});
|
||||
const secondUser = TestHelper.getUserMock({id: 'seocnd_user_id'});
|
||||
const thirdUser = TestHelper.getUserMock({id: 'third_user_id'});
|
||||
const partialUpdatedFirstUser = {
|
||||
...firstUser,
|
||||
update_at: 123456789,
|
||||
};
|
||||
Reflect.deleteProperty(partialUpdatedFirstUser, 'email');
|
||||
Reflect.deleteProperty(partialUpdatedFirstUser, 'notify_props');
|
||||
const state = {
|
||||
profiles: {
|
||||
first_user_id: firstUser,
|
||||
second_user_id: secondUser,
|
||||
},
|
||||
};
|
||||
const action = {
|
||||
type: UserTypes.RECEIVED_PROFILES_LIST,
|
||||
data: [
|
||||
partialUpdatedFirstUser,
|
||||
thirdUser,
|
||||
],
|
||||
};
|
||||
const {profiles: newProfiles} = reducer(state as unknown as ReducerState, action);
|
||||
|
||||
expect(newProfiles.first_user_id).toEqual({...firstUser, ...partialUpdatedFirstUser});
|
||||
expect(newProfiles.second_user_id).toEqual(secondUser);
|
||||
expect(newProfiles.third_user_id).toEqual(thirdUser);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -198,18 +198,15 @@ function profiles(state: IDMappedObjects<UserProfile> = {}, action: GenericActio
|
||||
const users: UserProfile[] = action.data;
|
||||
|
||||
return users.reduce((nextState, user) => {
|
||||
const oldUser = nextState[user.id] || {};
|
||||
const oldUser = nextState[user.id];
|
||||
|
||||
if (isEqual(user, oldUser)) {
|
||||
if (oldUser && isEqual(user, oldUser)) {
|
||||
return nextState;
|
||||
}
|
||||
|
||||
return {
|
||||
...nextState,
|
||||
[user.id]: {
|
||||
...oldUser,
|
||||
...user,
|
||||
},
|
||||
[user.id]: user,
|
||||
};
|
||||
}, state);
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user