[MM-54357] Recent Mentions is showing posts for other similar named users. (#25010)

* Handle double quotes in Postgres
* quote the username when performing the search
Этот коммит содержится в:
Vishal
2023-11-02 11:05:44 +05:30
коммит произвёл GitHub
родитель e0dd8e3d3e
Коммит dfb561a641
3 изменённых файлов: 146 добавлений и 32 удалений

Просмотреть файл

@@ -23,7 +23,7 @@ import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getPost} from 'mattermost-redux/selectors/entities/posts';
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {getCurrentTimezone} from 'mattermost-redux/selectors/entities/timezone';
import {getCurrentUserMentionKeys} from 'mattermost-redux/selectors/entities/users';
import {getCurrentUser, getCurrentUserMentionKeys} from 'mattermost-redux/selectors/entities/users';
import type {Action, ActionResult, DispatchFunc, GenericAction, GetStateFunc} from 'mattermost-redux/types/actions';
import {trackEvent} from 'actions/telemetry_actions.jsx';
@@ -193,21 +193,38 @@ function updateSearchResultsTerms(terms: string) {
export function performSearch(terms: string, isMentionSearch?: boolean) {
return (dispatch: DispatchFunc, getState: GetStateFunc) => {
let searchTerms = terms;
const teamId = getCurrentTeamId(getState());
const config = getConfig(getState());
const viewArchivedChannels = config.ExperimentalViewArchivedChannels === 'true';
const extensionsFilters = getFilesSearchExtFilter(getState() as GlobalState);
const extensions = extensionsFilters?.map((ext) => `ext:${ext}`).join(' ');
let termsWithExtensionsFilters = terms;
let termsWithExtensionsFilters = searchTerms;
if (extensions?.trim().length > 0) {
termsWithExtensionsFilters += ` ${extensions}`;
}
if (isMentionSearch) {
// Username should be quoted to allow specific search
// in case username is made with multiple words splitted by dashes or other symbols.
const user = getCurrentUser(getState());
const termsArr = searchTerms.split(' ').filter((t) => Boolean(t && t.trim()));
const username = '@' + user.username;
const quotedUsername = `"${username}"`;
for (let i = 0; i < termsArr.length; i++) {
if (termsArr[i] === username) {
termsArr[i] = quotedUsername;
break;
}
}
searchTerms = termsArr.join(' ');
}
// timezone offset in seconds
const userCurrentTimezone = getCurrentTimezone(getState());
const timezoneOffset = ((userCurrentTimezone && (userCurrentTimezone.length > 0)) ? getUtcOffsetForTimeZone(userCurrentTimezone) : getBrowserUtcOffset()) * 60;
const messagesPromise = dispatch(searchPostsWithParams(isMentionSearch ? '' : teamId, {terms, is_or_search: Boolean(isMentionSearch), include_deleted_channels: viewArchivedChannels, time_zone_offset: timezoneOffset, page: 0, per_page: 20}));
const messagesPromise = dispatch(searchPostsWithParams(isMentionSearch ? '' : teamId, {terms: searchTerms, is_or_search: Boolean(isMentionSearch), include_deleted_channels: viewArchivedChannels, time_zone_offset: timezoneOffset, page: 0, per_page: 20}));
const filesPromise = dispatch(searchFilesWithParams(teamId, {terms: termsWithExtensionsFilters, is_or_search: Boolean(isMentionSearch), include_deleted_channels: viewArchivedChannels, time_zone_offset: timezoneOffset, page: 0, per_page: 20}));
return Promise.all([filesPromise, messagesPromise]);
};