Skip to content

Commit 62bafa2

Browse files
ClearlyClaireGargron
authored andcommitted
Hide blocking accounts from blocked users (mastodon#10442)
* Revert "Add indication that you have been blocked in web UI (mastodon#10420)" This reverts commit bd02ec6. * Revert "Add `blocked_by` relationship to the REST API (mastodon#10373)" This reverts commit 9745de8. * Hide blocking accounts from search results * Filter blocking accouts from account followers * Filter blocking accouts from account's following accounts * Filter blocking accounts from “reblogged by” and “favourited by” lists * Remove blocking account from URL search * Return 410 on trying to fetch user data from a user who blocked us * Return 410 in /api/v1/account/statuses for suspended or blocking accounts * Fix status filtering when performing URL search * Restore some React improvements Restore some cleanup from bd02ec6 * Refactor by adding `without_blocking` scope
1 parent 67eb47e commit 62bafa2

20 files changed

Lines changed: 136 additions & 62 deletions

app/controllers/api/v1/accounts/follower_accounts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def load_accounts
2525
end
2626

2727
def default_accounts
28-
Account.includes(:active_relationships, :account_stat).references(:active_relationships)
28+
Account.without_blocking(current_account).includes(:active_relationships, :account_stat).references(:active_relationships)
2929
end
3030

3131
def paginated_follows

app/controllers/api/v1/accounts/following_accounts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def load_accounts
2525
end
2626

2727
def default_accounts
28-
Account.includes(:passive_relationships, :account_stat).references(:passive_relationships)
28+
Account.without_blocking(current_account).includes(:passive_relationships, :account_stat).references(:passive_relationships)
2929
end
3030

3131
def paginated_follows

app/controllers/api/v1/accounts/statuses_controller.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
class Api::V1::Accounts::StatusesController < Api::BaseController
44
before_action -> { authorize_if_got_token! :read, :'read:statuses' }
55
before_action :set_account
6+
before_action :check_account_suspension
7+
before_action :check_account_block
68
after_action :insert_pagination_headers
79

810
respond_to :json
@@ -18,6 +20,14 @@ def set_account
1820
@account = Account.find(params[:account_id])
1921
end
2022

23+
def check_account_suspension
24+
gone if @account.suspended?
25+
end
26+
27+
def check_account_block
28+
gone if current_account.present? && @account.blocking?(current_account)
29+
end
30+
2131
def load_statuses
2232
cached_account_statuses
2333
end

app/controllers/api/v1/accounts_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Api::V1::AccountsController < Api::BaseController
1010
before_action :require_user!, except: [:show, :create]
1111
before_action :set_account, except: [:create]
1212
before_action :check_account_suspension, only: [:show]
13+
before_action :check_account_block, only: [:show]
1314
before_action :check_enabled_registrations, only: [:create]
1415

1516
respond_to :json
@@ -75,6 +76,10 @@ def check_account_suspension
7576
gone if @account.suspended?
7677
end
7778

79+
def check_account_block
80+
gone if current_account.present? && @account.blocking?(current_account)
81+
end
82+
7883
def account_params
7984
params.permit(:username, :email, :password, :agreement, :locale)
8085
end

app/controllers/api/v1/statuses/favourited_by_accounts_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def load_accounts
2222

2323
def default_accounts
2424
Account
25+
.without_blocking(current_account)
2526
.includes(:favourites, :account_stat)
2627
.references(:favourites)
2728
.where(favourites: { status_id: @status.id })

app/controllers/api/v1/statuses/reblogged_by_accounts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def load_accounts
2121
end
2222

2323
def default_accounts
24-
Account.includes(:statuses, :account_stat).references(:statuses)
24+
Account.without_blocking(current_account).includes(:statuses, :account_stat).references(:statuses)
2525
end
2626

2727
def paginated_statuses

app/javascript/mastodon/features/account/components/header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class Header extends ImmutablePureComponent {
111111
} else if (account.getIn(['relationship', 'requested'])) {
112112
actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.requested)} onClick={this.props.onFollow} />;
113113
} else if (!account.getIn(['relationship', 'blocking'])) {
114-
actionBtn = <Button disabled={account.getIn(['relationship', 'blocked_by'])} className={classNames('logo-button', { 'button--destructive': account.getIn(['relationship', 'following']) })} text={intl.formatMessage(account.getIn(['relationship', 'following']) ? messages.unfollow : messages.follow)} onClick={this.props.onFollow} />;
114+
actionBtn = <Button className={classNames('logo-button', { 'button--destructive': account.getIn(['relationship', 'following']) })} text={intl.formatMessage(account.getIn(['relationship', 'following']) ? messages.unfollow : messages.follow)} onClick={this.props.onFollow} />;
115115
} else if (account.getIn(['relationship', 'blocking'])) {
116116
actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.props.onBlock} />;
117117
}

