Composer: Fix composer blocked if editing message (#2732)

This commit is contained in:
Alexander Zinchuk 2023-03-03 14:30:45 +01:00
parent 7147393753
commit 16838bf012

View File

@ -361,6 +361,8 @@ const Composer: FC<OwnProps & StateProps> = ({
canSendVoices, canSendPlainText, canSendAudios, canSendVideos, canSendPhotos, canSendDocuments, canSendVoices, canSendPlainText, canSendAudios, canSendVideos, canSendPhotos, canSendDocuments,
} = useMemo(() => getAllowedAttachmentOptions(chat, isChatWithBot), [chat, isChatWithBot]); } = useMemo(() => getAllowedAttachmentOptions(chat, isChatWithBot), [chat, isChatWithBot]);
const isComposerBlocked = !canSendPlainText && !editingMessage;
const { const {
shouldSuggestCompression, shouldSuggestCompression,
shouldForceCompression, shouldForceCompression,
@ -501,7 +503,7 @@ const Composer: FC<OwnProps & StateProps> = ({
); );
const insertHtmlAndUpdateCursor = useCallback((newHtml: string, inputId: string = EDITABLE_INPUT_ID) => { const insertHtmlAndUpdateCursor = useCallback((newHtml: string, inputId: string = EDITABLE_INPUT_ID) => {
if (inputId === EDITABLE_INPUT_ID && !canSendPlainText) return; if (inputId === EDITABLE_INPUT_ID && isComposerBlocked) return;
const selection = window.getSelection()!; const selection = window.getSelection()!;
let messageInput: HTMLDivElement; let messageInput: HTMLDivElement;
if (inputId === EDITABLE_INPUT_ID) { if (inputId === EDITABLE_INPUT_ID) {
@ -525,7 +527,7 @@ const Composer: FC<OwnProps & StateProps> = ({
requestAnimationFrame(() => { requestAnimationFrame(() => {
focusEditableElement(messageInput); focusEditableElement(messageInput);
}); });
}, [canSendPlainText, getHtml, setHtml]); }, [isComposerBlocked, getHtml, setHtml]);
const insertFormattedTextAndUpdateCursor = useCallback(( const insertFormattedTextAndUpdateCursor = useCallback((
text: ApiFormattedText, inputId: string = EDITABLE_INPUT_ID, text: ApiFormattedText, inputId: string = EDITABLE_INPUT_ID,
@ -1071,10 +1073,10 @@ const Composer: FC<OwnProps & StateProps> = ({
}, [insertHtmlAndUpdateCursor]); }, [insertHtmlAndUpdateCursor]);
useEffect(() => { useEffect(() => {
if (canSendPlainText) return; if (!isComposerBlocked) return;
setHtml(''); setHtml('');
}, [canSendPlainText, setHtml, attachments]); }, [isComposerBlocked, setHtml, attachments]);
const insertTextAndUpdateCursorAttachmentModal = useCallback((text: string) => { const insertTextAndUpdateCursorAttachmentModal = useCallback((text: string) => {
insertTextAndUpdateCursor(text, EDITABLE_INPUT_MODAL_ID); insertTextAndUpdateCursor(text, EDITABLE_INPUT_MODAL_ID);
@ -1355,7 +1357,7 @@ const Composer: FC<OwnProps & StateProps> = ({
/> />
</Button> </Button>
)} )}
{(canSendPlainText || canSendGifs || canSendStickers) && ( {(!isComposerBlocked || canSendGifs || canSendStickers) && (
<SymbolMenuButton <SymbolMenuButton
chatId={chatId} chatId={chatId}
threadId={threadId} threadId={threadId}
@ -1374,7 +1376,7 @@ const Composer: FC<OwnProps & StateProps> = ({
closeBotCommandMenu={closeBotCommandMenu} closeBotCommandMenu={closeBotCommandMenu}
closeSendAsMenu={closeSendAsMenu} closeSendAsMenu={closeSendAsMenu}
isSymbolMenuForced={isSymbolMenuForced} isSymbolMenuForced={isSymbolMenuForced}
canSendPlainText={canSendPlainText} canSendPlainText={!isComposerBlocked}
/> />
)} )}
<MessageInput <MessageInput
@ -1382,14 +1384,14 @@ const Composer: FC<OwnProps & StateProps> = ({
id="message-input-text" id="message-input-text"
editableInputId={EDITABLE_INPUT_ID} editableInputId={EDITABLE_INPUT_ID}
chatId={chatId} chatId={chatId}
canSendPlainText={canSendPlainText} canSendPlainText={!isComposerBlocked}
threadId={threadId} threadId={threadId}
isActive={!hasAttachments} isActive={!hasAttachments}
getHtml={getHtml} getHtml={getHtml}
placeholder={ placeholder={
activeVoiceRecording && windowWidth <= SCREEN_WIDTH_TO_HIDE_PLACEHOLDER activeVoiceRecording && windowWidth <= SCREEN_WIDTH_TO_HIDE_PLACEHOLDER
? '' ? ''
: (canSendPlainText : (!isComposerBlocked
? (botKeyboardPlaceholder || lang('Message')) ? (botKeyboardPlaceholder || lang('Message'))
: lang('Chat.PlaceholderTextNotAllowed')) : lang('Chat.PlaceholderTextNotAllowed'))
} }