[Refactoring] Replace local* with account* for search result (#3981)
This commit is contained in:
parent
ed424cceae
commit
c0e5b94fcb
@ -249,17 +249,17 @@ export async function searchChats({ query }: { query: string }) {
|
|||||||
|
|
||||||
updateLocalDb(result);
|
updateLocalDb(result);
|
||||||
|
|
||||||
const localPeerIds = result.myResults.map(getApiChatIdFromMtpPeer);
|
const accountPeerIds = result.myResults.map(getApiChatIdFromMtpPeer);
|
||||||
const allChats = result.chats.concat(result.users)
|
const allChats = result.chats.concat(result.users)
|
||||||
.map((user) => buildApiChatFromPreview(user))
|
.map((user) => buildApiChatFromPreview(user))
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
const allUsers = result.users.map(buildApiUser).filter((user) => Boolean(user) && !user.isSelf) as ApiUser[];
|
const allUsers = result.users.map(buildApiUser).filter((user) => Boolean(user) && !user.isSelf) as ApiUser[];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
localChats: allChats.filter((r) => localPeerIds.includes(r.id)),
|
accountChats: allChats.filter((r) => accountPeerIds.includes(r.id)),
|
||||||
localUsers: allUsers.filter((u) => localPeerIds.includes(u.id)),
|
accountUsers: allUsers.filter((u) => accountPeerIds.includes(u.id)),
|
||||||
globalChats: allChats.filter((r) => !localPeerIds.includes(r.id)),
|
globalChats: allChats.filter((r) => !accountPeerIds.includes(r.id)),
|
||||||
globalUsers: allUsers.filter((u) => !localPeerIds.includes(u.id)),
|
globalUsers: allUsers.filter((u) => !accountPeerIds.includes(u.id)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,8 +41,8 @@ export type OwnProps = {
|
|||||||
type StateProps = {
|
type StateProps = {
|
||||||
currentUserId?: string;
|
currentUserId?: string;
|
||||||
localContactIds?: string[];
|
localContactIds?: string[];
|
||||||
localChatIds?: string[];
|
accountChatIds?: string[];
|
||||||
localUserIds?: string[];
|
accountUserIds?: string[];
|
||||||
globalChatIds?: string[];
|
globalChatIds?: string[];
|
||||||
globalUserIds?: string[];
|
globalUserIds?: string[];
|
||||||
foundIds?: string[];
|
foundIds?: string[];
|
||||||
@ -62,8 +62,8 @@ const ChatResults: FC<OwnProps & StateProps> = ({
|
|||||||
dateSearchQuery,
|
dateSearchQuery,
|
||||||
currentUserId,
|
currentUserId,
|
||||||
localContactIds,
|
localContactIds,
|
||||||
localChatIds,
|
accountChatIds,
|
||||||
localUserIds,
|
accountUserIds,
|
||||||
globalChatIds,
|
globalChatIds,
|
||||||
globalUserIds,
|
globalUserIds,
|
||||||
foundIds,
|
foundIds,
|
||||||
@ -127,18 +127,18 @@ 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(
|
const foundLocalContactIds = filterUsersByName(
|
||||||
contactIdsWithMe, usersById, searchQuery, currentUserId, lang('SavedMessages'),
|
contactIdsWithMe, usersById, searchQuery, currentUserId, lang('SavedMessages'),
|
||||||
);
|
);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...sortChatIds(unique([
|
...sortChatIds(unique([
|
||||||
...(foundContactIds || []),
|
...(foundLocalContactIds || []),
|
||||||
...(localChatIds || []),
|
...(accountChatIds || []),
|
||||||
...(localUserIds || []),
|
...(accountUserIds || []),
|
||||||
]), chatsById, undefined, currentUserId ? [currentUserId] : undefined),
|
]), chatsById, undefined, currentUserId ? [currentUserId] : undefined),
|
||||||
];
|
];
|
||||||
}, [searchQuery, currentUserId, localContactIds, lang, localChatIds, localUserIds, chatsById]);
|
}, [searchQuery, currentUserId, localContactIds, lang, accountChatIds, accountUserIds, chatsById]);
|
||||||
|
|
||||||
useHorizontalScroll(chatSelectionRef, !localResults.length, true);
|
useHorizontalScroll(chatSelectionRef, !localResults.length, true);
|
||||||
|
|
||||||
@ -317,15 +317,15 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
fetchingStatus, globalResults, localResults, resultsByType,
|
fetchingStatus, globalResults, localResults, resultsByType,
|
||||||
} = selectTabState(global).globalSearch;
|
} = selectTabState(global).globalSearch;
|
||||||
const { chatIds: globalChatIds, userIds: globalUserIds } = globalResults || {};
|
const { chatIds: globalChatIds, userIds: globalUserIds } = globalResults || {};
|
||||||
const { chatIds: localChatIds, userIds: localUserIds } = localResults || {};
|
const { chatIds: accountChatIds, userIds: accountUserIds } = localResults || {};
|
||||||
const { byChatId: globalMessagesByChatId } = messages;
|
const { byChatId: globalMessagesByChatId } = messages;
|
||||||
const foundIds = resultsByType?.text?.foundIds;
|
const foundIds = resultsByType?.text?.foundIds;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentUserId,
|
currentUserId,
|
||||||
localContactIds,
|
localContactIds,
|
||||||
localChatIds,
|
accountChatIds,
|
||||||
localUserIds,
|
accountUserIds,
|
||||||
globalChatIds,
|
globalChatIds,
|
||||||
globalUserIds,
|
globalUserIds,
|
||||||
foundIds,
|
foundIds,
|
||||||
|
|||||||
@ -40,22 +40,22 @@ addActionHandler('setGlobalSearchQuery', (global, actions, payload): ActionRetur
|
|||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
localChats, localUsers, globalChats, globalUsers,
|
accountChats, accountUsers, globalChats, globalUsers,
|
||||||
} = result;
|
} = result;
|
||||||
|
|
||||||
if (localChats.length || globalChats.length) {
|
if (accountChats.length || globalChats.length) {
|
||||||
global = addChats(global, buildCollectionByKey([...localChats, ...globalChats], 'id'));
|
global = addChats(global, buildCollectionByKey([...accountChats, ...globalChats], 'id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localUsers.length || globalUsers.length) {
|
if (accountUsers.length || globalUsers.length) {
|
||||||
global = addUsers(global, buildCollectionByKey([...localUsers, ...globalUsers], 'id'));
|
global = addUsers(global, buildCollectionByKey([...accountUsers, ...globalUsers], 'id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
global = updateGlobalSearchFetchingStatus(global, { chats: false }, tabId);
|
global = updateGlobalSearchFetchingStatus(global, { chats: false }, tabId);
|
||||||
global = updateGlobalSearch(global, {
|
global = updateGlobalSearch(global, {
|
||||||
localResults: {
|
localResults: {
|
||||||
chatIds: localChats.map(({ id }) => id),
|
chatIds: accountChats.map(({ id }) => id),
|
||||||
userIds: localUsers.map(({ id }) => id),
|
userIds: accountChats.map(({ id }) => id),
|
||||||
},
|
},
|
||||||
globalResults: {
|
globalResults: {
|
||||||
...selectTabState(global, tabId).globalSearch.globalResults,
|
...selectTabState(global, tabId).globalSearch.globalResults,
|
||||||
|
|||||||
@ -314,13 +314,13 @@ addActionHandler('setUserSearchQuery', (global, actions, payload): ActionReturnT
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { localUsers, globalUsers } = result;
|
const { accountUsers, globalUsers } = result;
|
||||||
|
|
||||||
let localUserIds;
|
let localUserIds;
|
||||||
let globalUserIds;
|
let globalUserIds;
|
||||||
if (localUsers.length) {
|
if (accountUsers.length) {
|
||||||
global = addUsers(global, buildCollectionByKey(localUsers, 'id'));
|
global = addUsers(global, buildCollectionByKey(accountUsers, 'id'));
|
||||||
localUserIds = localUsers.map(({ id }) => id);
|
localUserIds = accountUsers.map(({ id }) => id);
|
||||||
}
|
}
|
||||||
if (globalUsers.length) {
|
if (globalUsers.length) {
|
||||||
global = addUsers(global, buildCollectionByKey(globalUsers, 'id'));
|
global = addUsers(global, buildCollectionByKey(globalUsers, 'id'));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user