mattermost-mobile/app/selectors/channel.js
Amit Uttam 36c7cf4014 MM-21723 Handle deep link errors to inaccessible teams, channels & permalinks (#3815)
* Consolidated error handling for a user's reachable teams.
* Consolidated error handling for a user's reachable channels.
2020-01-21 14:43:24 -03:00

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 'mattermost-redux/selectors/entities/users';
import {getChannelByName} from 'mattermost-redux/selectors/entities/channels';
import {getTeamByName} from 'mattermost-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,
);