about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/components/status_content.jsx
diff options
context:
space:
mode:
authorChristian Schmidt <github@chsc.dk>2023-03-16 11:07:24 +0100
committerClaire <claire.github-309c@sitedethib.com>2023-03-16 23:21:08 +0100
commit8f97ffe91e79c0418666f64b5830d3e74fcc83ba (patch)
tree9ddf09dda84c65904c36dec759834ea446b4ac5d /app/javascript/flavours/glitch/components/status_content.jsx
parent193250556cb4e6b1b3e2f9bd1ac023b290176fd4 (diff)
[Glitch] Replace `Status#translatable?` with language matrix in separate endpoint
Port bd047acc356671727c112336bb237f979bba517d to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
Diffstat (limited to 'app/javascript/flavours/glitch/components/status_content.jsx')
-rw-r--r--app/javascript/flavours/glitch/components/status_content.jsx13
1 files changed, 11 insertions, 2 deletions
diff --git a/app/javascript/flavours/glitch/components/status_content.jsx b/app/javascript/flavours/glitch/components/status_content.jsx
index f21732065..6e1cc275e 100644
--- a/app/javascript/flavours/glitch/components/status_content.jsx
+++ b/app/javascript/flavours/glitch/components/status_content.jsx
@@ -3,6 +3,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
 import PropTypes from 'prop-types';
 import { FormattedMessage, injectIntl } from 'react-intl';
 import Permalink from './permalink';
+import { connect } from 'react-redux';
 import classnames from 'classnames';
 import Icon from 'flavours/glitch/components/icon';
 import { autoPlayGif, languages as preloadedLanguages } from 'flavours/glitch/initial_state';
@@ -99,7 +100,12 @@ class TranslateButton extends React.PureComponent {
 
 }
 
-export default @injectIntl
+const mapStateToProps = state => ({
+  languages: state.getIn(['server', 'translationLanguages', 'items']),
+});
+
+export default @connect(mapStateToProps)
+@injectIntl
 class StatusContent extends React.PureComponent {
 
   static contextTypes = {
@@ -120,6 +126,7 @@ class StatusContent extends React.PureComponent {
     onUpdate: PropTypes.func,
     tagLinks: PropTypes.bool,
     rewriteMentions: PropTypes.string,
+    languages: ImmutablePropTypes.map,
     intl: PropTypes.object,
   };
 
@@ -315,7 +322,9 @@ class StatusContent extends React.PureComponent {
     } = this.props;
 
     const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden;
-    const renderTranslate = this.props.onTranslate && status.get('translatable');
+    const contentLocale = intl.locale.replace(/[_-].*/, '');
+    const targetLanguages = this.props.languages?.get(status.get('language') || 'und');
+    const renderTranslate = this.props.onTranslate && this.context.identity.signedIn && ['public', 'unlisted'].includes(status.get('visibility')) && status.get('contentHtml').length > 0 && targetLanguages?.includes(contentLocale);
 
     const content = { __html: status.get('translation') ? status.getIn(['translation', 'content']) : status.get('contentHtml') };
     const spoilerContent = { __html: status.get('spoilerHtml') };