[Perf] Reduce usage of frequently updated currentUser
This commit is contained in:
parent
1c82160285
commit
be7920f9e0
@ -3,9 +3,8 @@ import { getActions, withGlobal } from '../../../global';
|
|||||||
|
|
||||||
import type { FC } from '../../../lib/teact/teact';
|
import type { FC } from '../../../lib/teact/teact';
|
||||||
import { SettingsScreens } from '../../../types';
|
import { SettingsScreens } from '../../../types';
|
||||||
import type { ApiUser } from '../../../api/types';
|
|
||||||
|
|
||||||
import { selectIsPremiumPurchaseBlocked, selectUser } from '../../../global/selectors';
|
import { selectIsPremiumPurchaseBlocked } from '../../../global/selectors';
|
||||||
import useLang from '../../../hooks/useLang';
|
import useLang from '../../../hooks/useLang';
|
||||||
import useHistoryBack from '../../../hooks/useHistoryBack';
|
import useHistoryBack from '../../../hooks/useHistoryBack';
|
||||||
|
|
||||||
@ -22,7 +21,7 @@ type OwnProps = {
|
|||||||
|
|
||||||
type StateProps = {
|
type StateProps = {
|
||||||
sessionCount: number;
|
sessionCount: number;
|
||||||
currentUser?: ApiUser;
|
currentUserId?: string;
|
||||||
canBuyPremium?: boolean;
|
canBuyPremium?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -30,7 +29,7 @@ const SettingsMain: FC<OwnProps & StateProps> = ({
|
|||||||
isActive,
|
isActive,
|
||||||
onScreenSelect,
|
onScreenSelect,
|
||||||
onReset,
|
onReset,
|
||||||
currentUser,
|
currentUserId,
|
||||||
sessionCount,
|
sessionCount,
|
||||||
canBuyPremium,
|
canBuyPremium,
|
||||||
}) => {
|
}) => {
|
||||||
@ -41,13 +40,12 @@ const SettingsMain: FC<OwnProps & StateProps> = ({
|
|||||||
} = getActions();
|
} = getActions();
|
||||||
|
|
||||||
const lang = useLang();
|
const lang = useLang();
|
||||||
const profileId = currentUser?.id;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (profileId) {
|
if (currentUserId) {
|
||||||
loadProfilePhotos({ profileId });
|
loadProfilePhotos({ profileId: currentUserId });
|
||||||
}
|
}
|
||||||
}, [profileId, loadProfilePhotos]);
|
}, [currentUserId, loadProfilePhotos]);
|
||||||
|
|
||||||
useHistoryBack({
|
useHistoryBack({
|
||||||
isActive,
|
isActive,
|
||||||
@ -61,16 +59,16 @@ const SettingsMain: FC<OwnProps & StateProps> = ({
|
|||||||
return (
|
return (
|
||||||
<div className="settings-content custom-scroll">
|
<div className="settings-content custom-scroll">
|
||||||
<div className="settings-main-menu">
|
<div className="settings-main-menu">
|
||||||
{currentUser && (
|
{currentUserId && (
|
||||||
<ProfileInfo
|
<ProfileInfo
|
||||||
userId={currentUser.id}
|
userId={currentUserId}
|
||||||
canPlayVideo={Boolean(isActive)}
|
canPlayVideo={Boolean(isActive)}
|
||||||
forceShowSelf
|
forceShowSelf
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{currentUser && (
|
{currentUserId && (
|
||||||
<ChatExtra
|
<ChatExtra
|
||||||
chatOrUserId={currentUser.id}
|
chatOrUserId={currentUserId}
|
||||||
forceShowSelf
|
forceShowSelf
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@ -160,7 +158,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
sessionCount: global.activeSessions.orderedHashes.length,
|
sessionCount: global.activeSessions.orderedHashes.length,
|
||||||
currentUser: currentUserId ? selectUser(global, currentUserId) : undefined,
|
currentUserId,
|
||||||
canBuyPremium: !selectIsPremiumPurchaseBlocked(global),
|
canBuyPremium: !selectIsPremiumPurchaseBlocked(global),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import React, {
|
|||||||
import { getActions } from '../../../global';
|
import { getActions } from '../../../global';
|
||||||
|
|
||||||
import type { FC } from '../../../lib/teact/teact';
|
import type { FC } from '../../../lib/teact/teact';
|
||||||
import type { ApiPhoto, ApiUser } from '../../../api/types';
|
import type { ApiPhoto } from '../../../api/types';
|
||||||
|
|
||||||
import useFlag from '../../../hooks/useFlag';
|
import useFlag from '../../../hooks/useFlag';
|
||||||
import useLang from '../../../hooks/useLang';
|
import useLang from '../../../hooks/useLang';
|
||||||
@ -17,13 +17,13 @@ import ConfirmDialog from '../../ui/ConfirmDialog';
|
|||||||
import styles from './SettingsPrivacyPublicPhoto.module.scss';
|
import styles from './SettingsPrivacyPublicPhoto.module.scss';
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
currentUser: ApiUser;
|
currentUserId: string;
|
||||||
hasCurrentUserFullInfo?: boolean;
|
hasCurrentUserFullInfo?: boolean;
|
||||||
currentUserFallbackPhoto?: ApiPhoto;
|
currentUserFallbackPhoto?: ApiPhoto;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SettingsPrivacyPublicProfilePhoto: FC<OwnProps> = ({
|
const SettingsPrivacyPublicProfilePhoto: FC<OwnProps> = ({
|
||||||
currentUser,
|
currentUserId,
|
||||||
hasCurrentUserFullInfo,
|
hasCurrentUserFullInfo,
|
||||||
currentUserFallbackPhoto,
|
currentUserFallbackPhoto,
|
||||||
}) => {
|
}) => {
|
||||||
@ -40,9 +40,9 @@ const SettingsPrivacyPublicProfilePhoto: FC<OwnProps> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!hasCurrentUserFullInfo) {
|
if (!hasCurrentUserFullInfo) {
|
||||||
loadFullUser({ userId: currentUser.id });
|
loadFullUser({ userId: currentUserId });
|
||||||
}
|
}
|
||||||
}, [hasCurrentUserFullInfo, currentUser.id, loadFullUser]);
|
}, [hasCurrentUserFullInfo, currentUserId, loadFullUser]);
|
||||||
|
|
||||||
const handleSelectFile = useCallback((file: File) => {
|
const handleSelectFile = useCallback((file: File) => {
|
||||||
uploadProfilePhoto({
|
uploadProfilePhoto({
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import type { ApiPrivacySettings } from '../../../types';
|
|||||||
import { SettingsScreens } from '../../../types';
|
import { SettingsScreens } from '../../../types';
|
||||||
|
|
||||||
import { getPrivacyKey } from './helpers/privacy';
|
import { getPrivacyKey } from './helpers/privacy';
|
||||||
import { selectUser, selectUserFullInfo } from '../../../global/selectors';
|
import { selectUserFullInfo } from '../../../global/selectors';
|
||||||
import useLang from '../../../hooks/useLang';
|
import useLang from '../../../hooks/useLang';
|
||||||
import useHistoryBack from '../../../hooks/useHistoryBack';
|
import useHistoryBack from '../../../hooks/useHistoryBack';
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ type StateProps =
|
|||||||
Partial<ApiPrivacySettings> & {
|
Partial<ApiPrivacySettings> & {
|
||||||
chatsById?: Record<string, ApiChat>;
|
chatsById?: Record<string, ApiChat>;
|
||||||
usersById?: Record<string, ApiUser>;
|
usersById?: Record<string, ApiUser>;
|
||||||
currentUser: ApiUser;
|
currentUserId: string;
|
||||||
hasCurrentUserFullInfo?: boolean;
|
hasCurrentUserFullInfo?: boolean;
|
||||||
currentUserFallbackPhoto?: ApiPhoto;
|
currentUserFallbackPhoto?: ApiPhoto;
|
||||||
};
|
};
|
||||||
@ -42,7 +42,7 @@ const SettingsPrivacyVisibility: FC<OwnProps & StateProps> = ({
|
|||||||
blockUserIds,
|
blockUserIds,
|
||||||
blockChatIds,
|
blockChatIds,
|
||||||
chatsById,
|
chatsById,
|
||||||
currentUser,
|
currentUserId,
|
||||||
hasCurrentUserFullInfo,
|
hasCurrentUserFullInfo,
|
||||||
currentUserFallbackPhoto,
|
currentUserFallbackPhoto,
|
||||||
}) => {
|
}) => {
|
||||||
@ -227,7 +227,7 @@ const SettingsPrivacyVisibility: FC<OwnProps & StateProps> = ({
|
|||||||
|
|
||||||
{screen === SettingsScreens.PrivacyProfilePhoto && exceptionLists.shouldShowAllowed && (
|
{screen === SettingsScreens.PrivacyProfilePhoto && exceptionLists.shouldShowAllowed && (
|
||||||
<SettingsPrivacyPublicProfilePhoto
|
<SettingsPrivacyPublicProfilePhoto
|
||||||
currentUser={currentUser}
|
currentUserId={currentUserId}
|
||||||
hasCurrentUserFullInfo={hasCurrentUserFullInfo}
|
hasCurrentUserFullInfo={hasCurrentUserFullInfo}
|
||||||
currentUserFallbackPhoto={currentUserFallbackPhoto}
|
currentUserFallbackPhoto={currentUserFallbackPhoto}
|
||||||
/>
|
/>
|
||||||
@ -241,12 +241,12 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
let privacySettings: ApiPrivacySettings | undefined;
|
let privacySettings: ApiPrivacySettings | undefined;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
currentUserId,
|
||||||
chats: { byId: chatsById },
|
chats: { byId: chatsById },
|
||||||
settings: { privacy },
|
settings: { privacy },
|
||||||
} = global;
|
} = global;
|
||||||
|
|
||||||
const currentUser = selectUser(global, global.currentUserId!)!;
|
const currentUserFullInfo = selectUserFullInfo(global, currentUserId!);
|
||||||
const currentUserFullInfo = selectUserFullInfo(global, global.currentUserId!);
|
|
||||||
|
|
||||||
switch (screen) {
|
switch (screen) {
|
||||||
case SettingsScreens.PrivacyPhoneNumber:
|
case SettingsScreens.PrivacyPhoneNumber:
|
||||||
@ -284,7 +284,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
|
|
||||||
if (!privacySettings) {
|
if (!privacySettings) {
|
||||||
return {
|
return {
|
||||||
currentUser,
|
currentUserId: currentUserId!,
|
||||||
hasCurrentUserFullInfo: Boolean(currentUserFullInfo),
|
hasCurrentUserFullInfo: Boolean(currentUserFullInfo),
|
||||||
currentUserFallbackPhoto: currentUserFullInfo?.fallbackPhoto,
|
currentUserFallbackPhoto: currentUserFullInfo?.fallbackPhoto,
|
||||||
};
|
};
|
||||||
@ -293,7 +293,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
return {
|
return {
|
||||||
...privacySettings,
|
...privacySettings,
|
||||||
chatsById,
|
chatsById,
|
||||||
currentUser,
|
currentUserId: currentUserId!,
|
||||||
hasCurrentUserFullInfo: Boolean(currentUserFullInfo),
|
hasCurrentUserFullInfo: Boolean(currentUserFullInfo),
|
||||||
currentUserFallbackPhoto: currentUserFullInfo?.fallbackPhoto,
|
currentUserFallbackPhoto: currentUserFullInfo?.fallbackPhoto,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -37,6 +37,7 @@ import {
|
|||||||
selectCanAnimateInterface,
|
selectCanAnimateInterface,
|
||||||
selectChatFolder,
|
selectChatFolder,
|
||||||
} from '../../global/selectors';
|
} from '../../global/selectors';
|
||||||
|
import { getUserFullName } from '../../global/helpers';
|
||||||
import buildClassName from '../../util/buildClassName';
|
import buildClassName from '../../util/buildClassName';
|
||||||
import { waitForTransitionEnd } from '../../util/cssAnimationEndListeners';
|
import { waitForTransitionEnd } from '../../util/cssAnimationEndListeners';
|
||||||
import { processDeepLink } from '../../util/deeplink';
|
import { processDeepLink } from '../../util/deeplink';
|
||||||
@ -135,7 +136,7 @@ type StateProps = {
|
|||||||
attachBotToInstall?: ApiAttachBot;
|
attachBotToInstall?: ApiAttachBot;
|
||||||
requestedAttachBotInChat?: TabState['requestedAttachBotInChat'];
|
requestedAttachBotInChat?: TabState['requestedAttachBotInChat'];
|
||||||
requestedDraft?: TabState['requestedDraft'];
|
requestedDraft?: TabState['requestedDraft'];
|
||||||
currentUser?: ApiUser;
|
currentUserName?: string;
|
||||||
urlAuth?: TabState['urlAuth'];
|
urlAuth?: TabState['urlAuth'];
|
||||||
limitReached?: ApiLimitTypeWithModal;
|
limitReached?: ApiLimitTypeWithModal;
|
||||||
deleteFolderDialog?: ApiChatFolder;
|
deleteFolderDialog?: ApiChatFolder;
|
||||||
@ -191,7 +192,7 @@ const Main: FC<OwnProps & StateProps> = ({
|
|||||||
requestedAttachBotInChat,
|
requestedAttachBotInChat,
|
||||||
requestedDraft,
|
requestedDraft,
|
||||||
webApp,
|
webApp,
|
||||||
currentUser,
|
currentUserName,
|
||||||
urlAuth,
|
urlAuth,
|
||||||
isPremiumModalOpen,
|
isPremiumModalOpen,
|
||||||
isPaymentModalOpen,
|
isPaymentModalOpen,
|
||||||
@ -516,7 +517,7 @@ const Main: FC<OwnProps & StateProps> = ({
|
|||||||
<Dialogs isOpen={hasDialogs} />
|
<Dialogs isOpen={hasDialogs} />
|
||||||
{audioMessage && <AudioPlayer key={audioMessage.id} message={audioMessage} noUi />}
|
{audioMessage && <AudioPlayer key={audioMessage.id} message={audioMessage} noUi />}
|
||||||
<SafeLinkModal url={safeLinkModalUrl} />
|
<SafeLinkModal url={safeLinkModalUrl} />
|
||||||
<UrlAuthModal urlAuth={urlAuth} currentUser={currentUser} />
|
<UrlAuthModal urlAuth={urlAuth} currentUserName={currentUserName} />
|
||||||
<HistoryCalendar isOpen={isHistoryCalendarOpen} />
|
<HistoryCalendar isOpen={isHistoryCalendarOpen} />
|
||||||
<StickerSetModal
|
<StickerSetModal
|
||||||
isOpen={Boolean(openedStickerSetShortName)}
|
isOpen={Boolean(openedStickerSetShortName)}
|
||||||
@ -643,7 +644,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
attachBotToInstall: requestedAttachBotInstall?.bot,
|
attachBotToInstall: requestedAttachBotInstall?.bot,
|
||||||
requestedAttachBotInChat,
|
requestedAttachBotInChat,
|
||||||
webApp,
|
webApp,
|
||||||
currentUser,
|
currentUserName: getUserFullName(currentUser),
|
||||||
urlAuth,
|
urlAuth,
|
||||||
isCurrentUserPremium: selectIsCurrentUserPremium(global),
|
isCurrentUserPremium: selectIsCurrentUserPremium(global),
|
||||||
isPremiumModalOpen: premiumModal?.isOpen,
|
isPremiumModalOpen: premiumModal?.isOpen,
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import React, {
|
|||||||
import { getActions, getGlobal } from '../../global';
|
import { getActions, getGlobal } from '../../global';
|
||||||
|
|
||||||
import type { FC } from '../../lib/teact/teact';
|
import type { FC } from '../../lib/teact/teact';
|
||||||
import type { ApiUser } from '../../api/types';
|
|
||||||
import type { TabState } from '../../global/types';
|
import type { TabState } from '../../global/types';
|
||||||
|
|
||||||
import { ensureProtocol } from '../../util/ensureProtocol';
|
import { ensureProtocol } from '../../util/ensureProtocol';
|
||||||
@ -21,11 +20,11 @@ import styles from './UrlAuthModal.module.scss';
|
|||||||
|
|
||||||
export type OwnProps = {
|
export type OwnProps = {
|
||||||
urlAuth?: TabState['urlAuth'];
|
urlAuth?: TabState['urlAuth'];
|
||||||
currentUser?: ApiUser;
|
currentUserName?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const UrlAuthModal: FC<OwnProps> = ({
|
const UrlAuthModal: FC<OwnProps> = ({
|
||||||
urlAuth, currentUser,
|
urlAuth, currentUserName,
|
||||||
}) => {
|
}) => {
|
||||||
const { closeUrlAuthModal, acceptBotUrlAuth, acceptLinkUrlAuth } = getActions();
|
const { closeUrlAuthModal, acceptBotUrlAuth, acceptLinkUrlAuth } = getActions();
|
||||||
const [isLoginChecked, setLoginChecked] = useState(true);
|
const [isLoginChecked, setLoginChecked] = useState(true);
|
||||||
@ -82,7 +81,7 @@ const UrlAuthModal: FC<OwnProps> = ({
|
|||||||
label={(
|
label={(
|
||||||
<>
|
<>
|
||||||
{renderText(
|
{renderText(
|
||||||
lang('Conversation.OpenBotLinkLogin', [domain, getUserFullName(currentUser)]),
|
lang('Conversation.OpenBotLinkLogin', [domain, currentUserName]),
|
||||||
['simple_markdown'],
|
['simple_markdown'],
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user