From cb3a0bf3ed1994a34e506bc4b82dc47ac25a1951 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Mon, 12 Mar 2018 18:39:07 +0100 Subject: [PATCH] Remove text requirement when media attached from statuses (fixes #381) Ports 0c2a08adeb3d45f66f53e6b0cb0807511327e8b0 to glitchsoc --- app/javascript/flavours/glitch/actions/compose.js | 5 +++-- .../flavours/glitch/components/status_content.js | 11 ++++++++++- .../flavours/glitch/features/composer/index.js | 7 ++++++- app/javascript/flavours/glitch/reducers/compose.js | 3 --- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index c463871044..1e93868592 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -102,8 +102,9 @@ export function mentionCompose(account, router) { export function submitCompose() { return function (dispatch, getState) { let status = getState().getIn(['compose', 'text'], ''); + let media = getState().getIn(['compose', 'media_attachments']); - if (!status || !status.length) { + if ((!status || !status.length) && media.size === 0) { return; } @@ -114,7 +115,7 @@ export function submitCompose() { api(getState).post('/api/v1/statuses', { status, in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null), - media_ids: getState().getIn(['compose', 'media_attachments']).map(item => item.get('id')), + media_ids: media.map(item => item.get('id')), sensitive: getState().getIn(['compose', 'sensitive']), spoiler_text: getState().getIn(['compose', 'spoiler_text'], ''), visibility: getState().getIn(['compose', 'privacy']), diff --git a/app/javascript/flavours/glitch/components/status_content.js b/app/javascript/flavours/glitch/components/status_content.js index 0c40e62cca..a15bf7c523 100644 --- a/app/javascript/flavours/glitch/components/status_content.js +++ b/app/javascript/flavours/glitch/components/status_content.js @@ -23,7 +23,12 @@ export default class StatusContent extends React.PureComponent { }; _updateStatusLinks () { - const node = this.node; + const node = this.node; + + if (!node) { + return; + } + const links = node.querySelectorAll('a'); for (var i = 0; i < links.length; ++i) { @@ -126,6 +131,10 @@ export default class StatusContent extends React.PureComponent { disabled, } = this.props; + if (status.get('content').length === 0) { + return null; + } + const hidden = this.props.setExpansion ? !this.props.expanded : this.state.hidden; const content = { __html: status.get('contentHtml') }; diff --git a/app/javascript/flavours/glitch/features/composer/index.js b/app/javascript/flavours/glitch/features/composer/index.js index e50f3ec3f2..792ed79a31 100644 --- a/app/javascript/flavours/glitch/features/composer/index.js +++ b/app/javascript/flavours/glitch/features/composer/index.js @@ -73,6 +73,7 @@ function mapStateToProps (state) { suggestionToken: state.getIn(['compose', 'suggestion_token']), suggestions: state.getIn(['compose', 'suggestions']), text: state.getIn(['compose', 'text']), + anyMedia: state.getIn(['compose', 'media_attachments']).size > 0, }; }; @@ -272,6 +273,7 @@ class Composer extends React.Component { acceptContentTypes, advancedOptions, amUnlocked, + anyMedia, intl, isSubmitting, isUploading, @@ -305,6 +307,8 @@ class Composer extends React.Component { text, } = this.props; + let disabledButton = isSubmitting || isUploading || (!!text.length && !text.trim().length && !anyMedia); + return (
list.push(media)); map.set('is_uploading', false); map.set('resetFileKey', Math.floor((Math.random() * 0x10000))); - map.update('text', oldText => `${oldText.trim()} ${media.get('text_url')}`); map.set('focusDate', new Date()); map.set('idempotencyKey', uuid()); @@ -169,12 +168,10 @@ function appendMedia(state, media) { }; function removeMedia(state, mediaId) { - const media = state.get('media_attachments').find(item => item.get('id') === mediaId); const prevSize = state.get('media_attachments').size; return state.withMutations(map => { map.update('media_attachments', list => list.filterNot(item => item.get('id') === mediaId)); - map.update('text', text => text.replace(media.get('text_url'), '').trim()); map.set('idempotencyKey', uuid()); if (prevSize === 1) {