From 343d2adca50b287404888f1d3fde1dd38e7f0dbe Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Thu, 29 Aug 2024 15:52:11 +0200 Subject: [PATCH] Reply: Support in chats where sending is blocked (#4859) --- .../middle/message/ContextMenuContainer.tsx | 27 ++++++++++++------- src/global/selectors/messages.ts | 6 ++++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/components/middle/message/ContextMenuContainer.tsx b/src/components/middle/message/ContextMenuContainer.tsx index c81627549..e36c7c265 100644 --- a/src/components/middle/message/ContextMenuContainer.tsx +++ b/src/components/middle/message/ContextMenuContainer.tsx @@ -19,7 +19,7 @@ import { MAIN_THREAD_ID } from '../../../api/types'; import { PREVIEW_AVATAR_COUNT, SERVICE_NOTIFICATIONS_USER_ID } from '../../../config'; import { areReactionsEmpty, - getHasAdminRight, + getCanPostInChat, getIsDownloading, getMessageDownloadableMedia, getMessageVideo, @@ -30,6 +30,7 @@ import { isMessageLocal, isOwnMessage, isUserId, + isUserRightBanned, } from '../../../global/helpers'; import { selectActiveDownloads, @@ -50,6 +51,7 @@ import { selectRequestedChatTranslationLanguage, selectRequestedMessageTranslationLanguage, selectStickerSet, + selectThreadInfo, selectUserStatus, } from '../../../global/selectors'; import buildClassName from '../../../util/buildClassName'; @@ -129,7 +131,7 @@ type StateProps = { isReactionPickerOpen?: boolean; isInSavedMessages?: boolean; isChannel?: boolean; - canPostMessagesInChannel?: boolean; + canReplyInChat?: boolean; }; const selection = window.getSelection(); @@ -190,8 +192,7 @@ const ContextMenuContainer: FC = ({ isInSavedMessages, onClose, onCloseAnimationEnd, - isChannel, - canPostMessagesInChannel, + canReplyInChat, }) => { const { openThread, @@ -364,7 +365,7 @@ const ContextMenuContainer: FC = ({ const handleReply = useLastCallback(() => { const quoteText = canQuoteSelection && selectionRange ? getSelectionAsFormattedText(selectionRange) : undefined; - if (isChannel && !canPostMessagesInChannel) { + if (!canReplyInChat) { openReplyMenu({ fromChatId: message.chatId, messageId: message.id, quoteText }); } else { updateDraftReplyInfo({ @@ -685,7 +686,7 @@ export default memo(withGlobal( const { noOptions, - canReply, + canReplyGlobally, canPin, canUnpin, canDelete, @@ -721,7 +722,15 @@ export default memo(withGlobal( const isPinned = messageListType === 'pinned'; const isScheduled = messageListType === 'scheduled'; const isChannel = chat && isChatChannel(chat); - const canPostMessagesInChannel = isChannel && getHasAdminRight(chat, 'postMessages'); + + const threadInfo = threadId && selectThreadInfo(global, message.chatId, threadId); + const isMessageThread = Boolean(threadInfo && !threadInfo?.isCommentsInfo && threadInfo?.fromChannelId); + + const canSendText = chat && !isUserRightBanned(chat, 'sendPlain', chatFullInfo); + + const canReplyInChat = chat && threadId ? getCanPostInChat(chat, threadId, isMessageThread, chatFullInfo) + && canSendText : false; + const isLocal = isMessageLocal(message); const hasTtl = hasMessageTtl(message); const canShowSeenBy = Boolean(!isLocal @@ -764,7 +773,7 @@ export default memo(withGlobal( noOptions, canSendNow: isScheduled, canReschedule: isScheduled, - canReply: !isPinned && !isScheduled && canReply, + canReply: !isPinned && !isScheduled && canReplyGlobally, canPin: !isScheduled && canPin, canUnpin: !isScheduled && canUnpin, canDelete, @@ -804,7 +813,7 @@ export default memo(withGlobal( isReactionPickerOpen: selectIsReactionPickerOpen(global), isInSavedMessages, isChannel, - canPostMessagesInChannel, + canReplyInChat, }; }, )(ContextMenuContainer)); diff --git a/src/global/selectors/messages.ts b/src/global/selectors/messages.ts index 923d8ed04..0e4092102 100644 --- a/src/global/selectors/messages.ts +++ b/src/global/selectors/messages.ts @@ -658,11 +658,13 @@ export function selectAllowedMessageActions(global: T, me const canPostInChat = getCanPostInChat(chat, threadId, isMessageThread, chatFullInfo); const canReply = (() => { if (isLocal || isServiceNotification) return false; - if (isChatChannel(chat)) return true; if (!canPostInChat || chat.isForbidden) return false; return !messageTopic || !messageTopic.isClosed || messageTopic.isOwner || getHasAdminRight(chat, 'manageTopics'); })(); + const canReplyGlobally = canReply || (!isSavedDialog && !isLocal && !isServiceNotification + && (isSuperGroup || isBasicGroup || isChatChannel(chat))); + const hasPinPermission = isPrivate || ( chat.isCreator || (!isChannel && !isUserRightBanned(chat, 'pinMessages')) @@ -737,6 +739,7 @@ export function selectAllowedMessageActions(global: T, me const noOptions = [ canReply, + canReplyGlobally, canEdit, canPin, canUnpin, @@ -758,6 +761,7 @@ export function selectAllowedMessageActions(global: T, me return { noOptions, canReply, + canReplyGlobally, canEdit, canPin, canUnpin,