Skip to content

Commit 7c1ea77

Browse files
authored
Improve blocked view of profiles (mastodon#10491)
* Revert "Fix filtering of favourited_by, reblogged_by, followers and following (mastodon#10447)" This reverts commit 1205440. * Revert "Hide blocking accounts from blocked users (mastodon#10442)" This reverts commit 62bafa2. * Improve blocked view of profiles - Change "You are blocked" to "Profile unavailable" - Hide following/followers in API when blocked - Disable follow button and show "Profile unavailable" on public profile as well
1 parent 0b0d3d2 commit 7c1ea77

26 files changed

Lines changed: 97 additions & 138 deletions

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ def set_account
1919
end
2020

2121
def load_accounts
22-
return [] if @account.user_hides_network? && current_account.id != @account.id
22+
return [] if hide_results?
2323

2424
default_accounts.merge(paginated_follows).to_a
2525
end
2626

27+
def hide_results?
28+
(@account.user_hides_network? && current_account.id != @account.id) || (current_account && @account.blocking?(current_account))
29+
end
30+
2731
def default_accounts
28-
Account.without_blocking(current_account).includes(:active_relationships, :account_stat).references(:active_relationships)
32+
Account.includes(:active_relationships, :account_stat).references(:active_relationships)
2933
end
3034

3135
def paginated_follows

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ def set_account
1919
end
2020

2121
def load_accounts
22-
return [] if @account.user_hides_network? && current_account.id != @account.id
22+
return [] if hide_results?
2323

2424
default_accounts.merge(paginated_follows).to_a
2525
end
2626

27+
def hide_results?
28+
(@account.user_hides_network? && current_account.id != @account.id) || (current_account && @account.blocking?(current_account))
29+
end
30+
2731
def default_accounts
28-
Account.without_blocking(current_account).includes(:passive_relationships, :account_stat).references(:passive_relationships)
32+
Account.includes(:passive_relationships, :account_stat).references(:passive_relationships)
2933
end
3034

3135
def paginated_follows

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
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
86
after_action :insert_pagination_headers
97

108
respond_to :json
@@ -20,14 +18,6 @@ def set_account
2018
@account = Account.find(params[:account_id])
2119
end
2220

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-
3121
def load_statuses
3222
cached_account_statuses
3323
end

app/controllers/api/v1/accounts_controller.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ 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]
1413
before_action :check_enabled_registrations, only: [:create]
1514

1615
respond_to :json
@@ -76,10 +75,6 @@ def check_account_suspension
7675
gone if @account.suspended?
7776
end
7877

79-
def check_account_block
80-
gone if current_account.present? && @account.blocking?(current_account)
81-
end
82-
8378
def account_params
8479
params.permit(:username, :email, :password, :agreement, :locale)
8580
end

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

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

2323
def default_accounts
2424
Account
25-
.without_blocking(current_account)
2625
.includes(:favourites, :account_stat)
2726
.references(:favourites)
2827
.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.without_blocking(current_account).includes(:statuses, :account_stat).references(:statuses)
24+
Account.includes(:statuses, :account_stat).references(:statuses)
2525
end
2626

2727
def paginated_statuses

