[Refactoring] Message: Simplify asForwarded logic

This commit is contained in:
Alexander Zinchuk 2022-01-13 01:11:47 +01:00
parent 7f74b8cd99
commit 392aee6c84
2 changed files with 10 additions and 6 deletions

View File

@ -274,20 +274,24 @@ const Message: FC<OwnProps & StateProps> = ({
const isScheduled = messageListType === 'scheduled' || message.isScheduled; const isScheduled = messageListType === 'scheduled' || message.isScheduled;
const hasReply = isReplyMessage(message) && !shouldHideReply; const hasReply = isReplyMessage(message) && !shouldHideReply;
const hasThread = Boolean(threadInfo) && messageListType === 'thread'; const hasThread = Boolean(threadInfo) && messageListType === 'thread';
const customShape = getMessageCustomShape(message);
const { forwardInfo, viaBotId } = message; const { forwardInfo, viaBotId } = message;
const asForwarded = ( const asForwarded = (
forwardInfo && (!isChatWithSelf || isScheduled) && !isRepliesChat && !forwardInfo.isLinkedChannelPost forwardInfo
&& (!isChatWithSelf || isScheduled)
&& !isRepliesChat
&& !forwardInfo.isLinkedChannelPost
&& !customShape
); );
const isInDocumentGroup = Boolean(message.groupedId) && !message.isInAlbum; const isInDocumentGroup = Boolean(message.groupedId) && !message.isInAlbum;
const isAlbum = Boolean(album) && album!.messages.length > 1; const isAlbum = Boolean(album) && album!.messages.length > 1;
const { const {
text, photo, video, audio, voice, document, sticker, contact, poll, webPage, invoice, text, photo, video, audio, voice, document, sticker, contact, poll, webPage, invoice,
} = getMessageContent(message); } = getMessageContent(message);
const customShape = getMessageCustomShape(message);
const textParts = renderMessageText(message, highlight, isEmojiOnlyMessage(customShape)); const textParts = renderMessageText(message, highlight, isEmojiOnlyMessage(customShape));
const isContextMenuShown = contextMenuPosition !== undefined; const isContextMenuShown = contextMenuPosition !== undefined;
const signature = ( const signature = (
(isChannel && message.adminTitle) || (forwardInfo && !asForwarded && forwardInfo.adminTitle) || undefined (isChannel && message.adminTitle) || (!asForwarded && forwardInfo?.adminTitle) || undefined
); );
const metaSafeAuthorWidth = useMemo(() => { const metaSafeAuthorWidth = useMemo(() => {
return signature ? calculateAuthorWidth(signature) : undefined; return signature ? calculateAuthorWidth(signature) : undefined;
@ -473,7 +477,7 @@ const Message: FC<OwnProps & StateProps> = ({
function renderContent() { function renderContent() {
const className = buildClassName( const className = buildClassName(
'content-inner', 'content-inner',
asForwarded && !customShape && 'forwarded-message', asForwarded && 'forwarded-message',
hasReply && 'reply-message', hasReply && 'reply-message',
noMediaCorners && 'no-media-corners', noMediaCorners && 'no-media-corners',
); );
@ -735,7 +739,7 @@ const Message: FC<OwnProps & StateProps> = ({
style={style} style={style}
dir="auto" dir="auto"
> >
{asForwarded && !customShape && (!isInDocumentGroup || isFirstInDocumentGroup) && ( {asForwarded && (!isInDocumentGroup || isFirstInDocumentGroup) && (
<div className="message-title">{lang('ForwardedMessage')}</div> <div className="message-title">{lang('ForwardedMessage')}</div>
)} )}
{renderContent()} {renderContent()}

View File

@ -77,7 +77,7 @@ export function buildContentClassName(
} }
} }
if (asForwarded && !customShape) { if (asForwarded) {
classNames.push('is-forwarded'); classNames.push('is-forwarded');
} }