mattermost-mobile/app/selectors/channel.js
Anurag Shivarathri 6e23fbe7a7
MM-32921 shared channels (#5241)
* Unable to open previews from search, pinned and mentions

* Updated Compass Icons

* Added Icon to LHS and Channel Info

* Added Icons to Manage/View Members list

* Added Icon to shared users in posts

* Added icon to channel header, fixed header style

* Added Icons in autocomplete

* WIP: Add shared shannels to browse

* Adding Shared Channels string to i18n

* Added remote organization to remote user profile

* Updated snapshot for channel header

* Added browsing shared channels

* Removed the exmpty line

* Added snapshot when user is remote

* Reverted compass icons and added icons only needed for shared channels

* Fixed i18n swapped

* Copied compass-icons from webapp

* Fixed showing shared channels as deleted after browsing them

* Added new compass ttf to android & fixed icon style for browse channel listing

* Fixed search for shared channels

* user profile snapshot updated with testId

* User list row snapshot updated with testID

* Moved shared user check to util function

* Fixed required props warning for ChannelIcon component

* Update app/screens/user_profile/index.js

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>

* Removed Request related redux

* Reverted client4

* Added rest calls

* Updated snapshot

* Reverted files

* Adding back shared channels stuff to channel icon & showing shared channels only when enabled in browse channels

* Fixed misc issues

* moved empty array outside the function to avoid re-render

* Removed renaming fields

Co-authored-by: Miguel Alatzar <migbot@users.noreply.github.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-05-24 16:07:47 +05:30

90 lines
2.7 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {createSelector} from 'reselect';
import {General} from '@mm-redux/constants';
import {getCurrentUserId, getUser} from '@mm-redux/selectors/entities/users';
import {getChannelByName, getChannelsInCurrentTeam, getMyChannelMemberships} from '@mm-redux/selectors/entities/channels';
import {getTeamByName} from '@mm-redux/selectors/entities/teams';
import {getConfig} from '@mm-redux/selectors/entities/general';
import {isArchivedChannel} from '@mm-redux/utils/channel_utils';
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,
getConfig,
(team, channel, config) => {
if (!(team && channel)) {
return false;
}
const viewArchivedChannels = config.ExperimentalViewArchivedChannels === 'true';
if (isArchivedChannel(channel) && !viewArchivedChannels) {
return false;
}
return true;
},
);
export const joinablePublicChannels = createSelector(
getChannelsInCurrentTeam,
getMyChannelMemberships,
(channels, myMembers) => {
return channels.filter((c) => {
return (!myMembers[c.id] && c.type === General.OPEN_CHANNEL && c.delete_at === 0);
});
},
);
export const joinableSharedChannels = createSelector(
getChannelsInCurrentTeam,
getMyChannelMemberships,
(channels, myMembers) => {
return channels.filter((c) => {
return (!myMembers[c.id] && c.type === General.OPEN_CHANNEL && c.shared === true && c.delete_at === 0);
});
},
);
export const teamArchivedChannels = createSelector(
getChannelsInCurrentTeam,
(channels) => {
return channels.filter((c) => c.delete_at !== 0);
},
);