From 905124fe96cb710a28c3aee7c5bfa24b226f16c9 Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Fri, 21 Mar 2025 14:02:23 +0400 Subject: [PATCH] Unique Gift: Fix displayed sender (#5743) --- src/components/middle/message/actions/StarGift.tsx | 4 +++- src/components/middle/message/actions/StarGiftUnique.tsx | 9 ++++++--- src/components/modals/gift/info/GiftInfoModal.tsx | 5 +++-- src/global/selectors/messages.ts | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/components/middle/message/actions/StarGift.tsx b/src/components/middle/message/actions/StarGift.tsx index 9b95fba1b..3f76f324c 100644 --- a/src/components/middle/message/actions/StarGift.tsx +++ b/src/components/middle/message/actions/StarGift.tsx @@ -10,6 +10,7 @@ import { selectCanPlayAnimatedEmojis, selectPeer, selectSender, + selectUser, } from '../../../../global/selectors'; import buildClassName from '../../../../util/buildClassName'; import { formatStarsAsText } from '../../../../util/localization/format'; @@ -175,10 +176,11 @@ const StarGiftAction = ({ export default memo(withGlobal( (global, { message, action }): StateProps => { + const currentUser = selectUser(global, global.currentUserId!); const canPlayAnimatedEmojis = selectCanPlayAnimatedEmojis(global); const messageSender = selectSender(global, message); const giftSender = action.fromId ? selectPeer(global, action.fromId) : undefined; - const messageRecipient = selectPeer(global, message.chatId); + const messageRecipient = message.isOutgoing ? selectPeer(global, message.chatId) : currentUser; const giftRecipient = action.peerId ? selectPeer(global, action.peerId) : undefined; return { diff --git a/src/components/middle/message/actions/StarGiftUnique.tsx b/src/components/middle/message/actions/StarGiftUnique.tsx index d80058de7..1a9d31f6f 100644 --- a/src/components/middle/message/actions/StarGiftUnique.tsx +++ b/src/components/middle/message/actions/StarGiftUnique.tsx @@ -9,6 +9,7 @@ import { selectCanPlayAnimatedEmojis, selectPeer, selectSender, + selectUser, } from '../../../../global/selectors'; import buildClassName from '../../../../util/buildClassName'; import buildStyle from '../../../../util/buildStyle'; @@ -72,7 +73,8 @@ const StarGiftAction = ({ [lang('ActionStarGiftUniqueSymbol'), pattern.name], ], [lang, model, pattern, backdrop]); - const peer = isOutgoing ? recipient : sender; + const shouldShowFrom = !isOutgoing || action.isUpgrade; + const peer = shouldShowFrom && !action.isUpgrade ? sender : recipient; const fallbackPeerTitle = lang('ActionFallbackSomeone'); const peerTitle = peer && getPeerTitle(lang, peer); @@ -117,7 +119,7 @@ const StarGiftAction = ({

{isSelf ? lang('ActionStarGiftSelf') : lang( - isOutgoing ? 'ActionStarGiftTo' : 'ActionStarGiftFrom', + shouldShowFrom ? 'ActionStarGiftFrom' : 'ActionStarGiftTo', { peer: renderPeerLink(peer?.id, peerTitle || fallbackPeerTitle), }, @@ -144,10 +146,11 @@ const StarGiftAction = ({ export default memo(withGlobal( (global, { message, action }): StateProps => { + const currentUser = selectUser(global, global.currentUserId!); const canPlayAnimatedEmojis = selectCanPlayAnimatedEmojis(global); const messageSender = selectSender(global, message); const giftSender = action.fromId ? selectPeer(global, action.fromId) : undefined; - const messageRecipient = selectPeer(global, message.chatId); + const messageRecipient = message.isOutgoing ? selectPeer(global, message.chatId) : currentUser; const giftRecipient = action.peerId ? selectPeer(global, action.peerId) : undefined; return { diff --git a/src/components/modals/gift/info/GiftInfoModal.tsx b/src/components/modals/gift/info/GiftInfoModal.tsx index 5ea3a3a4d..44833407b 100644 --- a/src/components/modals/gift/info/GiftInfoModal.tsx +++ b/src/components/modals/gift/info/GiftInfoModal.tsx @@ -172,9 +172,10 @@ const GiftInfoModal = ({ }); const handleFocusUpgraded = useLastCallback(() => { - if (!savedGift?.upgradeMsgId || !renderingTargetPeer) return; + const giftChat = isSender ? renderingTargetPeer : renderingFromPeer; + if (!savedGift?.upgradeMsgId || !giftChat) return; const { upgradeMsgId } = savedGift; - focusMessage({ chatId: renderingTargetPeer.id, messageId: upgradeMsgId! }); + focusMessage({ chatId: giftChat.id, messageId: upgradeMsgId! }); handleClose(); }); diff --git a/src/global/selectors/messages.ts b/src/global/selectors/messages.ts index 4656b8d63..5a100a536 100644 --- a/src/global/selectors/messages.ts +++ b/src/global/selectors/messages.ts @@ -400,8 +400,9 @@ export function selectOutgoingStatus( export function selectSender(global: T, message: ApiMessage): ApiPeer | undefined { const { senderId } = message; const chat = selectChat(global, message.chatId); + const currentUser = selectUser(global, global.currentUserId!); if (!senderId) { - return chat; + return message.isOutgoing ? currentUser : chat; } if (chat && isChatChannel(chat) && !chat.areProfilesShown) return chat;