From 9f8fce3c47d826ef761d19d42ca6ea83ac210314 Mon Sep 17 00:00:00 2001 From: diondiondion Date: Thu, 30 Oct 2025 20:29:25 +0100 Subject: [PATCH] [Glitch] Show error when submitting empty post rather than failing silently Port 214d59bd373f1c83dca55728e2d15738d33de836 to glitch-soc Signed-off-by: Claire --- app/javascript/flavours/glitch/actions/compose.js | 12 +++++++++++- .../features/compose/components/compose_form.jsx | 5 ++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index 06a3331bbb..09d6e7bbb3 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -5,6 +5,7 @@ import { throttle } from 'lodash'; import api from 'flavours/glitch/api'; import { browserHistory } from 'flavours/glitch/components/router'; +import { countableText } from 'flavours/glitch/features/compose/util/counter'; import { search as emojiSearch } from 'flavours/glitch/features/emoji/emoji_mart_search_light'; import { tagHistory } from 'flavours/glitch/settings'; import { recoverHashtags } from 'flavours/glitch/utils/hashtag'; @@ -93,6 +94,7 @@ const messages = defineMessages({ open: { id: 'compose.published.open', defaultMessage: 'Open' }, published: { id: 'compose.published.body', defaultMessage: 'Post published.' }, saved: { id: 'compose.saved.body', defaultMessage: 'Post saved.' }, + blankPostError: { id: 'compose.error.blank_post', defaultMessage: 'Post can\'t be blank.' }, }); export const ensureComposeIsVisible = (getState) => { @@ -215,7 +217,15 @@ export function submitCompose(overridePrivacy = null, successCallback = undefine const spoilers = getState().getIn(['compose', 'spoiler']) || getState().getIn(['local_settings', 'always_show_spoilers_field']); const spoiler_text = spoilers ? getState().getIn(['compose', 'spoiler_text'], '') : ''; - if (!(status?.length || media.size !== 0 || (hasQuote && spoiler_text?.length))) { + const fulltext = `${spoiler_text ?? ''}${countableText(status ?? '')}`; + const hasText = fulltext.trim().length > 0; + + if (!(hasText || media.size !== 0 || (hasQuote && spoiler_text?.length))) { + dispatch(showAlert({ + message: messages.blankPostError, + })); + dispatch(focusCompose()); + return; } diff --git a/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx b/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx index 92d29dd16b..42fbeb3a33 100644 --- a/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx +++ b/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx @@ -138,11 +138,10 @@ class ComposeForm extends ImmutablePureComponent { }; canSubmit = () => { - const { isSubmitting, isChangingUpload, isUploading, anyMedia, maxChars } = this.props; + const { isSubmitting, isChangingUpload, isUploading, maxChars } = this.props; const fulltext = this.getFulltextForCharacterCounting(); - const isOnlyWhitespace = fulltext.length !== 0 && fulltext.trim().length === 0; - return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars || (isOnlyWhitespace && !anyMedia)); + return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > maxChars); }; handleSubmit = (e, overridePrivacy = null) => {