* Remove mattermost-redux * Move mm-redux files into app/redux * Add @redux path to tsconfig.json * Fix imports * Install missing dependencies * Fix tsc errors * Fix i18n_utils test * Fix more imports * Remove redux websocket * Fix tests * Rename @redux * Apply changes from mattermost-redux PR 1103 * Remove mattermost-redux mention in template * Add missing imports * Rename app/redux/ to app/mm-redux/ * Remove test file * Fix fetching Sidebar GM profiles Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {createSelector} from 'reselect';
|
|
|
|
import {getCurrentUserId, getUser} from '@mm-redux/selectors/entities/users';
|
|
import {getChannelByName} from '@mm-redux/selectors/entities/channels';
|
|
import {getTeamByName} from '@mm-redux/selectors/entities/teams';
|
|
|
|
const getOtherUserIdForDm = createSelector(
|
|
(state, channel) => channel,
|
|
getCurrentUserId,
|
|
(channel, currentUserId) => {
|
|
if (!channel) {
|
|
return '';
|
|
}
|
|
|
|
return channel.name.split('__').find((m) => m !== currentUserId) || currentUserId;
|
|
},
|
|
);
|
|
|
|
export const getChannelMembersForDm = createSelector(
|
|
(state, channel) => getUser(state, getOtherUserIdForDm(state, channel)),
|
|
(otherUser) => {
|
|
if (!otherUser) {
|
|
return [];
|
|
}
|
|
|
|
return [otherUser];
|
|
},
|
|
);
|
|
|
|
export const getChannelNameForSearchAutocomplete = createSelector(
|
|
(state, channelId) => state.entities.channels.channels[channelId],
|
|
(channel) => {
|
|
if (channel && channel.display_name) {
|
|
return channel.display_name;
|
|
}
|
|
return '';
|
|
},
|
|
);
|
|
|
|
const getTeam = (state, channelName, teamName) => getTeamByName(state, teamName);
|
|
const getChannel = (state, channelName) => getChannelByName(state, channelName);
|
|
|
|
export const getChannelReachable = createSelector(
|
|
getTeam,
|
|
getChannel,
|
|
(team, channel) => team && channel,
|
|
);
|