mattermost-mobile/app/components/autocomplete/at_mention/index.js
Hossein Ahmadian-Yazdi b6eb3b9349
[MM-23158] Group Mentions & Invites - Display group mentions in suggestions list in the main channel textbox (#4118)
* groups in group mention

* fix sorting issues

* address PR comments

* fix tests

* Update groups.ts

* fix nock

* fix translations

* Adding test

* fix linting

* update redux functions

* Add license check

* adddress PR comments

* remove lodash import

* fix lint problems

* revert package.json changes

* Address PR comments

* address PR comments

* fix naming

* address PR comments

* address PR comments

* Address comments found in second PR

* getAllGroups updated

* address PR comments

* Update app/mm-redux/utils/group_utils.ts

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* revert change

* remove unneeded actions

* Use correct server version

* MM-26631: Fix order of group displaying

* MM-26633: Fix group mentions not showing up in group constrained team

* MM-26636: Group mentions not updating when role updates

* MM-26637: Group name not updating right away

* Address PR comments

* TRY AND catch

* address PR comments

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-07-08 07:31:58 -04:00

92 lines
3.2 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {isMinimumServerVersion} from '@mm-redux/utils/helpers';
import {autocompleteUsers} from '@mm-redux/actions/users';
import {getLicense} from '@mm-redux/selectors/entities/general';
import {getCurrentChannelId, getDefaultChannel} from '@mm-redux/selectors/entities/channels';
import {getAssociatedGroupsForReference, searchAssociatedGroupsForReferenceLocal} from '@mm-redux/selectors/entities/groups';
import {getCurrentTeamId} from '@mm-redux/selectors/entities/teams';
import {isLandscape} from 'app/selectors/device';
import {
filterMembersInChannel,
filterMembersNotInChannel,
filterMembersInCurrentTeam,
getMatchTermForAtMention,
} from 'app/selectors/autocomplete';
import {getTheme} from '@mm-redux/selectors/entities/preferences';
import {haveIChannelPermission} from '@mm-redux/selectors/entities/roles';
import {Permissions} from '@mm-redux/constants';
import AtMention from './at_mention';
function mapStateToProps(state, ownProps) {
const {cursorPosition, isSearch} = ownProps;
const currentChannelId = getCurrentChannelId(state);
const currentTeamId = getCurrentTeamId(state);
const license = getLicense(state);
const hasLicense = license?.IsLicensed === 'true' && license?.LDAPGroups === 'true';
let useChannelMentions = true;
if (isMinimumServerVersion(state.entities.general.serverVersion, 5, 22)) {
useChannelMentions = haveIChannelPermission(
state,
{
channel: currentChannelId,
permission: Permissions.USE_CHANNEL_MENTIONS,
default: true,
},
);
}
const value = ownProps.value.substring(0, cursorPosition);
const matchTerm = getMatchTermForAtMention(value, isSearch);
let teamMembers;
let inChannel;
let outChannel;
let groups = [];
if (isSearch) {
teamMembers = filterMembersInCurrentTeam(state, matchTerm);
} else {
inChannel = filterMembersInChannel(state, matchTerm);
outChannel = filterMembersNotInChannel(state, matchTerm);
}
if (hasLicense && isMinimumServerVersion(state.entities.general.serverVersion, 5, 24)) {
if (matchTerm) {
groups = searchAssociatedGroupsForReferenceLocal(state, matchTerm, currentTeamId, currentChannelId);
} else {
groups = getAssociatedGroupsForReference(state, currentTeamId, currentChannelId);
}
}
return {
currentChannelId,
currentTeamId,
defaultChannel: getDefaultChannel(state),
matchTerm,
teamMembers,
inChannel,
outChannel,
requestStatus: state.requests.users.autocompleteUsers.status,
theme: getTheme(state),
isLandscape: isLandscape(state),
useChannelMentions,
groups,
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
autocompleteUsers,
}, dispatch),
};
}
export default connect(mapStateToProps, mapDispatchToProps)(AtMention);