Global Search: Fix missing Saved Messages in search results

This commit is contained in:
Alexander Zinchuk 2022-01-21 17:29:19 +01:00
parent ace2d3be35
commit 71059dff06
2 changed files with 12 additions and 4 deletions

View File

@ -105,7 +105,9 @@ const ChatResults: FC<OwnProps & StateProps> = ({
];
// No need for expensive global updates on users, so we avoid them
const usersById = getGlobal().users.byId;
const foundContactIds = filterUsersByName(contactIdsWithMe, usersById, searchQuery);
const foundContactIds = filterUsersByName(
contactIdsWithMe, usersById, searchQuery, currentUserId, lang('SavedMessages'),
);
return [
...sortChatIds(unique([
@ -114,7 +116,7 @@ const ChatResults: FC<OwnProps & StateProps> = ({
...(localUserIds || []),
]), chatsById, undefined, currentUserId ? [currentUserId] : undefined),
];
}, [searchQuery, localContactIds, currentUserId, localChatIds, localUserIds, chatsById]);
}, [searchQuery, currentUserId, localContactIds, lang, localChatIds, localUserIds, chatsById]);
const globalResults = useMemo(() => {
if (!searchQuery || searchQuery.length < MIN_QUERY_LENGTH_FOR_GLOBAL_SEARCH || !globalChatIds || !globalUserIds) {

View File

@ -232,7 +232,13 @@ export function sortUserIds(
}, 'desc');
}
export function filterUsersByName(userIds: string[], usersById: Record<string, ApiUser>, query?: string) {
export function filterUsersByName(
userIds: string[],
usersById: Record<string, ApiUser>,
query?: string,
currentUserId?: string,
savedMessagesLang?: string,
) {
if (!query) {
return userIds;
}
@ -245,7 +251,7 @@ export function filterUsersByName(userIds: string[], usersById: Record<string, A
return false;
}
const name = getUserFullName(user);
const name = id === currentUserId ? savedMessagesLang : getUserFullName(user);
return (name && searchWords(name)) || searchWords(user.username);
});
}