Suggested Avatar: Fix opening avatar for second time not working (#3082)

This commit is contained in:
Alexander Zinchuk 2023-04-26 21:15:27 +04:00
parent f13d0218d8
commit 01bd8f8b5b
2 changed files with 28 additions and 21 deletions

View File

@ -1,6 +1,6 @@
import type { FC } from '../../lib/teact/teact'; import type { FC } from '../../lib/teact/teact';
import React, { import React, {
memo, useEffect, useMemo, useRef, memo, useCallback, useEffect, useMemo, useRef,
} from '../../lib/teact/teact'; } from '../../lib/teact/teact';
import { getActions, getGlobal, withGlobal } from '../../global'; import { getActions, getGlobal, withGlobal } from '../../global';
@ -149,19 +149,26 @@ const ActionMessage: FC<OwnProps & StateProps> = ({
: undefined; : undefined;
}, [targetUserIds, usersById]); }, [targetUserIds, usersById]);
const content = renderActionMessageText( const renderContent = useCallback(() => {
lang, return renderActionMessageText(
message, lang,
senderUser, message,
senderChat, senderUser,
targetUsers, senderChat,
targetMessage, targetUsers,
targetChatId, targetMessage,
topic, targetChatId,
{ isEmbedded }, topic,
observeIntersectionForLoading, { isEmbedded },
observeIntersectionForPlaying, observeIntersectionForLoading,
); observeIntersectionForPlaying,
);
},
[
isEmbedded, lang, message, observeIntersectionForLoading, observeIntersectionForPlaying, senderChat,
senderUser, targetChatId, targetMessage, targetUsers, topic,
]);
const { const {
isContextMenuOpen, contextMenuPosition, isContextMenuOpen, contextMenuPosition,
handleBeforeContextMenu, handleContextMenu, handleBeforeContextMenu, handleContextMenu,
@ -190,7 +197,7 @@ const ActionMessage: FC<OwnProps & StateProps> = ({
} }
if (isEmbedded) { if (isEmbedded) {
return <span ref={ref} className="embedded-action-message">{content}</span>; return <span ref={ref} className="embedded-action-message">{renderContent()}</span>;
} }
function renderGift() { function renderGift() {
@ -231,12 +238,12 @@ const ActionMessage: FC<OwnProps & StateProps> = ({
onMouseDown={handleMouseDown} onMouseDown={handleMouseDown}
onContextMenu={handleContextMenu} onContextMenu={handleContextMenu}
> >
{!isSuggestedAvatar && <span className="action-message-content">{content}</span>} {!isSuggestedAvatar && <span className="action-message-content">{renderContent()}</span>}
{isGift && renderGift()} {isGift && renderGift()}
{isSuggestedAvatar && ( {isSuggestedAvatar && (
<ActionMessageSuggestedAvatar <ActionMessageSuggestedAvatar
message={message} message={message}
content={content} renderContent={renderContent}
/> />
)} )}
{contextMenuPosition && ( {contextMenuPosition && (

View File

@ -19,12 +19,12 @@ import ConfirmDialog from '../ui/ConfirmDialog';
type OwnProps = { type OwnProps = {
message: ApiMessage; message: ApiMessage;
content?: TextPart; renderContent: () => TextPart | undefined;
}; };
const ActionMessageSuggestedAvatar: FC<OwnProps> = ({ const ActionMessageSuggestedAvatar: FC<OwnProps> = ({
message, message,
content, renderContent,
}) => { }) => {
const { const {
openMediaViewer, uploadProfilePhoto, showNotification, openMediaViewer, uploadProfilePhoto, showNotification,
@ -102,7 +102,7 @@ const ActionMessageSuggestedAvatar: FC<OwnProps> = ({
withVideo={isVideo} withVideo={isVideo}
size="jumbo" size="jumbo"
/> />
<span>{content}</span> <span>{renderContent()}</span>
<span className="action-message-button">{lang(isVideo ? 'ViewVideoAction' : 'ViewPhotoAction')}</span> <span className="action-message-button">{lang(isVideo ? 'ViewVideoAction' : 'ViewPhotoAction')}</span>
<CropModal <CropModal
@ -115,7 +115,7 @@ const ActionMessageSuggestedAvatar: FC<OwnProps> = ({
title={lang('SuggestedVideo')} title={lang('SuggestedVideo')}
confirmHandler={handleSetVideo} confirmHandler={handleSetVideo}
onClose={closeVideoModal} onClose={closeVideoModal}
textParts={content} textParts={renderContent()}
/> />
</span> </span>
); );