Unique Gift: Fix displayed sender (#5743)

This commit is contained in:
zubiden 2025-03-21 14:02:23 +04:00 committed by Alexander Zinchuk
parent d43c0e8f1f
commit 905124fe96
4 changed files with 14 additions and 7 deletions

View File

@ -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<OwnProps>(
(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 {

View File

@ -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 = ({
<div className={styles.info}>
<h3 className={styles.title}>
{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<OwnProps>(
(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 {

View File

@ -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();
});

View File

@ -400,8 +400,9 @@ export function selectOutgoingStatus<T extends GlobalState>(
export function selectSender<T extends GlobalState>(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;