[MM-63582] Recent Mentions Not Properly Handling Hyphenated Custom Keywords (#30578)
* quote all terms for better recent mentions accuracy --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
1
webapp/.gitignore
поставляемый
1
webapp/.gitignore
поставляемый
@@ -12,3 +12,4 @@ platform/*/dist
|
|||||||
platform/*/lib
|
platform/*/lib
|
||||||
|
|
||||||
config.override.mk
|
config.override.mk
|
||||||
|
build
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import type {IDMappedObjects} from '@mattermost/types/utilities';
|
|||||||
|
|
||||||
import {SearchTypes} from 'mattermost-redux/action_types';
|
import {SearchTypes} from 'mattermost-redux/action_types';
|
||||||
import * as SearchActions from 'mattermost-redux/actions/search';
|
import * as SearchActions from 'mattermost-redux/actions/search';
|
||||||
|
import {getCurrentTimezone} from 'mattermost-redux/selectors/entities/timezone';
|
||||||
|
|
||||||
import {trackEvent} from 'actions/telemetry_actions.jsx';
|
import {trackEvent} from 'actions/telemetry_actions.jsx';
|
||||||
import {
|
import {
|
||||||
@@ -45,7 +46,7 @@ import {
|
|||||||
import mockStore from 'tests/test_store';
|
import mockStore from 'tests/test_store';
|
||||||
import {ActionTypes, RHSStates, Constants} from 'utils/constants';
|
import {ActionTypes, RHSStates, Constants} from 'utils/constants';
|
||||||
import {TestHelper} from 'utils/test_helper';
|
import {TestHelper} from 'utils/test_helper';
|
||||||
import {getBrowserUtcOffset} from 'utils/timezone';
|
import {getUtcOffsetForTimeZone} from 'utils/timezone';
|
||||||
|
|
||||||
import type {GlobalState} from 'types/store';
|
import type {GlobalState} from 'types/store';
|
||||||
import type {RhsState} from 'types/store/rhs';
|
import type {RhsState} from 'types/store/rhs';
|
||||||
@@ -109,7 +110,7 @@ describe('rhs view actions', () => {
|
|||||||
first_name: currentUserFirstName,
|
first_name: currentUserFirstName,
|
||||||
timezone: {
|
timezone: {
|
||||||
useAutomaticTimezone: true,
|
useAutomaticTimezone: true,
|
||||||
automaticTimezone: '',
|
automaticTimezone: 'UTC+3', // set an arbitrary timezone
|
||||||
manualTimezone: '',
|
manualTimezone: '',
|
||||||
},
|
},
|
||||||
} as UserProfile,
|
} as UserProfile,
|
||||||
@@ -221,7 +222,7 @@ describe('rhs view actions', () => {
|
|||||||
|
|
||||||
describe('performSearch', () => {
|
describe('performSearch', () => {
|
||||||
// timezone offset in seconds
|
// timezone offset in seconds
|
||||||
let timeZoneOffset = getBrowserUtcOffset() * 60;
|
let timeZoneOffset = getUtcOffsetForTimeZone(getCurrentTimezone(initialState)) * 60;
|
||||||
|
|
||||||
// Avoid problems with negative cero
|
// Avoid problems with negative cero
|
||||||
if (timeZoneOffset === 0) {
|
if (timeZoneOffset === 0) {
|
||||||
@@ -263,10 +264,10 @@ describe('rhs view actions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('it dispatches searchPosts correctly for Recent Mentions', () => {
|
test('it dispatches searchPosts correctly for Recent Mentions', () => {
|
||||||
const terms = `@here test search ${currentUsername} @${currentUsername} ${currentUserFirstName}`;
|
const terms = `@here test search ${currentUsername} @${currentUsername} ${currentUserFirstName} custom-hyphenated-term`;
|
||||||
store.dispatch(performSearch(terms, '', true));
|
store.dispatch(performSearch(terms, '', true));
|
||||||
|
|
||||||
const mentionsQuotedTerms = `@here test search "${currentUsername}" "@${currentUsername}" "${currentUserFirstName}"`;
|
const mentionsQuotedTerms = `"@here" "test" "search" "${currentUsername}" "@${currentUsername}" "${currentUserFirstName}" "custom-hyphenated-term"`;
|
||||||
const compareStore = mockStore(initialState);
|
const compareStore = mockStore(initialState);
|
||||||
compareStore.dispatch(SearchActions.searchPostsWithParams('', {include_deleted_channels: false, terms: mentionsQuotedTerms, is_or_search: true, time_zone_offset: timeZoneOffset, page: 0, per_page: 20}));
|
compareStore.dispatch(SearchActions.searchPostsWithParams('', {include_deleted_channels: false, terms: mentionsQuotedTerms, is_or_search: true, time_zone_offset: timeZoneOffset, page: 0, per_page: 20}));
|
||||||
compareStore.dispatch(SearchActions.searchFilesWithParams('', {include_deleted_channels: false, terms, is_or_search: true, time_zone_offset: timeZoneOffset, page: 0, per_page: 20}));
|
compareStore.dispatch(SearchActions.searchFilesWithParams('', {include_deleted_channels: false, terms, is_or_search: true, time_zone_offset: timeZoneOffset, page: 0, per_page: 20}));
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {getConfig} from 'mattermost-redux/selectors/entities/general';
|
|||||||
import {getLatestInteractablePostId, getPost} from 'mattermost-redux/selectors/entities/posts';
|
import {getLatestInteractablePostId, getPost} from 'mattermost-redux/selectors/entities/posts';
|
||||||
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
|
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
|
||||||
import {getCurrentTimezone} from 'mattermost-redux/selectors/entities/timezone';
|
import {getCurrentTimezone} from 'mattermost-redux/selectors/entities/timezone';
|
||||||
import {getCurrentUser, getCurrentUserMentionKeys} from 'mattermost-redux/selectors/entities/users';
|
import {getCurrentUserMentionKeys} from 'mattermost-redux/selectors/entities/users';
|
||||||
|
|
||||||
import {trackEvent} from 'actions/telemetry_actions.jsx';
|
import {trackEvent} from 'actions/telemetry_actions.jsx';
|
||||||
import {
|
import {
|
||||||
@@ -222,19 +222,11 @@ export function performSearch(terms: string, teamId: string, isMentionSearch?: b
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isMentionSearch) {
|
if (isMentionSearch) {
|
||||||
// Username and FirstName should be quoted to allow specific search
|
// For mentions, perform a specific search by quoting all terms.
|
||||||
// in case the name is made with multiple words splitted by dashes or other symbols.
|
// This ensures terms split by dashes or other symbols are treated as a single unit.
|
||||||
const user = getCurrentUser(getState());
|
|
||||||
const termsArr = searchTerms.split(' ').filter((t) => Boolean(t && t.trim()));
|
const termsArr = searchTerms.split(' ').filter((t) => Boolean(t && t.trim()));
|
||||||
const atUsername = '@' + user.username;
|
|
||||||
for (let i = 0; i < termsArr.length; i++) {
|
for (let i = 0; i < termsArr.length; i++) {
|
||||||
if (termsArr[i] === atUsername) {
|
termsArr[i] = `"${termsArr[i]}"`;
|
||||||
termsArr[i] = `"${atUsername}"`;
|
|
||||||
} else if (termsArr[i] === user.username) {
|
|
||||||
termsArr[i] = `"${user.username}"`;
|
|
||||||
} else if (termsArr[i] === user.first_name) {
|
|
||||||
termsArr[i] = `"${user.first_name}"`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
searchTerms = termsArr.join(' ');
|
searchTerms = termsArr.join(' ');
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user