Reply: Support in chats where sending is blocked (#4859)

This commit is contained in:
Alexander Zinchuk 2024-08-29 15:52:11 +02:00
parent eec23ac6e9
commit 343d2adca5
2 changed files with 23 additions and 10 deletions

View File

@ -19,7 +19,7 @@ import { MAIN_THREAD_ID } from '../../../api/types';
import { PREVIEW_AVATAR_COUNT, SERVICE_NOTIFICATIONS_USER_ID } from '../../../config'; import { PREVIEW_AVATAR_COUNT, SERVICE_NOTIFICATIONS_USER_ID } from '../../../config';
import { import {
areReactionsEmpty, areReactionsEmpty,
getHasAdminRight, getCanPostInChat,
getIsDownloading, getIsDownloading,
getMessageDownloadableMedia, getMessageDownloadableMedia,
getMessageVideo, getMessageVideo,
@ -30,6 +30,7 @@ import {
isMessageLocal, isMessageLocal,
isOwnMessage, isOwnMessage,
isUserId, isUserId,
isUserRightBanned,
} from '../../../global/helpers'; } from '../../../global/helpers';
import { import {
selectActiveDownloads, selectActiveDownloads,
@ -50,6 +51,7 @@ import {
selectRequestedChatTranslationLanguage, selectRequestedChatTranslationLanguage,
selectRequestedMessageTranslationLanguage, selectRequestedMessageTranslationLanguage,
selectStickerSet, selectStickerSet,
selectThreadInfo,
selectUserStatus, selectUserStatus,
} from '../../../global/selectors'; } from '../../../global/selectors';
import buildClassName from '../../../util/buildClassName'; import buildClassName from '../../../util/buildClassName';
@ -129,7 +131,7 @@ type StateProps = {
isReactionPickerOpen?: boolean; isReactionPickerOpen?: boolean;
isInSavedMessages?: boolean; isInSavedMessages?: boolean;
isChannel?: boolean; isChannel?: boolean;
canPostMessagesInChannel?: boolean; canReplyInChat?: boolean;
}; };
const selection = window.getSelection(); const selection = window.getSelection();
@ -190,8 +192,7 @@ const ContextMenuContainer: FC<OwnProps & StateProps> = ({
isInSavedMessages, isInSavedMessages,
onClose, onClose,
onCloseAnimationEnd, onCloseAnimationEnd,
isChannel, canReplyInChat,
canPostMessagesInChannel,
}) => { }) => {
const { const {
openThread, openThread,
@ -364,7 +365,7 @@ const ContextMenuContainer: FC<OwnProps & StateProps> = ({
const handleReply = useLastCallback(() => { const handleReply = useLastCallback(() => {
const quoteText = canQuoteSelection && selectionRange ? getSelectionAsFormattedText(selectionRange) : undefined; const quoteText = canQuoteSelection && selectionRange ? getSelectionAsFormattedText(selectionRange) : undefined;
if (isChannel && !canPostMessagesInChannel) { if (!canReplyInChat) {
openReplyMenu({ fromChatId: message.chatId, messageId: message.id, quoteText }); openReplyMenu({ fromChatId: message.chatId, messageId: message.id, quoteText });
} else { } else {
updateDraftReplyInfo({ updateDraftReplyInfo({
@ -685,7 +686,7 @@ export default memo(withGlobal<OwnProps>(
const { const {
noOptions, noOptions,
canReply, canReplyGlobally,
canPin, canPin,
canUnpin, canUnpin,
canDelete, canDelete,
@ -721,7 +722,15 @@ export default memo(withGlobal<OwnProps>(
const isPinned = messageListType === 'pinned'; const isPinned = messageListType === 'pinned';
const isScheduled = messageListType === 'scheduled'; const isScheduled = messageListType === 'scheduled';
const isChannel = chat && isChatChannel(chat); 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 isLocal = isMessageLocal(message);
const hasTtl = hasMessageTtl(message); const hasTtl = hasMessageTtl(message);
const canShowSeenBy = Boolean(!isLocal const canShowSeenBy = Boolean(!isLocal
@ -764,7 +773,7 @@ export default memo(withGlobal<OwnProps>(
noOptions, noOptions,
canSendNow: isScheduled, canSendNow: isScheduled,
canReschedule: isScheduled, canReschedule: isScheduled,
canReply: !isPinned && !isScheduled && canReply, canReply: !isPinned && !isScheduled && canReplyGlobally,
canPin: !isScheduled && canPin, canPin: !isScheduled && canPin,
canUnpin: !isScheduled && canUnpin, canUnpin: !isScheduled && canUnpin,
canDelete, canDelete,
@ -804,7 +813,7 @@ export default memo(withGlobal<OwnProps>(
isReactionPickerOpen: selectIsReactionPickerOpen(global), isReactionPickerOpen: selectIsReactionPickerOpen(global),
isInSavedMessages, isInSavedMessages,
isChannel, isChannel,
canPostMessagesInChannel, canReplyInChat,
}; };
}, },
)(ContextMenuContainer)); )(ContextMenuContainer));

View File

@ -658,11 +658,13 @@ export function selectAllowedMessageActions<T extends GlobalState>(global: T, me
const canPostInChat = getCanPostInChat(chat, threadId, isMessageThread, chatFullInfo); const canPostInChat = getCanPostInChat(chat, threadId, isMessageThread, chatFullInfo);
const canReply = (() => { const canReply = (() => {
if (isLocal || isServiceNotification) return false; if (isLocal || isServiceNotification) return false;
if (isChatChannel(chat)) return true;
if (!canPostInChat || chat.isForbidden) return false; if (!canPostInChat || chat.isForbidden) return false;
return !messageTopic || !messageTopic.isClosed || messageTopic.isOwner || getHasAdminRight(chat, 'manageTopics'); return !messageTopic || !messageTopic.isClosed || messageTopic.isOwner || getHasAdminRight(chat, 'manageTopics');
})(); })();
const canReplyGlobally = canReply || (!isSavedDialog && !isLocal && !isServiceNotification
&& (isSuperGroup || isBasicGroup || isChatChannel(chat)));
const hasPinPermission = isPrivate || ( const hasPinPermission = isPrivate || (
chat.isCreator chat.isCreator
|| (!isChannel && !isUserRightBanned(chat, 'pinMessages')) || (!isChannel && !isUserRightBanned(chat, 'pinMessages'))
@ -737,6 +739,7 @@ export function selectAllowedMessageActions<T extends GlobalState>(global: T, me
const noOptions = [ const noOptions = [
canReply, canReply,
canReplyGlobally,
canEdit, canEdit,
canPin, canPin,
canUnpin, canUnpin,
@ -758,6 +761,7 @@ export function selectAllowedMessageActions<T extends GlobalState>(global: T, me
return { return {
noOptions, noOptions,
canReply, canReply,
canReplyGlobally,
canEdit, canEdit,
canPin, canPin,
canUnpin, canUnpin,