app/javascript/mastodon/features/account_timeline/index.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
1414
import { FormattedMessage } from 'react-intl';
1515
import { fetchAccountIdentityProofs } from '../../actions/identity_proofs';
1616

17-
const emptyList = ImmutableList();
18-
1917
const mapStateToProps = (state, { params: { accountId }, withReplies = false }) => {
2018
const path = withReplies ? `${accountId}:with_replies` : accountId;
2119

2220
return {
23-
statusIds: state.getIn(['timelines', `account:${path}`, 'items'], emptyList),
24-
featuredStatusIds: withReplies ? ImmutableList() : state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], emptyList),
21+
statusIds: state.getIn(['timelines', `account:${path}`, 'items'], ImmutableList()),
22+
featuredStatusIds: withReplies ? ImmutableList() : state.getIn(['timelines', `account:${accountId}:pinned`, 'items'], ImmutableList()),
2523
isLoading: state.getIn(['timelines', `account:${path}`, 'isLoading']),
26-
hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
27-
blockedBy: state.getIn(['relationships', accountId, 'blocked_by'], false),
24+
hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
2825
};
2926
};
3027

@@ -40,31 +37,26 @@ class AccountTimeline extends ImmutablePureComponent {
4037
isLoading: PropTypes.bool,
4138
hasMore: PropTypes.bool,
4239
withReplies: PropTypes.bool,
43-
blockedBy: PropTypes.bool,
4440
};
4541

4642
componentWillMount () {
4743
const { params: { accountId }, withReplies } = this.props;
4844

4945
this.props.dispatch(fetchAccount(accountId));
5046
this.props.dispatch(fetchAccountIdentityProofs(accountId));
51-
5247
if (!withReplies) {
5348
this.props.dispatch(expandAccountFeaturedTimeline(accountId));
5449
}
55-
5650
this.props.dispatch(expandAccountTimeline(accountId, { withReplies }));
5751
}
5852

5953
componentWillReceiveProps (nextProps) {
6054
if ((nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) || nextProps.withReplies !== this.props.withReplies) {
6155
this.props.dispatch(fetchAccount(nextProps.params.accountId));
6256
this.props.dispatch(fetchAccountIdentityProofs(nextProps.params.accountId));
63-
6457
if (!nextProps.withReplies) {
6558
this.props.dispatch(expandAccountFeaturedTimeline(nextProps.params.accountId));
6659
}
67-
6860
this.props.dispatch(expandAccountTimeline(nextProps.params.accountId, { withReplies: nextProps.params.withReplies }));
6961
}
7062
}
@@ -74,7 +66,7 @@ class AccountTimeline extends ImmutablePureComponent {
7466
}
7567