app/helpers/stream_entries_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def account_action_button(account)
2323
safe_join([render(file: Rails.root.join('app', 'javascript', 'images', 'logo.svg')), t('accounts.unfollow')])
2424
end
2525
elsif !(account.memorial? || account.moved?)
26-
link_to account_follow_path(account), class: 'button logo-button', data: { method: :post } do
26+
link_to account_follow_path(account), class: "button logo-button#{account.blocking?(current_account) ? ' disabled' : ''}", data: { method: :post } do
2727
safe_join([render(file: Rails.root.join('app', 'javascript', 'images', 'logo.svg')), t('accounts.follow')])
2828
end
2929
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class Header extends ImmutablePureComponent {
109109
} else if (account.getIn(['relationship', 'requested'])) {
110110
actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.requested)} onClick={this.props.onFollow} />;
111111
} else if (!account.getIn(['relationship', 'blocking'])) {
112-
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} />;
112+
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} />;
113113
} else if (account.getIn(['relationship', 'blocking'])) {
114114
actionBtn = <Button className='logo-button' text={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.props.onBlock} />;
115115
}

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ 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+
1719
const mapStateToProps = (state, { params: { accountId }, withReplies = false }) => {
1820
const path = withReplies ? `${accountId}:with_replies` : accountId;
1921

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

@@ -37,26 +40,31 @@ class AccountTimeline extends ImmutablePureComponent {
3740
isLoading: PropTypes.bool,
3841
hasMore: PropTypes.bool,
3942
withReplies: PropTypes.bool,
43+
blockedBy: PropTypes.bool,
4044
};
4145

4246
componentWillMount () {
4347
const { params: { accountId }, withReplies } = this.props;
4448

4549
this.props.dispatch(fetchAccount(accountId));
4650
this.props.dispatch(fetchAccountIdentityProofs(accountId));
51+
4752
if (!withReplies) {
4853
this.props.dispatch(expandAccountFeaturedTimeline(accountId));
4954
}
55+
5056
this.props.dispatch(expandAccountTimeline(accountId, { withReplies }));
5157
}
5258

5359
componentWillReceiveProps (nextProps) {
5460
if ((nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) || nextProps.withReplies !== this.props.withReplies) {
5561
this.props.dispatch(fetchAccount(nextProps.params.accountId));
5662
this.props.dispatch(fetchAccountIdentityProofs(nextProps.params.accountId));
63+
5764
if (!nextProps.withReplies) {
5865
this.props.dispatch(expandAccountFeaturedTimeline(nextProps.params.accountId));
5966
}
67+
6068
this.props.dispatch(expandAccountTimeline(nextProps.params.accountId, { withReplies: nextProps.params.withReplies }));
6169
}
6270
}
@@ -66,7 +74,7 @@ class AccountTimeline extends ImmutablePureComponent {
6674
}
6775

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

7179
if (!statusIds && isLoading) {
7280
return (
@@ -76,6 +84,8 @@ class AccountTimeline extends ImmutablePureComponent {
7684
);
7785
}
7886

87+
const emptyMessage = blockedBy ? <FormattedMessage id='empty_column.account_unavailable' defaultMessage='Profile unavailable' /> : <FormattedMessage id='empty_column.account_timeline' defaultMessage='No toots here!' />;
88+
7989
return (
8090
<Column>
8191
<ColumnBackButton />
@@ -84,13 +94,13 @@ class AccountTimeline extends ImmutablePureComponent {
8494
prepend={<HeaderContainer accountId={this.props.params.accountId} />}
8595
alwaysPrepend
8696
scrollKey='account_timeline'
87-
statusIds={statusIds}
97+
statusIds={blockedBy ? emptyList : statusIds}
8898
featuredStatusIds={featuredStatusIds}
8999
isLoading={isLoading}
90100
hasMore={hasMore}
91101
onLoadMore={this.handleLoadMore}
92102
shouldUpdateScroll={shouldUpdateScroll}
93-
emptyMessage={<FormattedMessage id='empty_column.account_timeline' defaultMessage='No toots here!' />}
103+
emptyMessage={emptyMessage}
94104
/>
95105
</Column>
96106
);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ 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),
2324
});
2425

2526
export default @connect(mapStateToProps)
@@ -31,6 +32,7 @@ class Followers extends ImmutablePureComponent {
3132
shouldUpdateScroll: PropTypes.func,
3233
accountIds: ImmutablePropTypes.list,
3334
hasMore: PropTypes.bool,
35+
blockedBy: PropTypes.bool,
3436
};
3537

3638
componentWillMount () {
@@ -50,7 +52,7 @@ class Followers extends ImmutablePureComponent {
5052
}, 300, { leading: true });
5153

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

5557
if (!accountIds) {
5658
return (
@@ -60,7 +62,7 @@ class Followers extends ImmutablePureComponent {
6062
);
6163
}
6264

63-
const emptyMessage = <FormattedMessage id='account.followers.empty' defaultMessage='No one follows this user yet.' />;
65+
const emptyMessage = blockedBy ? <FormattedMessage id='empty_column.account_unavailable' defaultMessage='Profile unavailable' /> : <FormattedMessage id='account.followers.empty' defaultMessage='No one follows this user yet.' />;
6466

6567
return (
6668
<Column>
@@ -75,7 +77,7 @@ class Followers extends ImmutablePureComponent {
7577
alwaysPrepend
7678
emptyMessage={emptyMessage}
7779
>
78-
{accountIds.map(id =>
80+
{blockedBy ? [] : accountIds.map(id =>
7981
<AccountContainer key={id} id={id} withNote={false} />
8082
)}
8183
</ScrollableList>

0 commit comments

Comments
 (0)