mattermost-mobile/app/selectors/channel.js
Jesús Espino 9bd89930b7
MM-11567: Autocomplete search in: for DMs and GMs (#2133)
* MM-11567: Autocomplete search in: for DMs and GMs

* More robust behavior on older versions and a fix on autocompletion

* Moving get display_name for search to a selector
2018-09-27 18:38:07 +02:00

39 lines
1 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';
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 '';
}
);