[Perf] Message: Remove n^2 for detecting contacts

This commit is contained in:
Alexander Zinchuk 2024-09-06 15:42:46 +02:00
parent 1e4950c7e3
commit 67bdfe318b
2 changed files with 2 additions and 7 deletions

View File

@ -72,7 +72,6 @@ import { selectTabState } from './tabs';
import {
selectBot,
selectIsCurrentUserPremium,
selectIsUserOrChatContact,
selectUser,
selectUserStatus,
} from './users';
@ -1197,7 +1196,7 @@ function canAutoLoadMedia<T extends GlobalState>({
sender?: ApiPeer;
}) {
const isMediaFromContact = Boolean(sender && (
selectIsChatWithSelf(global, sender.id) || selectIsUserOrChatContact(global, sender)
selectIsChatWithSelf(global, sender.id) || selectUser(global, sender.id)?.isContact
));
return Boolean(

View File

@ -1,5 +1,5 @@
import type {
ApiPeer, ApiUser, ApiUserFullInfo, ApiUserStatus,
ApiUser, ApiUserFullInfo, ApiUserStatus,
} from '../../api/types';
import type { GlobalState } from '../types';
@ -42,10 +42,6 @@ export function selectUserByPhoneNumber<T extends GlobalState>(global: T, phoneN
return Object.values(global.users.byId).find((user) => user?.phoneNumber === phoneNumberCleaned);
}
export function selectIsUserOrChatContact<T extends GlobalState>(global: T, peer: ApiPeer) {
return global.contactList && global.contactList.userIds.includes(peer.id);
}
export function selectBot<T extends GlobalState>(global: T, userId: string): ApiUser | undefined {
const user = selectUser(global, userId);
if (!user || !isUserBot(user)) {