From 8c1381f00a27472574d22fe1857a51bf3c56da9a Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Fri, 18 Oct 2024 23:34:42 +0200 Subject: [PATCH] Disables text editor for DMs and GMs with remote users (#28861) This change makes the text editor behave similarly to the case of read only channels, in a disabled state and showing a placeholder that indicates that DMs and GMs with remote users are currently not supported. There is no way to create this type of channels now, but chances are that existing servers have some already, so this is intended to explicitly indicate that those won't work. --- .../advanced_text_editor.tsx | 34 +++++++++++++------ .../advanced_text_editor/use_emoji_picker.tsx | 4 +-- .../advanced_text_editor/use_upload_files.tsx | 6 ++-- webapp/channels/src/i18n/en.json | 1 + 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx b/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx index 6c3979c321..fb042d5149 100644 --- a/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx +++ b/webapp/channels/src/components/advanced_text_editor/advanced_text_editor.tsx @@ -108,7 +108,10 @@ const AdvancedTextEditor = ({ const isRHS = Boolean(postId && !isThreadView); const currentUserId = useSelector(getCurrentUserId); - const channelDisplayName = useSelector((state: GlobalState) => getChannelSelector(state, channelId)?.display_name || ''); + const channel = useSelector((state: GlobalState) => getChannelSelector(state, channelId)); + const channelDisplayName = channel?.display_name || ''; + const channelType = channel?.type || ''; + const isChannelShared = channel?.shared; const draftFromStore = useSelector((state: GlobalState) => getDraftSelector(state, channelId, postId)); const badConnection = useSelector((state: GlobalState) => connectionErrorCount(state) > 1); const maxPostSize = useSelector((state: GlobalState) => parseInt(getConfig(state).MaxPostSize || '', 10) || Constants.DEFAULT_CHARACTER_LIMIT); @@ -165,6 +168,8 @@ const AdvancedTextEditor = ({ const readOnlyChannel = !canPost; const hasDraftMessage = Boolean(draft.message); + const isDMOrGMRemote = isChannelShared && (channelType === Constants.DM_CHANNEL || channelType === Constants.GM_CHANNEL); + const isDisabled = Boolean(readOnlyChannel || isDMOrGMRemote); const handleShowPreview = useCallback(() => { setShowPreview((prev) => !prev); @@ -241,12 +246,12 @@ const AdvancedTextEditor = ({ useOrientationHandler(textboxRef, postId); const pluginItems = usePluginItems(draft, textboxRef, handleDraftChange); const focusTextbox = useTextboxFocus(textboxRef, channelId, isRHS, canPost); - const [attachmentPreview, fileUploadJSX] = useUploadFiles(draft, postId, channelId, isThreadView, storedDrafts, readOnlyChannel, textboxRef, handleDraftChange, focusTextbox, setServerError); + const [attachmentPreview, fileUploadJSX] = useUploadFiles(draft, postId, channelId, isThreadView, storedDrafts, isDisabled, textboxRef, handleDraftChange, focusTextbox, setServerError); const { emojiPicker, enableEmojiPicker, toggleEmojiPicker, - } = useEmojiPicker(readOnlyChannel, draft, caretPosition, setCaretPosition, handleDraftChange, showPreview, focusTextbox); + } = useEmojiPicker(isDisabled, draft, caretPosition, setCaretPosition, handleDraftChange, showPreview, focusTextbox); const { labels, additionalControl: priorityAdditionalControl, @@ -446,7 +451,7 @@ const AdvancedTextEditor = ({ }; }, [channelId, postId]); - const disableSendButton = Boolean(readOnlyChannel || (!draft.message.trim().length && !draft.fileInfos.length)) || !isValidPersistentNotifications; + const disableSendButton = Boolean(isDisabled || (!draft.message.trim().length && !draft.fileInfos.length)) || !isValidPersistentNotifications; const sendButton = readOnlyChannel ? null : (
{attachmentPreview} - {!readOnlyChannel && (showFormattingBar || showPreview) && ( + {!isDisabled && (showFormattingBar || showPreview) && ( ) : formattingBar} - {!readOnlyChannel && ( + {!isDisabled && ( void, @@ -116,7 +116,7 @@ const useEmojiPicker = ( let emojiPicker = null; - if (enableEmojiPicker && !readOnlyChannel) { + if (enableEmojiPicker && !isDisabled) { emojiPicker = ( <> >, - readOnlyChannel: boolean, + isDisabled: boolean, textboxRef: React.RefObject, handleDraftChange: (draft: PostDraft, options?: {instant?: boolean; show?: boolean}) => void, focusTextbox: (forceFocust?: boolean) => void, @@ -141,7 +141,7 @@ const useUploadFiles = ( }, [draft, fileUploadRef, handleDraftChange, handleUploadError, handleFileUploadChange]); let attachmentPreview = null; - if (!readOnlyChannel && (draft.fileInfos.length > 0 || draft.uploadsInProgress.length > 0)) { + if (!isDisabled && (draft.fileInfos.length > 0 || draft.uploadsInProgress.length > 0)) { attachmentPreview = ( upgrade to a paid plan.", "create_post.file_limit_sticky_banner.messageTitle": "Your free plan is limited to {storageGB} of files.",