forked from mastodon/mastodon
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
app/controllers/api/v1/statuses/mentioned_accounts_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# frozen_string_literal: true | ||
|
||
class Api::V1::Statuses::MentionedAccountsController < Api::BaseController | ||
include Authorization | ||
|
||
before_action -> { authorize_if_got_token! :read, :'read:accounts' } | ||
before_action :set_status | ||
after_action :insert_pagination_headers | ||
|
||
def index | ||
cache_if_unauthenticated! | ||
@accounts = load_accounts | ||
render json: @accounts, each_serializer: REST::AccountSerializer | ||
end | ||
|
||
private | ||
|
||
def load_accounts | ||
scope = default_accounts | ||
scope = scope.where.not(id: current_account.excluded_from_timeline_account_ids) unless current_account.nil? | ||
scope.merge(paginated_mentioned_users).to_a | ||
end | ||
|
||
def default_accounts | ||
Account | ||
.without_suspended | ||
.includes(:account_stat) | ||
.references(:favourites) | ||
.where(favourites: { status_id: @status.id }) | ||
end | ||
|
||
def paginated_favourites | ||
Favourite.paginate_by_max_id( | ||
limit_param(DEFAULT_ACCOUNTS_LIMIT), | ||
params[:max_id], | ||
params[:since_id] | ||
) | ||
end | ||
|
||
def insert_pagination_headers | ||
set_pagination_headers(next_path, prev_path) | ||
end | ||
|
||
def next_path | ||
api_v1_status_favourited_by_index_url pagination_params(max_id: pagination_max_id) if records_continue? | ||
end | ||
|
||
def prev_path | ||
api_v1_status_favourited_by_index_url pagination_params(since_id: pagination_since_id) unless @accounts.empty? | ||
end | ||
|
||
def pagination_max_id | ||
@accounts.last.favourites.last.id | ||
end | ||
|
||
def pagination_since_id | ||
@accounts.first.favourites.first.id | ||
end | ||
|
||
def records_continue? | ||
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT) | ||
end | ||
|
||
def set_status | ||
@status = Status.find(params[:status_id]) | ||
authorize @status, :show_mentioned_users? | ||
rescue Mastodon::NotPermittedError | ||
not_found | ||
end | ||
|
||
def pagination_params(core_params) | ||
params.slice(:limit).permit(:limit).merge(core_params) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
app/javascript/mastodon/features/mentioned_users/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import { injectIntl, FormattedMessage } from 'react-intl'; | ||
|
||
import { Helmet } from 'react-helmet'; | ||
|
||
import ImmutablePropTypes from 'react-immutable-proptypes'; | ||
import ImmutablePureComponent from 'react-immutable-pure-component'; | ||
import { connect } from 'react-redux'; | ||
|
||
import { debounce } from 'lodash'; | ||
|
||
import { fetchMentionedUsers, expandMentionedUsers } from 'mastodon/actions/interactions'; | ||
import ColumnHeader from 'mastodon/components/column_header'; | ||
import { LoadingIndicator } from 'mastodon/components/loading_indicator'; | ||
import ScrollableList from 'mastodon/components/scrollable_list'; | ||
import AccountContainer from 'mastodon/containers/account_container'; | ||
import Column from 'mastodon/features/ui/components/column'; | ||
|
||
const mapStateToProps = (state, props) => ({ | ||
accountIds: state.getIn(['user_lists', 'mentioned_users', props.params.statusId, 'items']), | ||
hasMore: !!state.getIn(['user_lists', 'mentioned_users', props.params.statusId, 'next']), | ||
isLoading: state.getIn(['user_lists', 'mentioned_users', props.params.statusId, 'isLoading'], true), | ||
}); | ||
|
||
class MentionedUsers extends ImmutablePureComponent { | ||
|
||
static propTypes = { | ||
params: PropTypes.object.isRequired, | ||
dispatch: PropTypes.func.isRequired, | ||
accountIds: ImmutablePropTypes.list, | ||
hasMore: PropTypes.bool, | ||
isLoading: PropTypes.bool, | ||
multiColumn: PropTypes.bool, | ||
intl: PropTypes.object.isRequired, | ||
}; | ||
|
||
UNSAFE_componentWillMount () { | ||
if (!this.props.accountIds) { | ||
this.props.dispatch(fetchMentionedUsers(this.props.params.statusId)); | ||
} | ||
} | ||
|
||
handleLoadMore = debounce(() => { | ||
this.props.dispatch(expandMentionedUsers(this.props.params.statusId)); | ||
}, 300, { leading: true }); | ||
|
||
render () { | ||
const { accountIds, hasMore, isLoading, multiColumn } = this.props; | ||
|
||
if (!accountIds) { | ||
return ( | ||
<Column> | ||
<LoadingIndicator /> | ||
</Column> | ||
); | ||
} | ||
|
||
const emptyMessage = <FormattedMessage id='empty_column.mentioned_users' defaultMessage='No one has been mentioned by this post.' />; | ||
|
||
return ( | ||
<Column bindToDocument={!multiColumn}> | ||
<ColumnHeader | ||
showBackButton | ||
multiColumn={multiColumn} | ||
/> | ||
|
||
<ScrollableList | ||
scrollKey='mentioned_users' | ||
onLoadMore={this.handleLoadMore} | ||
hasMore={hasMore} | ||
isLoading={isLoading} | ||
emptyMessage={emptyMessage} | ||
bindToDocument={!multiColumn} | ||
> | ||
{accountIds.map(id => | ||
<AccountContainer key={id} id={id} withNote={false} />, | ||
)} | ||
</ScrollableList> | ||
|
||
<Helmet> | ||
<meta name='robots' content='noindex' /> | ||
</Helmet> | ||
</Column> | ||
); | ||
} | ||
|
||
} | ||
|
||
export default connect(mapStateToProps)(injectIntl(MentionedUsers)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters