Fix cannot search user when pressing space (#7486) (#7498)

* - Update AT_METION_SEARCH_REGEX to allow to search user name with space, similar to mentioning user.
- Convert search term to lowercase.

* Update CHANNEL_MENTION_SEARCH_REGEX to allow to search channel name when typing space

* Fix app crash when searching in channel only

---------

Co-authored-by: Huỳnh Phương Khanh <phuongkhanh@evolgroup.vn>
(cherry picked from commit 191f498ab0)

Co-authored-by: Khanh P. Huynh <hpkhanh1610@gmail.com>
This commit is contained in:
Mattermost Build 2023-08-14 10:55:00 +03:00 committed by GitHub
parent 5e05956daa
commit 1f61dddff1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 4 deletions

View file

@ -42,7 +42,7 @@ const getMatchTermForAtMention = (() => {
return (value: string, isSearch: boolean) => {
if (value !== lastValue || isSearch !== lastIsSearch) {
const regex = isSearch ? AT_MENTION_SEARCH_REGEX : AT_MENTION_REGEX;
let term = value;
let term = value.toLowerCase();
if (term.startsWith('from: @') || term.startsWith('from:@')) {
term = term.replace('@', '');
}

View file

@ -5,13 +5,13 @@ export const AT_MENTION_REGEX = /\B(@([^@\r\n]*))$/i;
export const AT_MENTION_REGEX_GLOBAL = /\B(@([^@\r\n]*))/gi;
export const AT_MENTION_SEARCH_REGEX = /\bfrom:\s*(\S*)$/i;
export const AT_MENTION_SEARCH_REGEX = /\bfrom:\s*([^\r\n]*)$/i;
export const CHANNEL_MENTION_REGEX = /\B(~([^~\r\n]*))$/i;
export const CHANNEL_MENTION_REGEX_DELAYED = /\B(~([^~\r\n]{2,}))$/i;
export const CHANNEL_MENTION_SEARCH_REGEX = /\b(?:in|channel):\s*(\S*)$/i;
export const CHANNEL_MENTION_SEARCH_REGEX = /\b(?:in|channel):\s*([^\r\n]*)$/i;
export const DATE_MENTION_SEARCH_REGEX = /\b(?:on|before|after):\s*(\S*)$/i;

View file

@ -69,7 +69,7 @@ const PostResults = ({
const hasPhrases = (/"([^"]*)"/).test(searchValue || '');
let searchPatterns: SearchPattern[] | undefined;
if (matches && !hasPhrases) {
searchPatterns = matches?.[key].map(convertSearchTermToRegex);
searchPatterns = matches?.[key]?.map(convertSearchTermToRegex);
} else {
searchPatterns = parseSearchTerms(searchValue)?.map(convertSearchTermToRegex).sort((a, b) => {
return b.term.length - a.term.length;