From 875609f0d8c8f54c2df00cee7d6e7081920af05e Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:43:34 +0200 Subject: [PATCH] Various fixes (#4955) --- src/components/common/DeleteMessageModal.tsx | 15 +++-- .../main/premium/PremiumGiftModal.module.scss | 2 +- .../main/premium/StarsGiftModal.module.scss | 2 +- .../StarsGiftingPickerModal.module.scss | 2 +- src/components/mediaViewer/MediaViewer.tsx | 2 +- .../middle/DeleteSelectedMessageModal.tsx | 12 ++-- src/components/middle/HeaderPinnedMessage.tsx | 2 +- .../middle/composer/BotKeyboardMenu.tsx | 2 +- src/components/middle/message/Game.tsx | 1 + .../middle/message/InlineButtons.tsx | 5 +- src/components/modals/ModalContainer.tsx | 2 +- .../stars/StarsBalanceModal.module.scss | 2 +- .../StarsTransactionModal.module.scss | 2 +- src/components/modals/webApp/WebAppModal.tsx | 1 + .../payment/ReceiptModal.module.scss | 2 +- src/components/ui/Modal.scss | 4 ++ src/components/ui/Modal.tsx | 3 + src/global/actions/api/bots.ts | 55 ++++++------------- src/global/actions/ui/misc.ts | 3 +- src/global/helpers/payments.ts | 2 +- src/global/selectors/messages.ts | 20 ++----- src/global/types.ts | 1 + src/styles/_variables.scss | 1 + 23 files changed, 66 insertions(+), 77 deletions(-) diff --git a/src/components/common/DeleteMessageModal.tsx b/src/components/common/DeleteMessageModal.tsx index 49ac3fcd3..09cd2edf3 100644 --- a/src/components/common/DeleteMessageModal.tsx +++ b/src/components/common/DeleteMessageModal.tsx @@ -25,10 +25,11 @@ import { selectAllowedMessageActionsSlow, selectBot, selectChat, selectChatFullInfo, selectCurrentMessageIds, - selectCurrentMessageList, selectSenderFromMessage, selectTabState, + selectCurrentMessageList, selectSender, selectSenderFromMessage, selectTabState, selectUser, } from '../../global/selectors'; import buildClassName from '../../util/buildClassName'; +import { MEMO_EMPTY_ARRAY } from '../../util/memo'; import renderText from './helpers/renderText'; import useLastCallback from '../../hooks/useLastCallback'; @@ -182,8 +183,9 @@ const DeleteMessageModal: FC = ({ }); const filterMessageIdByUserId = useLastCallback((userIds: string[], selectedMessageIdList: number[]) => { + if (!chat) return MEMO_EMPTY_ARRAY; return selectedMessageIdList.filter((msgId) => { - const senderPeer = selectSenderFromMessage(getGlobal(), chat, msgId); + const senderPeer = selectSenderFromMessage(getGlobal(), chat.id, msgId); return senderPeer && userIds.includes(senderPeer.id); }); }); @@ -220,6 +222,8 @@ const DeleteMessageModal: FC = ({ }); const handleDeleteMessageForSelf = useLastCallback(() => { + if (!chat) return; + onConfirm?.(); const messageIds = album?.messages ? album.messages.map(({ id }) => id) @@ -241,7 +245,7 @@ const DeleteMessageModal: FC = ({ if (chosenBanOption && !havePermissionChanged && message) { const filteredUserIdList = chosenBanOption.filter((userId) => messageIds?.some((msgId) => { - const senderPeer = selectSenderFromMessage(getGlobal(), chat, msgId); + const senderPeer = selectSenderFromMessage(getGlobal(), chat.id, msgId); return senderPeer && senderPeer.id === userId; })); handleDeleteMember(filteredUserIdList); @@ -253,7 +257,7 @@ const DeleteMessageModal: FC = ({ if (chosenBanOption && havePermissionChanged) { const filteredUserIdList = chosenBanOption.filter((userId) => messageIds?.some((msgId) => { - const senderPeer = selectSenderFromMessage(getGlobal(), chat, msgId); + const senderPeer = selectSenderFromMessage(getGlobal(), chat.id, msgId); return senderPeer && senderPeer.id === userId; })); handleUpdateChatMemberBannedRights(filteredUserIdList); @@ -439,8 +443,7 @@ export default memo(withGlobal( const messageIdList = chat && selectCurrentMessageIds(global, chat.id, threadId!, type!); const isGroup = Boolean(chat) && isChatBasicGroup(chat); const isSuperGroup = Boolean(chat) && isChatSuperGroup(chat); - const sender = deleteMessageModal && chat && deleteMessageModal.message - && selectSenderFromMessage(global, chat, deleteMessageModal.message.id); + const sender = deleteMessageModal?.message && selectSender(global, deleteMessageModal.message); const contactName = chat && isUserId(chat.id) ? getUserFirstOrLastName(selectUser(global, getPrivateChatUserId(chat)!)) : undefined; diff --git a/src/components/main/premium/PremiumGiftModal.module.scss b/src/components/main/premium/PremiumGiftModal.module.scss index 7b5f0ef14..c52fba33a 100644 --- a/src/components/main/premium/PremiumGiftModal.module.scss +++ b/src/components/main/premium/PremiumGiftModal.module.scss @@ -7,7 +7,7 @@ } .root { - z-index: calc(var(--z-media-viewer) - 1); + z-index: calc(var(--z-modal-low-priority) + 1); } .root :global(.modal-content) { diff --git a/src/components/main/premium/StarsGiftModal.module.scss b/src/components/main/premium/StarsGiftModal.module.scss index d280c1401..7f7880dbd 100644 --- a/src/components/main/premium/StarsGiftModal.module.scss +++ b/src/components/main/premium/StarsGiftModal.module.scss @@ -5,7 +5,7 @@ } .root { - z-index: calc(var(--z-media-viewer) - 1); + z-index: calc(var(--z-modal-low-priority) + 1); } .root :global(.modal-content) { diff --git a/src/components/main/premium/StarsGiftingPickerModal.module.scss b/src/components/main/premium/StarsGiftingPickerModal.module.scss index f98e17843..9a1fd0a91 100644 --- a/src/components/main/premium/StarsGiftingPickerModal.module.scss +++ b/src/components/main/premium/StarsGiftingPickerModal.module.scss @@ -1,5 +1,5 @@ .root { - z-index: calc(var(--z-media-viewer) - 1); + z-index: calc(var(--z-modal-low-priority) + 1); } .root :global(.modal-content) { diff --git a/src/components/mediaViewer/MediaViewer.tsx b/src/components/mediaViewer/MediaViewer.tsx index 583221957..f6b1fd4de 100644 --- a/src/components/mediaViewer/MediaViewer.tsx +++ b/src/components/mediaViewer/MediaViewer.tsx @@ -119,7 +119,7 @@ const MediaViewer = ({ /* Animation */ const animationKey = useRef(); - const senderId = message?.senderId || avatarOwner?.id; + const senderId = message?.senderId || avatarOwner?.id || message?.chatId; const prevSenderId = usePreviousDeprecated(senderId); const headerAnimation = withAnimation ? 'slideFade' : 'none'; const isGhostAnimation = Boolean(withAnimation && !shouldSkipHistoryAnimations); diff --git a/src/components/middle/DeleteSelectedMessageModal.tsx b/src/components/middle/DeleteSelectedMessageModal.tsx index d05732dcd..11edd5ed7 100644 --- a/src/components/middle/DeleteSelectedMessageModal.tsx +++ b/src/components/middle/DeleteSelectedMessageModal.tsx @@ -32,6 +32,7 @@ import { } from '../../global/selectors'; import buildClassName from '../../util/buildClassName'; import { buildCollectionByCallback } from '../../util/iteratees'; +import { MEMO_EMPTY_ARRAY } from '../../util/memo'; import renderText from '../common/helpers/renderText'; import useLang from '../../hooks/useLang'; @@ -219,8 +220,9 @@ const DeleteSelectedMessageModal: FC = ({ }); const filterMessageIdByUserId = useLastCallback((userIds: string[], selectedMessageIdList: number[]) => { + if (!chat) return MEMO_EMPTY_ARRAY; return selectedMessageIdList.filter((msgId) => { - const sender = selectSenderFromMessage(getGlobal(), chat, msgId); + const sender = selectSenderFromMessage(getGlobal(), chat.id, msgId); return sender && userIds.includes(sender.id); }); }); @@ -248,13 +250,15 @@ const DeleteSelectedMessageModal: FC = ({ }); const handleDeleteMessageForSelf = useLastCallback(() => { + if (!chat) return; + if (isSchedule) { deleteScheduledMessages({ messageIds: selectedMessageIds! }); } else if (!isSenderOwner && shouldShowOptions) { if (chosenSpanOption) { const userIdList = chosenSpanOption.filter((option) => !Number.isNaN(Number(option))); const filteredMessageIdList = filterMessageIdByUserId(userIdList, selectedMessageIds!); - if (filteredMessageIdList && filteredMessageIdList.length) { + if (filteredMessageIdList?.length) { reportMessages({ messageIds: filteredMessageIdList, reason: 'spam', description: '' }); } } @@ -268,7 +272,7 @@ const DeleteSelectedMessageModal: FC = ({ if (chosenBanOption && !havePermissionChanged) { const userIdList = chosenBanOption.filter((option) => !Number.isNaN(Number(option))); const filteredUserIdList = userIdList.filter((userId) => selectedMessageIds?.some((msgId) => { - const sender = selectSenderFromMessage(getGlobal(), chat, msgId); + const sender = selectSenderFromMessage(getGlobal(), chat.id, msgId); return sender && sender.id === userId; })); handleDeleteMember(filteredUserIdList); @@ -279,7 +283,7 @@ const DeleteSelectedMessageModal: FC = ({ if (chosenBanOption && havePermissionChanged) { const userIdList = chosenBanOption.filter((option) => !Number.isNaN(Number(option))); const filteredUserIdList = userIdList.filter((userId) => selectedMessageIds?.some((msgId) => { - const sender = selectSenderFromMessage(getGlobal(), chat, msgId); + const sender = selectSenderFromMessage(getGlobal(), chat.id, msgId); return sender && sender.id === userId; })); handleUpdateChatMemberBannedRights(filteredUserIdList); diff --git a/src/components/middle/HeaderPinnedMessage.tsx b/src/components/middle/HeaderPinnedMessage.tsx index 61e67df38..b24ef9052 100644 --- a/src/components/middle/HeaderPinnedMessage.tsx +++ b/src/components/middle/HeaderPinnedMessage.tsx @@ -77,7 +77,7 @@ const HeaderPinnedMessage: FC = ({ const handleInlineButtonClick = useLastCallback(() => { if (inlineButton) { - clickBotInlineButton({ messageId: message.id, button: inlineButton }); + clickBotInlineButton({ chatId: message.chatId, messageId: message.id, button: inlineButton }); } }); diff --git a/src/components/middle/composer/BotKeyboardMenu.tsx b/src/components/middle/composer/BotKeyboardMenu.tsx index 9198f9799..b9158e35e 100644 --- a/src/components/middle/composer/BotKeyboardMenu.tsx +++ b/src/components/middle/composer/BotKeyboardMenu.tsx @@ -70,7 +70,7 @@ const BotKeyboardMenu: FC = ({ ripple disabled={button.type === 'unsupported'} // eslint-disable-next-line react/jsx-no-bind - onClick={() => clickBotInlineButton({ messageId: message.id, button })} + onClick={() => clickBotInlineButton({ chatId: message.chatId, messageId: message.id, button })} > {buttonTexts?.[i][j]} diff --git a/src/components/middle/message/Game.tsx b/src/components/middle/message/Game.tsx index 10b354020..d6e4b5cfa 100644 --- a/src/components/middle/message/Game.tsx +++ b/src/components/middle/message/Game.tsx @@ -39,6 +39,7 @@ const Game: FC = ({ const handleGameClick = () => { clickBotInlineButton({ + chatId: message.chatId, messageId: message.id, button: message.inlineButtons![0][0], }); diff --git a/src/components/middle/message/InlineButtons.tsx b/src/components/middle/message/InlineButtons.tsx index cf5be9c5b..e985a1bf4 100644 --- a/src/components/middle/message/InlineButtons.tsx +++ b/src/components/middle/message/InlineButtons.tsx @@ -2,6 +2,7 @@ import type { FC, TeactNode } from '../../../lib/teact/teact'; import React, { memo, useMemo } from '../../../lib/teact/teact'; import type { ApiKeyboardButton, ApiMessage } from '../../../api/types'; +import type { ActionPayloads } from '../../../global/types'; import { RE_TME_LINK } from '../../../config'; import renderKeyboardButtonText from '../composer/helpers/renderKeyboardButtonText'; @@ -15,7 +16,7 @@ import './InlineButtons.scss'; type OwnProps = { message: ApiMessage; - onClick: ({ messageId, button }: { messageId: number; button: ApiKeyboardButton }) => void; + onClick: (payload: ActionPayloads['clickBotInlineButton']) => void; }; const InlineButtons: FC = ({ message, onClick }) => { @@ -62,7 +63,7 @@ const InlineButtons: FC = ({ message, onClick }) => { ripple disabled={button.type === 'unsupported'} // eslint-disable-next-line react/jsx-no-bind - onClick={() => onClick({ messageId: message.id, button })} + onClick={() => onClick({ chatId: message.chatId, messageId: message.id, button })} > {buttonTexts[i][j]} diff --git a/src/components/modals/ModalContainer.tsx b/src/components/modals/ModalContainer.tsx index b3d7ad449..22a0acfc6 100644 --- a/src/components/modals/ModalContainer.tsx +++ b/src/components/modals/ModalContainer.tsx @@ -52,6 +52,7 @@ type Entries = { }[keyof T][]; const MODALS: ModalRegistry = { + webApp: WebAppModal, giftCodeModal: GiftCodeModal, boostModal: BoostModal, chatlistModal: ChatlistModal, @@ -60,7 +61,6 @@ const MODALS: ModalRegistry = { inviteViaLinkModal: InviteViaLinkModal, requestedAttachBotInstall: AttachBotInstallModal, reportAdModal: ReportAdModal, - webApp: WebAppModal, collectibleInfoModal: CollectibleInfoModal, mapModal: MapModal, isStarPaymentModalOpen: StarsPaymentModal, diff --git a/src/components/modals/stars/StarsBalanceModal.module.scss b/src/components/modals/stars/StarsBalanceModal.module.scss index 309cbaa8b..a28662b77 100644 --- a/src/components/modals/stars/StarsBalanceModal.module.scss +++ b/src/components/modals/stars/StarsBalanceModal.module.scss @@ -1,7 +1,7 @@ @use '../../../styles/mixins'; .root { - z-index: calc(var(--z-media-viewer) - 1); + z-index: calc(var(--z-modal-low-priority) + 1); } .root :global(.modal-content) { diff --git a/src/components/modals/stars/transaction/StarsTransactionModal.module.scss b/src/components/modals/stars/transaction/StarsTransactionModal.module.scss index c92d4501b..38d2e8797 100644 --- a/src/components/modals/stars/transaction/StarsTransactionModal.module.scss +++ b/src/components/modals/stars/transaction/StarsTransactionModal.module.scss @@ -1,5 +1,5 @@ .modal { - z-index: calc(var(--z-media-viewer) - 1); + z-index: calc(var(--z-modal-low-priority) + 1); } .modal :global(.modal-dialog) { diff --git a/src/components/modals/webApp/WebAppModal.tsx b/src/components/modals/webApp/WebAppModal.tsx index bfa8e7cf7..cef7ac191 100644 --- a/src/components/modals/webApp/WebAppModal.tsx +++ b/src/components/modals/webApp/WebAppModal.tsx @@ -595,6 +595,7 @@ const WebAppModal: FC = ({ ; + isLowStackPriority?: boolean; onClose: () => void; onCloseAnimationEnd?: () => void; onEnter?: () => void; @@ -59,6 +60,7 @@ const Modal: FC = ({ noBackdropClose, children, style, + isLowStackPriority, onClose, onCloseAnimationEnd, onEnter, @@ -153,6 +155,7 @@ const Modal: FC = ({ className, noBackdrop && 'transparent-backdrop', isSlim && 'slim', + isLowStackPriority && 'low-priority', ); return ( diff --git a/src/global/actions/api/bots.ts b/src/global/actions/api/bots.ts index 46b9f73d1..99c672768 100644 --- a/src/global/actions/api/bots.ts +++ b/src/global/actions/api/bots.ts @@ -37,6 +37,7 @@ import { selectMessageReplyInfo, selectPeer, selectSendAs, + selectSender, selectTabState, selectUser, selectUserFullInfo, @@ -49,7 +50,14 @@ const runDebouncedForSearch = debounce((cb) => cb(), 500, false); let botFatherId: string | null; addActionHandler('clickBotInlineButton', (global, actions, payload): ActionReturnType => { - const { messageId, button, tabId = getCurrentTabId() } = payload; + const { + chatId, messageId, button, tabId = getCurrentTabId(), + } = payload; + const chat = selectChat(global, chatId); + const message = selectChatMessage(global, chatId, messageId); + if (!chat || !message) { + return; + } switch (button.type) { case 'command': @@ -61,11 +69,6 @@ addActionHandler('clickBotInlineButton', (global, actions, payload): ActionRetur break; } case 'callback': { - const chat = selectCurrentChat(global, tabId); - if (!chat) { - return; - } - void answerCallbackButton(global, actions, chat, messageId, button.data, undefined, tabId); break; } @@ -89,10 +92,6 @@ addActionHandler('clickBotInlineButton', (global, actions, payload): ActionRetur break; } case 'receipt': { - const chat = selectCurrentChat(global, tabId); - if (!chat) { - return; - } const { receiptMessageId } = button; actions.getReceipt({ chatId: chat.id, messageId: receiptMessageId, tabId, @@ -100,10 +99,6 @@ addActionHandler('clickBotInlineButton', (global, actions, payload): ActionRetur break; } case 'buy': { - const chat = selectCurrentChat(global, tabId); - if (!chat) { - return; - } actions.openInvoice({ type: 'message', chatId: chat.id, @@ -113,11 +108,6 @@ addActionHandler('clickBotInlineButton', (global, actions, payload): ActionRetur break; } case 'game': { - const chat = selectCurrentChat(global, tabId); - if (!chat) { - return; - } - void answerCallbackButton(global, actions, chat, messageId, undefined, true, tabId); break; } @@ -137,30 +127,22 @@ addActionHandler('clickBotInlineButton', (global, actions, payload): ActionRetur case 'simpleWebView': { const { url } = button; - const { chatId } = selectCurrentMessageList(global, tabId) || {}; - if (!chatId) { + const sender = selectSender(global, message); + if (!sender) { return; } - const message = selectChatMessage(global, chatId, messageId); - if (!message?.senderId) return; + const theme = extractCurrentThemeParams(); actions.requestSimpleWebView({ - url, botId: message?.senderId, theme, buttonText: button.text, tabId, + url, botId: sender.id, theme, buttonText: button.text, tabId, }); break; } case 'webView': { const { url } = button; - const chat = selectCurrentChat(global, tabId); - if (!chat) { - return; - } - const message = selectChatMessage(global, chat.id, messageId); - if (!message) { - return; - } - const botId = message.viaBotId || message.senderId; + const sender = selectSender(global, message); + const botId = message.viaBotId || sender?.id; if (!botId) { return; } @@ -177,10 +159,6 @@ addActionHandler('clickBotInlineButton', (global, actions, payload): ActionRetur } case 'urlAuth': { const { url } = button; - const chat = selectCurrentChat(global, tabId); - if (!chat) { - return; - } actions.requestBotUrlAuth({ chatId: chat.id, messageId, @@ -355,7 +333,8 @@ addActionHandler('switchBotInline', (global, actions, payload): ActionReturnType if (!message) { return undefined; } - botId = message.viaBotId || message.senderId; + const sender = selectSender(global, message); + botId = message.viaBotId || sender?.id; } if (!botId) { diff --git a/src/global/actions/ui/misc.ts b/src/global/actions/ui/misc.ts index 5ca10d0db..220f99a87 100644 --- a/src/global/actions/ui/misc.ts +++ b/src/global/actions/ui/misc.ts @@ -31,6 +31,7 @@ import { selectCurrentMessageList, selectIsCurrentUserPremium, selectIsTrustedBot, + selectSender, selectTabState, } from '../../selectors'; @@ -433,7 +434,7 @@ addActionHandler('openGame', (global, actions, payload): ActionReturnType => { const message = selectChatMessage(global, chatId, messageId); if (!message) return; - const botId = message.viaBotId || message.senderId; + const botId = message.viaBotId || selectSender(global, message)?.id; if (!botId) return; if (!selectIsTrustedBot(global, botId)) { diff --git a/src/global/helpers/payments.ts b/src/global/helpers/payments.ts index cfe0a59f4..10e9c00d7 100644 --- a/src/global/helpers/payments.ts +++ b/src/global/helpers/payments.ts @@ -200,7 +200,7 @@ export function getStarsTransactionFromGift(message: ApiMessage): ApiStarsTransa stars: stars!, peer: { type: 'peer', - id: message.isOutgoing ? message.chatId : message.senderId!, + id: message.isOutgoing ? message.chatId : (message.senderId || message.chatId), }, date: message.date, isGift: true, diff --git a/src/global/selectors/messages.ts b/src/global/selectors/messages.ts index 27e1c8a54..226f7e9da 100644 --- a/src/global/selectors/messages.ts +++ b/src/global/selectors/messages.ts @@ -432,28 +432,18 @@ export function getSendersFromSelectedMessages( return selectedMessageIds.map((id) => { const message = selectChatMessage(global, chat.id, id); - if (!message?.senderId) { - return undefined; - } - return selectSender(global, message); + return message && selectSender(global, message); }); } export function selectSenderFromMessage( global: T, - chat: ApiChat | undefined, - selectedMessageId: number | undefined, + chatId: string, + messageId: number, ): ApiPeer | undefined { - if (!chat?.id || !selectedMessageId) { - return undefined; - } + const message = selectChatMessage(global, chatId, messageId); - const message = selectChatMessage(global, chat.id, selectedMessageId); - if (!message?.senderId) { - return undefined; - } - - return selectPeer(global, message.senderId); + return message && selectSender(global, message); } export function selectSenderFromHeader( diff --git a/src/global/types.ts b/src/global/types.ts index b3d5880d8..b69f501b9 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -2847,6 +2847,7 @@ export interface ActionPayloads { }; clickBotInlineButton: { + chatId: string; messageId: number; button: ApiKeyboardButton; } & WithTabId; diff --git a/src/styles/_variables.scss b/src/styles/_variables.scss index 8252543f1..c9b1fca33 100644 --- a/src/styles/_variables.scss +++ b/src/styles/_variables.scss @@ -248,6 +248,7 @@ $color-message-story-mention-to: #74bcff; --z-modal: 1510; --z-modal-menu: 1600; --z-media-viewer: 1500; + --z-modal-low-priority: 1400; --z-video-player-controls: 3; --z-drop-area: 55; --z-animation-fade: 50;