[Refactoring] Replace local* with account* for search result (#3981)

This commit is contained in:
Alexander Zinchuk 2023-12-04 14:37:46 +01:00
parent ed424cceae
commit c0e5b94fcb
4 changed files with 28 additions and 28 deletions

View File

@ -249,17 +249,17 @@ export async function searchChats({ query }: { query: string }) {
updateLocalDb(result);
const localPeerIds = result.myResults.map(getApiChatIdFromMtpPeer);
const accountPeerIds = result.myResults.map(getApiChatIdFromMtpPeer);
const allChats = result.chats.concat(result.users)
.map((user) => buildApiChatFromPreview(user))
.filter(Boolean);
const allUsers = result.users.map(buildApiUser).filter((user) => Boolean(user) && !user.isSelf) as ApiUser[];
return {
localChats: allChats.filter((r) => localPeerIds.includes(r.id)),
localUsers: allUsers.filter((u) => localPeerIds.includes(u.id)),
globalChats: allChats.filter((r) => !localPeerIds.includes(r.id)),
globalUsers: allUsers.filter((u) => !localPeerIds.includes(u.id)),
accountChats: allChats.filter((r) => accountPeerIds.includes(r.id)),
accountUsers: allUsers.filter((u) => accountPeerIds.includes(u.id)),
globalChats: allChats.filter((r) => !accountPeerIds.includes(r.id)),
globalUsers: allUsers.filter((u) => !accountPeerIds.includes(u.id)),
};
}

View File

@ -41,8 +41,8 @@ export type OwnProps = {
type StateProps = {
currentUserId?: string;
localContactIds?: string[];
localChatIds?: string[];
localUserIds?: string[];
accountChatIds?: string[];
accountUserIds?: string[];
globalChatIds?: string[];
globalUserIds?: string[];
foundIds?: string[];
@ -62,8 +62,8 @@ const ChatResults: FC<OwnProps & StateProps> = ({
dateSearchQuery,
currentUserId,
localContactIds,
localChatIds,
localUserIds,
accountChatIds,
accountUserIds,
globalChatIds,
globalUserIds,
foundIds,
@ -127,18 +127,18 @@ 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(
const foundLocalContactIds = filterUsersByName(
contactIdsWithMe, usersById, searchQuery, currentUserId, lang('SavedMessages'),
);
return [
...sortChatIds(unique([
...(foundContactIds || []),
...(localChatIds || []),
...(localUserIds || []),
...(foundLocalContactIds || []),
...(accountChatIds || []),
...(accountUserIds || []),
]), chatsById, undefined, currentUserId ? [currentUserId] : undefined),
];
}, [searchQuery, currentUserId, localContactIds, lang, localChatIds, localUserIds, chatsById]);
}, [searchQuery, currentUserId, localContactIds, lang, accountChatIds, accountUserIds, chatsById]);
useHorizontalScroll(chatSelectionRef, !localResults.length, true);
@ -317,15 +317,15 @@ export default memo(withGlobal<OwnProps>(
fetchingStatus, globalResults, localResults, resultsByType,
} = selectTabState(global).globalSearch;
const { chatIds: globalChatIds, userIds: globalUserIds } = globalResults || {};
const { chatIds: localChatIds, userIds: localUserIds } = localResults || {};
const { chatIds: accountChatIds, userIds: accountUserIds } = localResults || {};
const { byChatId: globalMessagesByChatId } = messages;
const foundIds = resultsByType?.text?.foundIds;
return {
currentUserId,
localContactIds,
localChatIds,
localUserIds,
accountChatIds,
accountUserIds,
globalChatIds,
globalUserIds,
foundIds,

View File

@ -40,22 +40,22 @@ addActionHandler('setGlobalSearchQuery', (global, actions, payload): ActionRetur
}
const {
localChats, localUsers, globalChats, globalUsers,
accountChats, accountUsers, globalChats, globalUsers,
} = result;
if (localChats.length || globalChats.length) {
global = addChats(global, buildCollectionByKey([...localChats, ...globalChats], 'id'));
if (accountChats.length || globalChats.length) {
global = addChats(global, buildCollectionByKey([...accountChats, ...globalChats], 'id'));
}
if (localUsers.length || globalUsers.length) {
global = addUsers(global, buildCollectionByKey([...localUsers, ...globalUsers], 'id'));
if (accountUsers.length || globalUsers.length) {
global = addUsers(global, buildCollectionByKey([...accountUsers, ...globalUsers], 'id'));
}
global = updateGlobalSearchFetchingStatus(global, { chats: false }, tabId);
global = updateGlobalSearch(global, {
localResults: {
chatIds: localChats.map(({ id }) => id),
userIds: localUsers.map(({ id }) => id),
chatIds: accountChats.map(({ id }) => id),
userIds: accountChats.map(({ id }) => id),
},
globalResults: {
...selectTabState(global, tabId).globalSearch.globalResults,

View File

@ -314,13 +314,13 @@ addActionHandler('setUserSearchQuery', (global, actions, payload): ActionReturnT
return;
}
const { localUsers, globalUsers } = result;
const { accountUsers, globalUsers } = result;
let localUserIds;
let globalUserIds;
if (localUsers.length) {
global = addUsers(global, buildCollectionByKey(localUsers, 'id'));
localUserIds = localUsers.map(({ id }) => id);
if (accountUsers.length) {
global = addUsers(global, buildCollectionByKey(accountUsers, 'id'));
localUserIds = accountUsers.map(({ id }) => id);
}
if (globalUsers.length) {
global = addUsers(global, buildCollectionByKey(globalUsers, 'id'));