From 27203e9976c1d8618c8d6c642370cc8af277e113 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 25 Apr 2023 17:24:08 +0400 Subject: [PATCH] Avatar: Finally remove animated avatars (#3061) --- .../calls/group/GroupCallParticipant.tsx | 9 ++-- .../calls/group/GroupCallParticipantVideo.tsx | 9 ++-- .../calls/group/GroupCallTopPane.tsx | 14 ++--- src/components/calls/phone/PhoneCall.tsx | 9 +--- src/components/common/Avatar.tsx | 20 +------- src/components/common/PickerSelectedItem.tsx | 9 +--- src/components/common/PrivateChatInfo.tsx | 11 +--- src/components/common/ProfilePhoto.tsx | 2 +- src/components/common/UserAvatar.tsx | 51 ------------------- src/components/left/main/Chat.tsx | 7 --- src/components/left/search/ChatMessage.tsx | 13 ++--- src/components/left/search/RecentContacts.tsx | 9 +++- .../left/settings/SettingsActiveWebsite.tsx | 9 +--- .../left/settings/SettingsActiveWebsites.tsx | 8 ++- .../settings/SettingsPrivacyBlockedUsers.tsx | 4 +- src/components/main/NewContactModal.tsx | 11 +--- .../main/premium/GiftPremiumModal.tsx | 9 +--- src/components/mediaViewer/SenderInfo.tsx | 3 +- src/components/middle/ActionMessage.tsx | 8 +-- src/components/middle/ReactorListModal.tsx | 8 ++- src/components/middle/composer/Composer.tsx | 8 +-- src/components/middle/composer/SendAsMenu.tsx | 20 +++----- .../middle/message/CommentButton.tsx | 2 - src/components/middle/message/Contact.tsx | 12 ++--- src/components/middle/message/Location.tsx | 8 +-- src/components/middle/message/Message.tsx | 15 ------ .../middle/message/MessageContextMenu.tsx | 4 +- src/components/middle/message/Poll.tsx | 4 +- .../middle/message/ReactionButton.tsx | 2 - src/components/right/RightSearch.tsx | 15 ++---- .../right/management/JoinRequest.tsx | 8 +-- .../right/management/ManageUser.tsx | 7 +-- src/global/helpers/chats.ts | 8 --- src/global/selectors/users.ts | 14 ----- 34 files changed, 76 insertions(+), 274 deletions(-) delete mode 100644 src/components/common/UserAvatar.tsx diff --git a/src/components/calls/group/GroupCallParticipant.tsx b/src/components/calls/group/GroupCallParticipant.tsx index 56c42bd55..d1b10c89c 100644 --- a/src/components/calls/group/GroupCallParticipant.tsx +++ b/src/components/calls/group/GroupCallParticipant.tsx @@ -4,10 +4,10 @@ import type { FC } from '../../../lib/teact/teact'; import React, { memo, useMemo, useRef } from '../../../lib/teact/teact'; import { withGlobal } from '../../../global'; -import type { ApiChat, ApiPhoto, ApiUser } from '../../../api/types'; +import type { ApiChat, ApiUser } from '../../../api/types'; import buildClassName from '../../../util/buildClassName'; -import { selectChat, selectUser, selectUserPhotoFromFullInfo } from '../../../global/selectors'; +import { selectChat, selectUser } from '../../../global/selectors'; import useLang from '../../../hooks/useLang'; import { GROUP_CALL_DEFAULT_VOLUME, GROUP_CALL_VOLUME_MULTIPLIER } from '../../../config'; @@ -23,7 +23,6 @@ type OwnProps = { type StateProps = { user?: ApiUser; - userProfilePhoto?: ApiPhoto; chat?: ApiChat; }; @@ -31,7 +30,6 @@ const GroupCallParticipant: FC = ({ openParticipantMenu, participant, user, - userProfilePhoto, chat, }) => { // eslint-disable-next-line no-null/no-null @@ -81,7 +79,7 @@ const GroupCallParticipant: FC = ({ onClick={handleOnClick} ref={anchorRef} > - +
{name} {aboutText} @@ -98,7 +96,6 @@ export default memo(withGlobal( return { user: participant.isUser ? selectUser(global, participant.id) : undefined, chat: !participant.isUser ? selectChat(global, participant.id) : undefined, - userProfilePhoto: participant.isUser ? selectUserPhotoFromFullInfo(global, participant.id) : undefined, }; }, )(GroupCallParticipant)); diff --git a/src/components/calls/group/GroupCallParticipantVideo.tsx b/src/components/calls/group/GroupCallParticipantVideo.tsx index 3a8859dd6..e09f3ef36 100644 --- a/src/components/calls/group/GroupCallParticipantVideo.tsx +++ b/src/components/calls/group/GroupCallParticipantVideo.tsx @@ -4,11 +4,11 @@ import type { FC } from '../../../lib/teact/teact'; import React, { memo, useCallback } from '../../../lib/teact/teact'; import { withGlobal } from '../../../global'; -import type { ApiChat, ApiPhoto, ApiUser } from '../../../api/types'; +import type { ApiChat, ApiUser } from '../../../api/types'; import { GROUP_CALL_THUMB_VIDEO_DISABLED } from '../../../config'; import buildClassName from '../../../util/buildClassName'; -import { selectChat, selectUser, selectUserPhotoFromFullInfo } from '../../../global/selectors'; +import { selectChat, selectUser } from '../../../global/selectors'; import useLang from '../../../hooks/useLang'; import Avatar from '../../common/Avatar'; @@ -25,7 +25,6 @@ type OwnProps = { type StateProps = { user?: ApiUser; chat?: ApiChat; - userProfilePhoto?: ApiPhoto; currentUserId?: string; isActive?: boolean; }; @@ -35,7 +34,6 @@ const GroupCallParticipantVideo: FC = ({ onClick, user, chat, - userProfilePhoto, isActive, isFullscreen, }) => { @@ -62,7 +60,7 @@ const GroupCallParticipantVideo: FC = ({ {lang('Back')} )} - + {!GROUP_CALL_THUMB_VIDEO_DISABLED && (
))} @@ -123,11 +126,13 @@ export default memo(withGlobal( const { userIds: topUserIds } = global.topPeers; const usersById = global.users.byId; const { recentlyFoundChatIds } = global; + const { animationLevel } = global.settings.byKey; return { topUserIds, usersById, recentlyFoundChatIds, + animationLevel, }; }, )(RecentContacts)); diff --git a/src/components/left/settings/SettingsActiveWebsite.tsx b/src/components/left/settings/SettingsActiveWebsite.tsx index 35f30975a..f08e8143c 100644 --- a/src/components/left/settings/SettingsActiveWebsite.tsx +++ b/src/components/left/settings/SettingsActiveWebsite.tsx @@ -3,10 +3,9 @@ import { getActions, withGlobal } from '../../../global'; import type { FC } from '../../../lib/teact/teact'; import type { AnimationLevel } from '../../../types'; -import type { ApiPhoto, ApiUser, ApiWebSession } from '../../../api/types'; +import type { ApiUser, ApiWebSession } from '../../../api/types'; import buildClassName from '../../../util/buildClassName'; -import { selectUserPhotoFromFullInfo } from '../../../global/selectors'; import useLang from '../../../hooks/useLang'; import useCurrentOrPrev from '../../../hooks/useCurrentOrPrev'; @@ -27,7 +26,6 @@ type OwnProps = { type StateProps = { session?: ApiWebSession; bot?: ApiUser; - botProfilePhoto?: ApiPhoto; animationLevel: AnimationLevel; }; @@ -35,7 +33,6 @@ const SettingsActiveWebsite: FC = ({ isOpen, session, bot, - botProfilePhoto, animationLevel, onClose, }) => { @@ -44,7 +41,6 @@ const SettingsActiveWebsite: FC = ({ const renderingSession = useCurrentOrPrev(session, true); const renderingBot = useCurrentOrPrev(bot, true); - const renderingBotProfilePhoto = useCurrentOrPrev(botProfilePhoto, true); const handleTerminateSessionClick = useCallback(() => { terminateWebAuthorization({ hash: session!.hash }); @@ -83,7 +79,6 @@ const SettingsActiveWebsite: FC = ({ = ({ export default memo(withGlobal((global, { hash }): StateProps => { const session = hash ? global.activeWebSessions.byHash[hash] : undefined; const bot = session ? global.users.byId[session.botId] : undefined; - const botProfilePhoto = bot ? selectUserPhotoFromFullInfo(global, bot.id) : undefined; return { session, bot, - botProfilePhoto, animationLevel: global.settings.byKey.animationLevel, }; })(SettingsActiveWebsite)); diff --git a/src/components/left/settings/SettingsActiveWebsites.tsx b/src/components/left/settings/SettingsActiveWebsites.tsx index 89f97589c..e45ac0a53 100644 --- a/src/components/left/settings/SettingsActiveWebsites.tsx +++ b/src/components/left/settings/SettingsActiveWebsites.tsx @@ -5,6 +5,7 @@ import { getActions, getGlobal, withGlobal } from '../../../global'; import type { FC } from '../../../lib/teact/teact'; import type { ApiWebSession } from '../../../api/types'; +import type { AnimationLevel } from '../../../types'; import { formatPastTimeShort } from '../../../util/dateFormat'; import buildClassName from '../../../util/buildClassName'; @@ -16,7 +17,7 @@ import useHistoryBack from '../../../hooks/useHistoryBack'; import ListItem from '../../ui/ListItem'; import ConfirmDialog from '../../ui/ConfirmDialog'; import SettingsActiveWebsite from './SettingsActiveWebsite'; -import UserAvatar from '../../common/UserAvatar'; +import Avatar from '../../common/Avatar'; import FullNameTitle from '../../common/FullNameTitle'; import styles from './SettingsActiveWebsites.module.scss'; @@ -29,12 +30,14 @@ type OwnProps = { type StateProps = { byHash: Record; orderedHashes: string[]; + animationLevel: AnimationLevel; }; const SettingsActiveWebsites: FC = ({ isActive, byHash, orderedHashes, + animationLevel, onReset, }) => { const { @@ -110,7 +113,7 @@ const SettingsActiveWebsites: FC = ({ // eslint-disable-next-line react/jsx-no-bind onClick={() => handleOpenSessionModal(session.hash)} > - +
{formatPastTimeShort(lang, session.dateActive * 1000)} {bot && } @@ -161,6 +164,7 @@ export default memo(withGlobal( return { byHash, orderedHashes, + animationLevel: global.settings.byKey.animationLevel, }; }, )(SettingsActiveWebsites)); diff --git a/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx b/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx index 48e718224..8a81cf18a 100644 --- a/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx +++ b/src/components/left/settings/SettingsPrivacyBlockedUsers.tsx @@ -1,13 +1,12 @@ import type { FC } from '../../../lib/teact/teact'; import React, { memo, useCallback, useMemo } from '../../../lib/teact/teact'; -import { getActions, getGlobal, withGlobal } from '../../../global'; +import { getActions, withGlobal } from '../../../global'; import type { ApiChat, ApiCountryCode, ApiUser } from '../../../api/types'; import { CHAT_HEIGHT_PX } from '../../../config'; import { formatPhoneNumberWithCode } from '../../../util/phoneNumber'; import { getMainUsername, isUserId } from '../../../global/helpers'; -import { selectUserPhotoFromFullInfo } from '../../../global/selectors'; import buildClassName from '../../../util/buildClassName'; import useLang from '../../../hooks/useLang'; import useHistoryBack from '../../../hooks/useHistoryBack'; @@ -99,7 +98,6 @@ const SettingsPrivacyBlockedUsers: FC = ({ size="medium" user={user} chat={chat} - userProfilePhoto={user ? selectUserPhotoFromFullInfo(getGlobal(), user.id) : undefined} />
{userOrChat && } diff --git a/src/components/main/NewContactModal.tsx b/src/components/main/NewContactModal.tsx index bf5d219b5..c4a3fcf4d 100644 --- a/src/components/main/NewContactModal.tsx +++ b/src/components/main/NewContactModal.tsx @@ -4,13 +4,11 @@ import React, { } from '../../lib/teact/teact'; import { getActions, withGlobal } from '../../global'; -import type { - ApiCountryCode, ApiPhoto, ApiUser, ApiUserStatus, -} from '../../api/types'; +import type { ApiCountryCode, ApiUser, ApiUserStatus } from '../../api/types'; import { IS_TOUCH_ENV } from '../../util/windowEnvironment'; import { getUserStatus } from '../../global/helpers'; -import { selectUser, selectUserPhotoFromFullInfo, selectUserStatus } from '../../global/selectors'; +import { selectUser, selectUserStatus } from '../../global/selectors'; import renderText from '../common/helpers/renderText'; import { formatPhoneNumberWithCode } from '../../util/phoneNumber'; import useLang from '../../hooks/useLang'; @@ -36,7 +34,6 @@ export type OwnProps = { type StateProps = { user?: ApiUser; userStatus?: ApiUserStatus; - userProfilePhoto?: ApiPhoto; phoneCodeList: ApiCountryCode[]; }; @@ -46,14 +43,12 @@ const NewContactModal: FC = ({ isByPhoneNumber, user, userStatus, - userProfilePhoto, phoneCodeList, }) => { const { updateContact, importContact, closeNewContactDialog } = getActions(); const lang = useLang(); const renderingUser = useCurrentOrPrev(user); - const renderingUserProfilePhoto = useCurrentOrPrev(userProfilePhoto); const renderingIsByPhoneNumber = useCurrentOrPrev(isByPhoneNumber); // eslint-disable-next-line no-null/no-null const inputRef = useRef(null); @@ -128,7 +123,6 @@ const NewContactModal: FC = ({
@@ -241,7 +235,6 @@ export default memo(withGlobal( return { user, userStatus: userId ? selectUserStatus(global, userId) : undefined, - userProfilePhoto: user ? selectUserPhotoFromFullInfo(global, user.id) : undefined, phoneCodeList: global.countryList.phoneCodes, }; }, diff --git a/src/components/main/premium/GiftPremiumModal.tsx b/src/components/main/premium/GiftPremiumModal.tsx index 60534bdd1..bf0144301 100644 --- a/src/components/main/premium/GiftPremiumModal.tsx +++ b/src/components/main/premium/GiftPremiumModal.tsx @@ -4,7 +4,7 @@ import React, { import { getActions, withGlobal } from '../../../global'; import type { FC } from '../../../lib/teact/teact'; -import type { ApiPhoto, ApiPremiumGiftOption, ApiUser } from '../../../api/types'; +import type { ApiPremiumGiftOption, ApiUser } from '../../../api/types'; import type { AnimationLevel } from '../../../types'; import { formatCurrency } from '../../../util/formatCurrency'; @@ -14,7 +14,6 @@ import { selectTabState, selectUser, selectUserFullInfo, - selectUserPhotoFromFullInfo, } from '../../../global/selectors'; import useCurrentOrPrev from '../../../hooks/useCurrentOrPrev'; @@ -34,7 +33,6 @@ export type OwnProps = { type StateProps = { user?: ApiUser; - userProfilePhoto?: ApiPhoto; gifts?: ApiPremiumGiftOption[]; monthlyCurrency?: string; monthlyAmount?: number; @@ -44,7 +42,6 @@ type StateProps = { const GiftPremiumModal: FC = ({ isOpen, user, - userProfilePhoto, gifts, monthlyCurrency, monthlyAmount, @@ -54,7 +51,6 @@ const GiftPremiumModal: FC = ({ const lang = useLang(); const renderedUser = useCurrentOrPrev(user, true); - const renderedUserProfilePhoto = useCurrentOrPrev(userProfilePhoto, true); const renderedGifts = useCurrentOrPrev(gifts, true); const [selectedOption, setSelectedOption] = useState(); const firstGift = renderedGifts?.[0]; @@ -133,7 +129,6 @@ const GiftPremiumModal: FC = ({ = ({ export default memo(withGlobal((global): StateProps => { const { forUserId, monthlyCurrency, monthlyAmount } = selectTabState(global).giftPremiumModal || {}; const user = forUserId ? selectUser(global, forUserId) : undefined; - const userProfilePhoto = user ? selectUserPhotoFromFullInfo(global, user.id) : undefined; const gifts = user ? selectUserFullInfo(global, user.id)?.premiumGifts : undefined; return { user, - userProfilePhoto, gifts, monthlyCurrency, monthlyAmount: monthlyAmount ? Number(monthlyAmount) : undefined, diff --git a/src/components/mediaViewer/SenderInfo.tsx b/src/components/mediaViewer/SenderInfo.tsx index ae8c5d627..b2fc17cd8 100644 --- a/src/components/mediaViewer/SenderInfo.tsx +++ b/src/components/mediaViewer/SenderInfo.tsx @@ -18,7 +18,6 @@ import useLang from '../../hooks/useLang'; import useAppLayout from '../../hooks/useAppLayout'; import Avatar from '../common/Avatar'; -import UserAvatar from '../common/UserAvatar'; import './SenderInfo.scss'; @@ -80,7 +79,7 @@ const SenderInfo: FC = ({ return (
{isUserId(sender.id) ? ( - + ) : ( )} diff --git a/src/components/middle/ActionMessage.tsx b/src/components/middle/ActionMessage.tsx index df82c878a..df9f91ee4 100644 --- a/src/components/middle/ActionMessage.tsx +++ b/src/components/middle/ActionMessage.tsx @@ -2,7 +2,7 @@ import type { FC } from '../../lib/teact/teact'; import React, { memo, useEffect, useMemo, useRef, } from '../../lib/teact/teact'; -import { getActions, getGlobal, withGlobal } from '../../global'; +import { getActions, withGlobal } from '../../global'; import type { ApiUser, ApiMessage, ApiChat, ApiSticker, ApiTopic, @@ -53,6 +53,7 @@ type OwnProps = { }; type StateProps = { + usersById: Record; senderUser?: ApiUser; senderChat?: ApiChat; targetUserIds?: string[]; @@ -73,6 +74,7 @@ const ActionMessage: FC = ({ appearanceOrder = 0, isJustAdded, isLastInList, + usersById, senderUser, senderChat, targetUserIds, @@ -138,8 +140,6 @@ const ActionMessage: FC = ({ const { transitionClassNames } = useShowTransition(isShown, undefined, noAppearanceAnimation, false); - // No need for expensive global updates on users and chats, so we avoid them - const usersById = getGlobal().users.byId; const targetUsers = useMemo(() => { return targetUserIds ? targetUserIds.map((userId) => usersById?.[userId]).filter(Boolean) @@ -256,6 +256,7 @@ export default memo(withGlobal( chatId, senderId, replyToMessageId, content, } = message; + const { byId: usersById } = global.users; const userId = senderId; const { targetUserIds, targetChatId } = content.action || {}; const targetMessageId = replyToMessageId; @@ -277,6 +278,7 @@ export default memo(withGlobal( const topic = selectTopicFromMessage(global, message); return { + usersById, senderUser, senderChat, targetChatId, diff --git a/src/components/middle/ReactorListModal.tsx b/src/components/middle/ReactorListModal.tsx index c9b09018f..9da1daab1 100644 --- a/src/components/middle/ReactorListModal.tsx +++ b/src/components/middle/ReactorListModal.tsx @@ -5,6 +5,7 @@ import React, { import { getActions, getGlobal, withGlobal } from '../../global'; import type { ApiAvailableReaction, ApiMessage, ApiReaction } from '../../api/types'; +import type { AnimationLevel } from '../../types'; import { LoadMoreDirection } from '../../types'; import { selectChatMessage, selectTabState } from '../../global/selectors'; @@ -20,7 +21,7 @@ import useFlag from '../../hooks/useFlag'; import InfiniteScroll from '../ui/InfiniteScroll'; import Modal from '../ui/Modal'; import Button from '../ui/Button'; -import UserAvatar from '../common/UserAvatar'; +import Avatar from '../common/Avatar'; import ListItem from '../ui/ListItem'; import ReactionStaticEmoji from '../common/ReactionStaticEmoji'; import Loading from '../ui/Loading'; @@ -38,6 +39,7 @@ export type StateProps = Pick = ({ @@ -48,6 +50,7 @@ const ReactorListModal: FC = ({ messageId, seenByUserIds, availableReactions, + animationLevel, }) => { const { loadReactors, @@ -191,7 +194,7 @@ const ReactorListModal: FC = ({ // eslint-disable-next-line react/jsx-no-bind onClick={() => handleClick(userId)} > - + {r.reaction && ( ( reactors: message?.reactors, seenByUserIds: message?.seenByUserIds, availableReactions: global.availableReactions, + animationLevel: global.settings.byKey.animationLevel, }; }, )(ReactorListModal)); diff --git a/src/components/middle/composer/Composer.tsx b/src/components/middle/composer/Composer.tsx index 67c2a9312..6d746f551 100644 --- a/src/components/middle/composer/Composer.tsx +++ b/src/components/middle/composer/Composer.tsx @@ -24,7 +24,6 @@ import type { ApiBotMenuButton, ApiAttachMenuPeerType, ApiChatFullInfo, - ApiPhoto, } from '../../../api/types'; import type { InlineBotSettings, ISettings } from '../../../types'; @@ -63,7 +62,7 @@ import { selectTabState, selectTheme, selectUser, - selectUserFullInfo, selectUserPhotoFromFullInfo, + selectUserFullInfo, } from '../../../global/selectors'; import { getAllowedAttachmentOptions, @@ -190,7 +189,6 @@ type StateProps = chatBotCommands?: ApiBotCommand[]; sendAsUser?: ApiUser; sendAsChat?: ApiChat; - sendAsUserProfilePhoto?: ApiPhoto; sendAsId?: string; editingDraft?: ApiFormattedText; requestedDraftText?: string; @@ -277,7 +275,6 @@ const Composer: FC = ({ chatBotCommands, sendAsUser, sendAsChat, - sendAsUserProfilePhoto, sendAsId, editingDraft, replyingToId, @@ -1373,7 +1370,6 @@ const Composer: FC = ({ @@ -1586,7 +1582,6 @@ export default memo(withGlobal( ); const sendAsUser = sendAsId ? selectUser(global, sendAsId) : undefined; const sendAsChat = !sendAsUser && sendAsId ? selectChat(global, sendAsId) : undefined; - const sendAsUserProfilePhoto = sendAsUser ? selectUserPhotoFromFullInfo(global, sendAsUser.id) : undefined; const requestedDraftText = selectRequestedDraftText(global, chatId); const requestedDraftFiles = selectRequestedDraftFiles(global, chatId); const currentMessageList = selectCurrentMessageList(global); @@ -1647,7 +1642,6 @@ export default memo(withGlobal( botMenuButton: chatBotFullInfo?.botInfo?.menuButton, sendAsUser, sendAsChat, - sendAsUserProfilePhoto, sendAsId, editingDraft, requestedDraftText, diff --git a/src/components/middle/composer/SendAsMenu.tsx b/src/components/middle/composer/SendAsMenu.tsx index 649fb78e9..251e52e7f 100644 --- a/src/components/middle/composer/SendAsMenu.tsx +++ b/src/components/middle/composer/SendAsMenu.tsx @@ -16,7 +16,6 @@ import useLang from '../../../hooks/useLang'; import ListItem from '../../ui/ListItem'; import Avatar from '../../common/Avatar'; -import UserAvatar from '../../common/UserAvatar'; import Menu from '../../ui/Menu'; import FullNameTitle from '../../common/FullNameTitle'; @@ -127,19 +126,12 @@ const SendAsMenu: FC = ({ rightElement={!isCurrentUserPremium && isPremium && } > - {user ? ( - - ) : ( - - )} +
{userOrChat && } {user diff --git a/src/components/middle/message/CommentButton.tsx b/src/components/middle/message/CommentButton.tsx index 0b6d5dac2..ffc855e75 100644 --- a/src/components/middle/message/CommentButton.tsx +++ b/src/components/middle/message/CommentButton.tsx @@ -9,7 +9,6 @@ import type { import { isUserId } from '../../../global/helpers'; import { formatIntegerCompact } from '../../../util/textFormat'; import buildClassName from '../../../util/buildClassName'; -import { selectUserPhotoFromFullInfo } from '../../../global/selectors'; import useLang from '../../../hooks/useLang'; import Avatar from '../../common/Avatar'; @@ -63,7 +62,6 @@ const CommentButton: FC = ({ key={user.id} size="small" user={isUserId(user.id) ? user as ApiUser : undefined} - userProfilePhoto={isUserId(user.id) ? selectUserPhotoFromFullInfo(getGlobal(), user.id) : undefined} chat={!isUserId(user.id) ? user as ApiChat : undefined} /> ))} diff --git a/src/components/middle/message/Contact.tsx b/src/components/middle/message/Contact.tsx index 847e610d1..7d988fa33 100644 --- a/src/components/middle/message/Contact.tsx +++ b/src/components/middle/message/Contact.tsx @@ -2,12 +2,10 @@ import type { FC } from '../../../lib/teact/teact'; import React, { useCallback } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; -import type { - ApiUser, ApiContact, ApiCountryCode, ApiPhoto, -} from '../../../api/types'; +import type { ApiUser, ApiContact, ApiCountryCode } from '../../../api/types'; import type { AnimationLevel } from '../../../types'; -import { selectUser, selectUserPhotoFromFullInfo } from '../../../global/selectors'; +import { selectUser } from '../../../global/selectors'; import { formatPhoneNumberWithCode } from '../../../util/phoneNumber'; import buildClassName from '../../../util/buildClassName'; @@ -21,7 +19,6 @@ type OwnProps = { type StateProps = { user?: ApiUser; - userProfilePhoto?: ApiPhoto; phoneCodeList: ApiCountryCode[]; animationLevel: AnimationLevel; }; @@ -29,7 +26,7 @@ type StateProps = { const UNREGISTERED_CONTACT_ID = '0'; const Contact: FC = ({ - contact, user, userProfilePhoto, phoneCodeList, animationLevel, + contact, user, phoneCodeList, animationLevel, }) => { const { openChat } = getActions(); @@ -53,7 +50,6 @@ const Contact: FC = ({ ( (global, { contact }): StateProps => { const { countryList: { phoneCodes: phoneCodeList } } = global; const user = selectUser(global, contact.userId); - const userProfilePhoto = user ? selectUserPhotoFromFullInfo(global, user.id) : undefined; return { user, - userProfilePhoto, phoneCodeList, animationLevel: global.settings.byKey.animationLevel, }; diff --git a/src/components/middle/message/Location.tsx b/src/components/middle/message/Location.tsx index 257cb90c3..8ced4fd01 100644 --- a/src/components/middle/message/Location.tsx +++ b/src/components/middle/message/Location.tsx @@ -5,9 +5,7 @@ import { requestMutation } from '../../../lib/fasterdom/fasterdom'; import { getActions } from '../../../global'; import type { FC } from '../../../lib/teact/teact'; -import type { - ApiChat, ApiMessage, ApiPhoto, ApiUser, -} from '../../../api/types'; +import type { ApiChat, ApiMessage, ApiUser } from '../../../api/types'; import type { ISettings } from '../../../types'; import { CUSTOM_APPENDIX_ATTRIBUTE, MESSAGE_CONTENT_SELECTOR } from '../../../config'; @@ -55,7 +53,6 @@ const SVG_PIN = { __html: ' + {location.heading !== undefined && (
)} diff --git a/src/components/middle/message/Message.tsx b/src/components/middle/message/Message.tsx index 51b9d3c79..c96db8cfd 100644 --- a/src/components/middle/message/Message.tsx +++ b/src/components/middle/message/Message.tsx @@ -24,7 +24,6 @@ import type { ApiTopic, ApiReaction, ApiStickerSet, - ApiPhoto, } from '../../../api/types'; import type { AnimationLevel, FocusDirection, IAlbum, ISettings, @@ -70,7 +69,6 @@ import { selectChatTranslations, selectRequestedTranslationLanguage, selectChatFullInfo, - selectUserPhotoFromFullInfo, } from '../../../global/selectors'; import { getMessageContent, @@ -203,8 +201,6 @@ type StateProps = { canShowSender: boolean; originSender?: ApiUser | ApiChat; botSender?: ApiUser; - senderUserProfilePhoto?: ApiPhoto; - originSenderUserProfilePhoto?: ApiPhoto; isThreadTop?: boolean; shouldHideReply?: boolean; replyMessage?: ApiMessage; @@ -313,8 +309,6 @@ const Message: FC = ({ canShowSender, originSender, botSender, - senderUserProfilePhoto, - originSenderUserProfilePhoto, isThreadTop, shouldHideReply, replyMessage, @@ -487,7 +481,6 @@ const Message: FC = ({ const shouldPreferOriginSender = forwardInfo && (isChatWithSelf || isRepliesChat || !messageSender); const avatarPeer = shouldPreferOriginSender ? originSender : messageSender; const senderPeer = forwardInfo ? originSender : messageSender; - const avatarUserProfilePhoto = shouldPreferOriginSender ? originSenderUserProfilePhoto : senderUserProfilePhoto; const { handleMouseDown, @@ -790,7 +783,6 @@ const Message: FC = ({ user={avatarUser} chat={avatarChat} text={hiddenName} - userProfilePhoto={avatarUserProfilePhoto} lastSyncTime={lastSyncTime} onClick={(avatarUser || avatarChat) ? handleAvatarClick : undefined} observeIntersection={observeIntersectionForLoading} @@ -1137,7 +1129,6 @@ const Message: FC = ({ isSelected={isSelected} theme={theme} peer={sender} - peerProfilePhoto={senderUserProfilePhoto} /> )}
@@ -1373,10 +1364,6 @@ export default memo(withGlobal( const senderAdminMember = sender?.id && isGroup ? chatFullInfo?.adminMembersById?.[sender?.id] : undefined; - const senderUserProfilePhoto = canShowSender && sender && isUserId(sender.id) - ? selectUserPhotoFromFullInfo(global, sender.id) : undefined; - const originSenderUserProfilePhoto = originSender && isUserId(originSender.id) - ? selectUserPhotoFromFullInfo(global, originSender.id) : undefined; const threadTopMessageId = threadId ? selectThreadTopMessageId(global, chatId, threadId) : undefined; const isThreadTop = message.id === threadTopMessageId; @@ -1443,8 +1430,6 @@ export default memo(withGlobal( canShowSender, originSender, botSender, - senderUserProfilePhoto, - originSenderUserProfilePhoto, shouldHideReply: shouldHideReply || isReplyToTopicStart, isThreadTop, replyMessage, diff --git a/src/components/middle/message/MessageContextMenu.tsx b/src/components/middle/message/MessageContextMenu.tsx index a87a9cfb8..fb758ece0 100644 --- a/src/components/middle/message/MessageContextMenu.tsx +++ b/src/components/middle/message/MessageContextMenu.tsx @@ -1,7 +1,7 @@ import React, { memo, useCallback, useEffect, useRef, } from '../../../lib/teact/teact'; -import { getActions, getGlobal } from '../../../global'; +import { getActions } from '../../../global'; import type { FC } from '../../../lib/teact/teact'; import type { @@ -21,7 +21,6 @@ import { getMessageCopyOptions } from './helpers/copyOptions'; import { disableScrolling, enableScrolling } from '../../../util/scrollLock'; import { getUserFullName } from '../../../global/helpers'; import buildClassName from '../../../util/buildClassName'; -import { selectUserPhotoFromFullInfo } from '../../../global/selectors'; import renderText from '../../common/helpers/renderText'; import useFlag from '../../../hooks/useFlag'; @@ -406,7 +405,6 @@ const MessageContextMenu: FC = ({ ))}
diff --git a/src/components/middle/message/Poll.tsx b/src/components/middle/message/Poll.tsx index 0dbbcbe54..64ef4fb78 100644 --- a/src/components/middle/message/Poll.tsx +++ b/src/components/middle/message/Poll.tsx @@ -7,7 +7,7 @@ import React, { useMemo, useRef, } from '../../../lib/teact/teact'; -import { getActions, getGlobal, withGlobal } from '../../../global'; +import { getActions, withGlobal } from '../../../global'; import type { ApiMessage, ApiPoll, ApiUser, ApiPollAnswer, @@ -19,7 +19,6 @@ import { formatMediaDuration } from '../../../util/dateFormat'; import type { LangFn } from '../../../hooks/useLang'; import useLang from '../../../hooks/useLang'; import { getServerTimeOffset } from '../../../util/serverTime'; -import { selectUserPhotoFromFullInfo } from '../../../global/selectors'; import CheckboxGroup from '../../ui/CheckboxGroup'; import RadioGroup from '../../ui/RadioGroup'; @@ -235,7 +234,6 @@ const Poll: FC = ({ key={user.id} size="micro" user={user} - userProfilePhoto={selectUserPhotoFromFullInfo(getGlobal(), user.id)} /> ))}
diff --git a/src/components/middle/message/ReactionButton.tsx b/src/components/middle/message/ReactionButton.tsx index c464f6b6c..a3555adbc 100644 --- a/src/components/middle/message/ReactionButton.tsx +++ b/src/components/middle/message/ReactionButton.tsx @@ -11,7 +11,6 @@ import type { ActiveReaction } from '../../../global/types'; import buildClassName from '../../../util/buildClassName'; import { formatIntegerCompact } from '../../../util/textFormat'; import { isSameReaction, isReactionChosen } from '../../../global/helpers'; -import { selectUserPhotoFromFullInfo } from '../../../global/selectors'; import Button from '../../ui/Button'; import Avatar from '../../common/Avatar'; @@ -81,7 +80,6 @@ const ReactionButton: FC<{ ))} diff --git a/src/components/right/RightSearch.tsx b/src/components/right/RightSearch.tsx index 8c54f59a1..9a289c82b 100644 --- a/src/components/right/RightSearch.tsx +++ b/src/components/right/RightSearch.tsx @@ -4,9 +4,7 @@ import React, { import { getActions, getGlobal, withGlobal } from '../../global'; import type { FC } from '../../lib/teact/teact'; -import type { - ApiMessage, ApiUser, ApiChat, ApiPhoto, -} from '../../api/types'; +import type { ApiMessage, ApiUser, ApiChat } from '../../api/types'; import type { AnimationLevel } from '../../types'; import { MEMO_EMPTY_ARRAY } from '../../util/memo'; @@ -15,11 +13,8 @@ import { selectChatMessages, selectChat, selectCurrentTextSearch, - selectUserPhotoFromFullInfo, } from '../../global/selectors'; -import { - isChatChannel, -} from '../../global/helpers'; +import { isChatChannel } from '../../global/helpers'; import { disableDirectTextInput, enableDirectTextInput } from '../../util/directInputManager'; import { renderMessageSummary } from '../common/helpers/renderMessageText'; import useLang from '../../hooks/useLang'; @@ -105,7 +100,6 @@ const RightSearch: FC = ({ } const senderUser = message.senderId ? selectUser(getGlobal(), message.senderId) : undefined; - const senderUserProfilePhoto = senderUser ? selectUserPhotoFromFullInfo(getGlobal(), senderUser.id) : undefined; let senderChat; if (chat && isChatChannel(chat)) { @@ -120,7 +114,6 @@ const RightSearch: FC = ({ return { message, senderUser, - senderUserProfilePhoto, senderChat, onClick: () => focusMessage({ chatId, threadId, messageId: id }), }; @@ -135,12 +128,11 @@ const RightSearch: FC = ({ }, '.ListItem-button', true); const renderSearchResult = ({ - message, senderUser, senderChat, senderUserProfilePhoto, onClick, + message, senderUser, senderChat, onClick, }: { message: ApiMessage; senderUser?: ApiUser; senderChat?: ApiChat; - senderUserProfilePhoto?: ApiPhoto; onClick: NoneToVoidFunction; }) => { const text = renderMessageSummary(lang, message, undefined, query); @@ -155,7 +147,6 @@ const RightSearch: FC = ({ diff --git a/src/components/right/management/JoinRequest.tsx b/src/components/right/management/JoinRequest.tsx index 147ea009e..844e69eb8 100644 --- a/src/components/right/management/JoinRequest.tsx +++ b/src/components/right/management/JoinRequest.tsx @@ -3,11 +3,11 @@ import React, { memo, useCallback } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { AnimationLevel } from '../../../types'; -import type { ApiPhoto, ApiUser } from '../../../api/types'; +import type { ApiUser } from '../../../api/types'; import useLang from '../../../hooks/useLang'; import { getUserFullName } from '../../../global/helpers'; -import { selectUser, selectUserPhotoFromFullInfo } from '../../../global/selectors'; +import { selectUser } from '../../../global/selectors'; import { formatHumanDate, formatTime, isToday } from '../../../util/dateFormat'; import { getServerTime } from '../../../util/serverTime'; import { createClassNameBuilder } from '../../../util/buildClassName'; @@ -27,7 +27,6 @@ type OwnProps = { type StateProps = { user?: ApiUser; - userProfilePhoto?: ApiPhoto; isSavedMessages?: boolean; animationLevel: AnimationLevel; }; @@ -39,7 +38,6 @@ const JoinRequest: FC = ({ date, isChannel, user, - userProfilePhoto, animationLevel, }) => { const { openChat, hideChatJoinRequest } = getActions(); @@ -73,7 +71,6 @@ const JoinRequest: FC = ({ key={userId} size="medium" user={user} - userProfilePhoto={userProfilePhoto} animationLevel={animationLevel} withVideo /> @@ -102,7 +99,6 @@ export default memo(withGlobal( return { user, - userProfilePhoto: user ? selectUserPhotoFromFullInfo(global, userId) : undefined, animationLevel: global.settings.byKey.animationLevel, }; }, diff --git a/src/components/right/management/ManageUser.tsx b/src/components/right/management/ManageUser.tsx index c0bba9f9a..66fd0fff1 100644 --- a/src/components/right/management/ManageUser.tsx +++ b/src/components/right/management/ManageUser.tsx @@ -16,7 +16,6 @@ import { selectTabState, selectUser, selectUserFullInfo, - selectUserPhotoFromFullInfo, } from '../../../global/selectors'; import { isUserBot, selectIsChatMuted } from '../../../global/helpers'; import useFlag from '../../../hooks/useFlag'; @@ -43,7 +42,6 @@ type OwnProps = { type StateProps = { user?: ApiUser; - userProfilePhoto?: ApiPhoto; progress?: ManagementProgress; isMuted?: boolean; personalPhoto?: ApiPhoto; @@ -55,7 +53,6 @@ const ERROR_FIRST_NAME_MISSING = 'Please provide first name'; const ManageUser: FC = ({ userId, user, - userProfilePhoto, progress, isMuted, onClose, @@ -233,7 +230,6 @@ const ManageUser: FC = ({ photo={notPersonalPhoto} noPersonalPhoto user={user} - userProfilePhoto={userProfilePhoto} size="mini" className="personal-photo" /> @@ -298,10 +294,9 @@ export default memo(withGlobal( const isMuted = chat && selectIsChatMuted(chat, selectNotifySettings(global), selectNotifyExceptions(global)); const personalPhoto = userFullInfo?.personalPhoto; const notPersonalPhoto = userFullInfo?.profilePhoto || userFullInfo?.fallbackPhoto; - const userProfilePhoto = user ? selectUserPhotoFromFullInfo(global, user.id) : undefined; return { - user, progress, isMuted, personalPhoto, notPersonalPhoto, userProfilePhoto, + user, progress, isMuted, personalPhoto, notPersonalPhoto, }; }, )(ManageUser)); diff --git a/src/global/helpers/chats.ts b/src/global/helpers/chats.ts index 2f6265ba7..06d06879f 100644 --- a/src/global/helpers/chats.ts +++ b/src/global/helpers/chats.ts @@ -5,7 +5,6 @@ import type { ApiChatAdminRights, ApiChatFolder, ApiTopic, - ApiPhoto, } from '../../api/types'; import { MAIN_THREAD_ID, @@ -21,7 +20,6 @@ import { orderBy } from '../../util/iteratees'; import { getUserFirstOrLastName } from './users'; import { formatDateToString, formatTime } from '../../util/dateFormat'; import { prepareSearchWordsForNeedle } from '../../util/searchWords'; -import { getVideoAvatarMediaHash } from './media'; const FOREVER_BANNED_DATE = Date.now() / 1000 + 31622400; // 366 days @@ -109,18 +107,12 @@ export function getTopicLink(chatId: string, chatUsername?: string, topicId?: nu export function getChatAvatarHash( owner: ApiChat | ApiUser, size: 'normal' | 'big' = 'normal', - type: 'photo' | 'video' = 'photo', avatarHash = owner.avatarHash, - profilePhoto?: ApiPhoto, ) { if (!avatarHash) { return undefined; } - if (type === 'video') { - return profilePhoto?.isVideo ? getVideoAvatarMediaHash(profilePhoto) : undefined; - } - switch (size) { case 'big': return `profile${owner.id}?${avatarHash}`; diff --git a/src/global/selectors/users.ts b/src/global/selectors/users.ts index 75f32262d..c182b4dbb 100644 --- a/src/global/selectors/users.ts +++ b/src/global/selectors/users.ts @@ -16,12 +16,6 @@ export function selectUserFullInfo(global: T, userId: str return global.users.fullInfoById[userId]; } -export function selectUserPhotoFromFullInfo(global: T, userId: string) { - const fullInfo = selectUserFullInfo(global, userId); - - return fullInfo?.personalPhoto || fullInfo?.profilePhoto || fullInfo?.fallbackPhoto; -} - export function selectIsUserBlocked(global: T, userId: string) { return selectUserFullInfo(global, userId)?.isBlocked; } @@ -36,14 +30,6 @@ export function selectIsPremiumPurchaseBlocked(global: T) return global.appConfig?.isPremiumPurchaseBlocked ?? true; } -// Slow, not to be used in `withGlobal` -export function selectUserByUsername(global: T, username: string) { - const usernameLowered = username.toLowerCase(); - return Object.values(global.users.byId).find( - (user) => user.usernames?.some((u) => u.username.toLowerCase() === usernameLowered), - ); -} - // Slow, not to be used in `withGlobal` export function selectUserByPhoneNumber(global: T, phoneNumber: string) { const phoneNumberCleaned = phoneNumber.replace(/[^0-9]/g, '');