From b4d373a3df2752d9f8bdc0d7f02350528f3789b2 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 10 May 2022 09:44:35 +0200 Subject: [PATCH] Add `limited` attribute to accounts in REST API and a warning in web UI (#18344) --- app/javascript/mastodon/actions/accounts.js | 7 +++ app/javascript/mastodon/components/avatar.js | 28 +++++---- .../features/account/components/header.js | 57 ++++++++++--------- .../account_timeline/components/header.js | 8 ++- .../components/limited_account_hint.js | 35 ++++++++++++ .../containers/header_container.js | 3 +- .../features/account_timeline/index.js | 16 ++++-- .../mastodon/features/followers/index.js | 20 +++++-- .../mastodon/features/following/index.js | 20 +++++-- app/javascript/mastodon/reducers/accounts.js | 7 ++- app/javascript/mastodon/selectors/index.js | 8 +++ .../styles/mastodon/components.scss | 9 +++ app/serializers/rest/account_serializer.rb | 7 ++- 13 files changed, 166 insertions(+), 59 deletions(-) create mode 100644 app/javascript/mastodon/features/account_timeline/components/limited_account_hint.js diff --git a/app/javascript/mastodon/actions/accounts.js b/app/javascript/mastodon/actions/accounts.js index ce7bb6d5f..eedf61dc9 100644 --- a/app/javascript/mastodon/actions/accounts.js +++ b/app/javascript/mastodon/actions/accounts.js @@ -77,6 +77,8 @@ export const FOLLOW_REQUEST_REJECT_REQUEST = 'FOLLOW_REQUEST_REJECT_REQUEST'; export const FOLLOW_REQUEST_REJECT_SUCCESS = 'FOLLOW_REQUEST_REJECT_SUCCESS'; export const FOLLOW_REQUEST_REJECT_FAIL = 'FOLLOW_REQUEST_REJECT_FAIL'; +export const ACCOUNT_REVEAL = 'ACCOUNT_REVEAL'; + export function fetchAccount(id) { return (dispatch, getState) => { dispatch(fetchRelationships([id])); @@ -780,3 +782,8 @@ export function unpinAccountFail(error) { error, }; }; + +export const revealAccount = id => ({ + type: ACCOUNT_REVEAL, + id, +}); diff --git a/app/javascript/mastodon/components/avatar.js b/app/javascript/mastodon/components/avatar.js index 570505833..12ab7d2df 100644 --- a/app/javascript/mastodon/components/avatar.js +++ b/app/javascript/mastodon/components/avatar.js @@ -2,11 +2,12 @@ import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { autoPlayGif } from '../initial_state'; +import classNames from 'classnames'; export default class Avatar extends React.PureComponent { static propTypes = { - account: ImmutablePropTypes.map.isRequired, + account: ImmutablePropTypes.map, size: PropTypes.number.isRequired, style: PropTypes.object, inline: PropTypes.bool, @@ -37,15 +38,6 @@ export default class Avatar extends React.PureComponent { const { account, size, animate, inline } = this.props; const { hovering } = this.state; - const src = account.get('avatar'); - const staticSrc = account.get('avatar_static'); - - let className = 'account__avatar'; - - if (inline) { - className = className + ' account__avatar-inline'; - } - const style = { ...this.props.style, width: `${size}px`, @@ -53,15 +45,21 @@ export default class Avatar extends React.PureComponent { backgroundSize: `${size}px ${size}px`, }; - if (hovering || animate) { - style.backgroundImage = `url(${src})`; - } else { - style.backgroundImage = `url(${staticSrc})`; + if (account) { + const src = account.get('avatar'); + const staticSrc = account.get('avatar_static'); + + if (hovering || animate) { + style.backgroundImage = `url(${src})`; + } else { + style.backgroundImage = `url(${staticSrc})`; + } } + return (
{ @@ -123,7 +124,7 @@ class Header extends ImmutablePureComponent { } render () { - const { account, intl, domain } = this.props; + const { account, hidden, intl, domain } = this.props; if (!account) { return null; @@ -267,21 +268,25 @@ class Header extends ImmutablePureComponent { {!suspended && info}
- + {!(suspended || hidden) && }
- +
{!suspended && (
- {actionBtn} - {bellBtn} + {!hidden && ( + + {actionBtn} + {bellBtn} + + )}
@@ -295,30 +300,30 @@ class Header extends ImmutablePureComponent {
-
-
- {fields.size > 0 && ( -
- {fields.map((pair, i) => ( -
-
+ {!(suspended || hidden) && ( +
+
+ {fields.size > 0 && ( +
+ {fields.map((pair, i) => ( +
+
-
- {pair.get('verified_at') && } -
-
- ))} -
- )} +
+ {pair.get('verified_at') && } +
+
+ ))} +
+ )} - {account.get('id') !== me && !suspended && } + {account.get('id') !== me && } - {account.get('note').length > 0 && account.get('note') !== '

' &&
} + {account.get('note').length > 0 && account.get('note') !== '

' &&
} -
-
+
+
- {!suspended && (
- )} -
+
+ )}
); diff --git a/app/javascript/mastodon/features/account_timeline/components/header.js b/app/javascript/mastodon/features/account_timeline/components/header.js index 507b6c895..fab0bc597 100644 --- a/app/javascript/mastodon/features/account_timeline/components/header.js +++ b/app/javascript/mastodon/features/account_timeline/components/header.js @@ -24,6 +24,7 @@ export default class Header extends ImmutablePureComponent { onAddToList: PropTypes.func.isRequired, hideTabs: PropTypes.bool, domain: PropTypes.string.isRequired, + hidden: PropTypes.bool, }; static contextTypes = { @@ -91,7 +92,7 @@ export default class Header extends ImmutablePureComponent { } render () { - const { account, hideTabs } = this.props; + const { account, hidden, hideTabs } = this.props; if (account === null) { return null; @@ -99,7 +100,7 @@ export default class Header extends ImmutablePureComponent { return (
- {account.get('moved') && } + {(!hidden && account.get('moved')) && }