mattermost-mobile/app/mm-redux/utils/group_utils.ts
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

35 lines
1.1 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {General} from '../constants';
import {Group} from '@mm-redux/types/groups';
import {getSuggestionsSplitByMultiple} from './user_utils';
export function filterGroupsMatchingTerm(groups: Array<Group>, term: string): Array<Group> {
const lowercasedTerm = term.toLowerCase();
let trimmedTerm = lowercasedTerm;
if (trimmedTerm.startsWith('@')) {
trimmedTerm = trimmedTerm.substr(1);
}
if (!trimmedTerm) {
return groups;
}
return groups.filter((group: Group) => {
if (!group) {
return false;
}
const groupSuggestions: string[] = [];
const groupnameSuggestions = getSuggestionsSplitByMultiple((group.name || '').toLowerCase(), General.AUTOCOMPLETE_SPLIT_CHARACTERS);
groupSuggestions.push(...groupnameSuggestions);
const displayname = (group.display_name || '').toLowerCase();
groupSuggestions.push(displayname);
return groupSuggestions.
some((suggestion) => suggestion.startsWith(trimmedTerm));
});
}