Skip to content

Commit

Permalink
Merge pull request #4 from TheEssem/feature/profile-limit-comment
Browse files Browse the repository at this point in the history
Show public limit comment on remote user profiles when their instance…
  • Loading branch information
alextecplayz authored Dec 7, 2024
2 parents d899150 + 3ac8910 commit 223f253
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/javascript/flavours/glitch/api_types/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface BaseApiAccountJSON {
moved?: ApiAccountJSON;
suspended?: boolean;
limited?: boolean;
remote_limit_reason?: string;
memorial?: boolean;
hide_collections: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,42 @@ import { Button } from 'flavours/glitch/components/button';
import { domain } from 'flavours/glitch/initial_state';
import { useAppDispatch } from 'flavours/glitch/store';

export const LimitedAccountHint: React.FC<{ accountId: string }> = ({
accountId,
}) => {
export const LimitedAccountHint: React.FC<{
accountId: string;
reason: string;
}> = ({ accountId, reason }) => {
const dispatch = useAppDispatch();
const reveal = useCallback(() => {
dispatch(revealAccount({ id: accountId }));
}, [dispatch, accountId]);

const message = reason ? (
<p>
<FormattedMessage
id='limited_account_hint.instance_limit.title'
defaultMessage='The server this profile is hosted on has been limited by the moderators of {domain}.'
values={{ domain }}
/>
<br />
<FormattedMessage
id='limited_account_hint.instance_limit.reason'
defaultMessage='Reason: {reason}'
values={{ reason }}
/>
</p>
) : (
<p>
<FormattedMessage
id='limited_account_hint.title'
defaultMessage='This profile has been hidden by the moderators of {domain}.'
values={{ domain }}
/>
</p>
);

return (
<div className='limited-account-hint'>
<p>
<FormattedMessage
id='limited_account_hint.title'
defaultMessage='This profile has been hidden by the moderators of {domain}.'
values={{ domain }}
/>
</p>
{message}
<Button onClick={reveal}>
<FormattedMessage
id='limited_account_hint.action'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const mapStateToProps = (state, { params: { acct, id, tagged }, withReplies = fa
hasMore: state.getIn(['timelines', `account:${path}`, 'hasMore']),
suspended: state.getIn(['accounts', accountId, 'suspended'], false),
hidden: getAccountHidden(state, accountId),
instanceHideReason: state.getIn(['accounts', accountId, 'remote_limit_reason']),
};
};

Expand Down Expand Up @@ -164,7 +165,7 @@ class AccountTimeline extends ImmutablePureComponent {
};

render () {
const { accountId, statusIds, featuredStatusIds, isLoading, hasMore, suspended, isAccount, hidden, multiColumn, remote, remoteUrl } = this.props;
const { accountId, statusIds, featuredStatusIds, isLoading, hasMore, suspended, isAccount, hidden, multiColumn, remote, remoteUrl, instanceHideReason } = this.props;

if (isLoading && statusIds.isEmpty()) {
return (
Expand All @@ -185,7 +186,7 @@ class AccountTimeline extends ImmutablePureComponent {
if (suspended) {
emptyMessage = <FormattedMessage id='empty_column.account_suspended' defaultMessage='Account suspended' />;
} else if (hidden) {
emptyMessage = <LimitedAccountHint accountId={accountId} />;
emptyMessage = <LimitedAccountHint accountId={accountId} reason={instanceHideReason} />;
} else if (remote && statusIds.isEmpty()) {
emptyMessage = <RemoteHint accountId={accountId} url={remoteUrl} />;
} else {
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/flavours/glitch/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"keyboard_shortcuts.bookmark": "to bookmark",
"keyboard_shortcuts.secondary_toot": "to send toot using secondary privacy setting",
"keyboard_shortcuts.toggle_collapse": "to collapse/uncollapse toots",
"limited_account_hint.instance_limit.title": "The server this profile is hosted on has been limited by the moderators of {domain}.",
"limited_account_hint.instance_limit.reason": "Reason: {reason}",
"moved_to_warning": "This account is marked as moved to {moved_to_link}, and may thus not accept new follows.",
"navigation_bar.app_settings": "App settings",
"navigation_bar.bubble_timeline": "Bubble timeline",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/flavours/glitch/models/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const accountDefaultValues: AccountShape = {
following_count: 0,
statuses_count: 0,
hidden: false,
remote_limit_reason: '',
suspended: false,
memorial: false,
limited: false,
Expand Down
7 changes: 7 additions & 0 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ def synchronization_uri_prefix
@synchronization_uri_prefix ||= "#{uri[URL_PREFIX_RE]}/"
end

def remote_limit_reason
domain_block = DomainBlock.find_by(domain: domain)
return if domain_block.nil? || domain_block.public_comment.empty?

domain_block.public_comment
end

class << self
def readonly_attributes
super - %w(statuses_count following_count followers_count)
Expand Down
5 changes: 5 additions & 0 deletions app/serializers/rest/account_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class REST::AccountSerializer < ActiveModel::Serializer

attribute :suspended, if: :suspended?
attribute :silenced, key: :limited, if: :silenced?
attribute :remote_limit_reason, if: :remote_limit_reason?
attribute :noindex, if: :local?

attribute :memorial, if: :memorial?
Expand Down Expand Up @@ -161,4 +162,8 @@ def noindex
def moved_and_not_nested?
object.moved?
end

def remote_limit_reason?
object.silenced? && object.pretty_acct != object.username
end
end

0 comments on commit 223f253

Please sign in to comment.