7668
render () {
77-
const { shouldUpdateScroll, statusIds, featuredStatusIds, isLoading, hasMore, blockedBy } = this.props;
69+
const { shouldUpdateScroll, statusIds, featuredStatusIds, isLoading, hasMore } = this.props;
7870

7971
if (!statusIds && isLoading) {
8072
return (
@@ -84,8 +76,6 @@ class AccountTimeline extends ImmutablePureComponent {
8476
);
8577
}
8678

87-
const emptyMessage = blockedBy ? <FormattedMessage id='empty_column.account_timeline_blocked' defaultMessage='You are blocked' /> : <FormattedMessage id='empty_column.account_timeline' defaultMessage='No toots here!' />;
88-
8979
return (
9080
<Column>
9181
<ColumnBackButton />
@@ -94,13 +84,13 @@ class AccountTimeline extends ImmutablePureComponent {
9484
prepend={<HeaderContainer accountId={this.props.params.accountId} />}
9585
alwaysPrepend
9686
scrollKey='account_timeline'
97-
statusIds={blockedBy ? emptyList : statusIds}
87+
statusIds={statusIds}
9888
featuredStatusIds={featuredStatusIds}
9989
isLoading={isLoading}
10090
hasMore={hasMore}
10191
onLoadMore={this.handleLoadMore}
10292
shouldUpdateScroll={shouldUpdateScroll}
103-
emptyMessage={emptyMessage}
93+
emptyMessage={<FormattedMessage id='empty_column.account_timeline' defaultMessage='No toots here!' />}
10494
/>
10595
</Column>
10696
);

app/javascript/mastodon/features/followers/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import ScrollableList from '../../components/scrollable_list';
2020
const mapStateToProps = (state, props) => ({
2121
accountIds: state.getIn(['user_lists', 'followers', props.params.accountId, 'items']),
2222
hasMore: !!state.getIn(['user_lists', 'followers', props.params.accountId, 'next']),
23-
blockedBy: state.getIn(['relationships', props.params.accountId, 'blocked_by'], false),
2423
});
2524

2625
export default @connect(mapStateToProps)
@@ -32,7 +31,6 @@ class Followers extends ImmutablePureComponent {
3231
shouldUpdateScroll: PropTypes.func,
3332
accountIds: ImmutablePropTypes.list,
3433
hasMore: PropTypes.bool,
35-
blockedBy: PropTypes.bool,
3634
};
3735

3836
componentWillMount () {
@@ -52,7 +50,7 @@ class Followers extends ImmutablePureComponent {
5250
}, 300, { leading: true });
5351

5452
render () {
55-
const { shouldUpdateScroll, accountIds, hasMore, blockedBy } = this.props;
53+
const { shouldUpdateScroll, accountIds, hasMore } = this.props;
5654

5755
if (!accountIds) {
5856
return (
@@ -62,7 +60,7 @@ class Followers extends ImmutablePureComponent {
6260
);
6361
}
6462

65-
const emptyMessage = blockedBy ? <FormattedMessage id='empty_column.account_timeline_blocked' defaultMessage='You are blocked' /> : <FormattedMessage id='account.followers.empty' defaultMessage='No one follows this user yet.' />;
63+
const emptyMessage = <FormattedMessage id='account.followers.empty' defaultMessage='No one follows this user yet.' />;
6664

6765
return (
6866
<Column>
@@ -77,7 +75,7 @@ class Followers extends ImmutablePureComponent {
7775
alwaysPrepend
7876
emptyMessage={emptyMessage}
7977
>
80-
{blockedBy ? [] : accountIds.map(id =>
78+
{accountIds.map(id =>
8179
<AccountContainer key={id} id={id} withNote={false} />
8280
)}
8381
</ScrollableList>

app/javascript/mastodon/features/following/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import ScrollableList from '../../components/scrollable_list';
2020
const mapStateToProps = (state, props) => ({
2121
accountIds: state.getIn(['user_lists', 'following', props.params.accountId, 'items']),
2222
hasMore: !!state.getIn(['user_lists', 'following', props.params.accountId, 'next']),
23-
blockedBy: state.getIn(['relationships', props.params.accountId, 'blocked_by'], false),
2423
});
2524

2625
export default @connect(mapStateToProps)
@@ -32,7 +31,6 @@ class Following extends ImmutablePureComponent {
3231
shouldUpdateScroll: PropTypes.func,
3332
accountIds: ImmutablePropTypes.list,
3433
hasMore: PropTypes.bool,
35-
blockedBy: PropTypes.bool,
3634
};
3735

3836
componentWillMount () {
@@ -52,7 +50,7 @@ class Following extends ImmutablePureComponent {
5250
}, 300, { leading: true });
5351

5452
render () {
55-
const { shouldUpdateScroll, accountIds, hasMore, blockedBy } = this.props;
53+
const { shouldUpdateScroll, accountIds, hasMore } = this.props;
5654

5755
if (!accountIds) {
5856
return (
@@ -62,7 +60,7 @@ class Following extends ImmutablePureComponent {
6260
);
6361
}
6462

65-
const emptyMessage = blockedBy ? <FormattedMessage id='empty_column.account_timeline_blocked' defaultMessage='You are blocked' /> : <FormattedMessage id='account.follows.empty' defaultMessage="This user doesn't follow anyone yet." />;
63+
const emptyMessage = <FormattedMessage id='account.follows.empty' defaultMessage="This user doesn't follow anyone yet." />;
6664

6765
return (
6866
<Column>
@@ -77,7 +75,7 @@ class Following extends ImmutablePureComponent {
7775
alwaysPrepend
7876
emptyMessage={emptyMessage}
7977
>
80-
{blockedBy ? [] : accountIds.map(id =>
78+
{accountIds.map(id =>
8179
<AccountContainer key={id} id={id} withNote={false} />
8280
)}
8381
</ScrollableList>

0 commit comments

Comments
 (0)