Skip to content

Commit

Permalink
Fix cannot search user when pressing space (#7486) (#7498)
Browse files Browse the repository at this point in the history
* - 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 <[email protected]>
(cherry picked from commit 191f498)

Co-authored-by: Khanh P. Huynh <[email protected]>
  • Loading branch information
mattermost-build and hpkhanh1610 authored Aug 14, 2023
1 parent 5e05956 commit 1f61ddd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/components/autocomplete/at_mention/at_mention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('@', '');
}
Expand Down
4 changes: 2 additions & 2 deletions app/constants/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion app/screens/home/search/results/post_results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1f61ddd

Please sign in to comment.