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

View File

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