2016-11-15 10:56:29 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-29 13:42:08 -05:00
|
|
|
class AccountsController < ApplicationController
|
2020-06-08 18:18:47 -04:00
|
|
|
PAGE_SIZE = 20
|
|
|
|
PAGE_SIZE_MAX = 200
|
2018-02-25 21:31:28 -05:00
|
|
|
|
2017-04-19 07:52:37 -04:00
|
|
|
include AccountControllerConcern
|
2019-07-11 14:11:09 -04:00
|
|
|
include SignatureAuthentication
|
2018-01-03 19:21:38 -05:00
|
|
|
|
|
|
|
before_action :set_cache_headers
|
2019-07-08 06:03:45 -04:00
|
|
|
before_action :set_body_classes
|
2016-02-29 13:42:08 -05:00
|
|
|
|
2020-02-19 16:31:53 -05:00
|
|
|
skip_around_action :set_locale, if: -> { [:json, :rss].include?(request.format&.to_sym) }
|
2019-09-27 19:33:27 -04:00
|
|
|
skip_before_action :require_functional!
|
2019-08-11 16:59:40 -04:00
|
|
|
|
2016-02-29 13:42:08 -05:00
|
|
|
def show
|
|
|
|
respond_to do |format|
|
2016-09-08 14:36:01 -04:00
|
|
|
format.html do
|
2019-07-08 06:03:45 -04:00
|
|
|
expires_in 0, public: true unless user_signed_in?
|
2019-03-17 10:39:25 -04:00
|
|
|
|
2018-08-09 03:56:53 -04:00
|
|
|
@pinned_statuses = []
|
|
|
|
@endorsed_accounts = @account.endorsed_accounts.to_a.sample(4)
|
2019-08-17 12:07:52 -04:00
|
|
|
@featured_hashtags = @account.featured_tags.order(statuses_count: :desc)
|
2017-08-24 19:41:18 -04:00
|
|
|
|
2017-08-16 11:12:58 -04:00
|
|
|
if current_account && @account.blocking?(current_account)
|
|
|
|
@statuses = []
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-09-04 06:53:18 -04:00
|
|
|
@pinned_statuses = cache_collection(@account.pinned_statuses, Status) if show_pinned_statuses?
|
2020-05-03 10:30:36 -04:00
|
|
|
@statuses = filtered_status_page
|
2017-08-24 19:41:18 -04:00
|
|
|
@statuses = cache_collection(@statuses, Status)
|
2019-08-18 14:54:36 -04:00
|
|
|
@rss_url = rss_url
|
2018-04-24 20:10:02 -04:00
|
|
|
|
2018-02-25 21:31:28 -05:00
|
|
|
unless @statuses.empty?
|
2018-04-24 20:10:02 -04:00
|
|
|
@older_url = older_url if @statuses.last.id > filtered_statuses.last.id
|
|
|
|
@newer_url = newer_url if @statuses.first.id < filtered_statuses.first.id
|
2018-02-25 21:31:28 -05:00
|
|
|
end
|
2016-09-08 14:36:01 -04:00
|
|
|
end
|
2016-03-24 08:21:53 -04:00
|
|
|
|
2018-04-24 20:10:02 -04:00
|
|
|
format.rss do
|
2019-10-02 12:30:33 -04:00
|
|
|
expires_in 1.minute, public: true
|
2019-03-17 10:39:25 -04:00
|
|
|
|
2020-06-08 18:18:47 -04:00
|
|
|
limit = params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE
|
|
|
|
@statuses = filtered_statuses.without_reblogs.limit(limit)
|
2019-08-18 14:54:36 -04:00
|
|
|
@statuses = cache_collection(@statuses, Status)
|
|
|
|
render xml: RSS::AccountSerializer.render(@account, @statuses, params[:tag])
|
2018-04-24 20:10:02 -04:00
|
|
|
end
|
|
|
|
|
2017-07-14 21:01:39 -04:00
|
|
|
format.json do
|
2019-07-11 14:11:09 -04:00
|
|
|
expires_in 3.minutes, public: !(authorized_fetch_mode? && signed_request_account.present?)
|
2019-07-21 16:32:16 -04:00
|
|
|
render_with_cache json: @account, content_type: 'application/activity+json', serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter, fields: restrict_fields_to
|
2017-07-14 21:01:39 -04:00
|
|
|
end
|
2016-02-29 13:42:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-07-08 06:03:45 -04:00
|
|
|
def set_body_classes
|
|
|
|
@body_classes = 'with-modals'
|
|
|
|
end
|
|
|
|
|
2017-09-04 06:53:18 -04:00
|
|
|
def show_pinned_statuses?
|
2019-02-04 18:27:18 -05:00
|
|
|
[replies_requested?, media_requested?, tag_requested?, params[:max_id].present?, params[:min_id].present?].none?
|
2017-09-04 06:53:18 -04:00
|
|
|
end
|
|
|
|
|
2017-08-16 11:12:58 -04:00
|
|
|
def filtered_statuses
|
|
|
|
default_statuses.tap do |statuses|
|
2019-02-03 22:25:59 -05:00
|
|
|
statuses.merge!(hashtag_scope) if tag_requested?
|
2017-08-24 19:41:18 -04:00
|
|
|
statuses.merge!(only_media_scope) if media_requested?
|
|
|
|
statuses.merge!(no_replies_scope) unless replies_requested?
|
2017-08-16 11:12:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_statuses
|
|
|
|
@account.statuses.where(visibility: [:public, :unlisted])
|
|
|
|
end
|
|
|
|
|
|
|
|
def only_media_scope
|
|
|
|
Status.where(id: account_media_status_ids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def account_media_status_ids
|
|
|
|
@account.media_attachments.attached.reorder(nil).select(:status_id).distinct
|
|
|
|
end
|
|
|
|
|
|
|
|
def no_replies_scope
|
|
|
|
Status.without_replies
|
|
|
|
end
|
|
|
|
|
2019-02-03 22:25:59 -05:00
|
|
|
def hashtag_scope
|
2019-03-13 08:02:13 -04:00
|
|
|
tag = Tag.find_normalized(params[:tag])
|
|
|
|
|
|
|
|
if tag
|
|
|
|
Status.tagged_with(tag.id)
|
|
|
|
else
|
|
|
|
Status.none
|
|
|
|
end
|
2019-02-03 22:25:59 -05:00
|
|
|
end
|
|
|
|
|
2019-03-14 00:28:30 -04:00
|
|
|
def username_param
|
|
|
|
params[:username]
|
2016-02-29 13:42:08 -05:00
|
|
|
end
|
2017-08-16 11:12:58 -04:00
|
|
|
|
2019-08-18 14:54:36 -04:00
|
|
|
def rss_url
|
|
|
|
if tag_requested?
|
|
|
|
short_account_tag_url(@account, params[:tag], format: 'rss')
|
|
|
|
else
|
|
|
|
short_account_url(@account, format: 'rss')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-25 21:31:28 -05:00
|
|
|
def older_url
|
|
|
|
pagination_url(max_id: @statuses.last.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def newer_url
|
|
|
|
pagination_url(min_id: @statuses.first.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def pagination_url(max_id: nil, min_id: nil)
|
2019-02-03 22:25:59 -05:00
|
|
|
if tag_requested?
|
|
|
|
short_account_tag_url(@account, params[:tag], max_id: max_id, min_id: min_id)
|
|
|
|
elsif media_requested?
|
2018-02-25 21:31:28 -05:00
|
|
|
short_account_media_url(@account, max_id: max_id, min_id: min_id)
|
2017-08-24 19:41:18 -04:00
|
|
|
elsif replies_requested?
|
2018-02-25 21:31:28 -05:00
|
|
|
short_account_with_replies_url(@account, max_id: max_id, min_id: min_id)
|
2017-08-16 11:12:58 -04:00
|
|
|
else
|
2018-02-25 21:31:28 -05:00
|
|
|
short_account_url(@account, max_id: max_id, min_id: min_id)
|
2017-08-16 11:12:58 -04:00
|
|
|
end
|
|
|
|
end
|
2017-08-24 19:41:18 -04:00
|
|
|
|
|
|
|
def media_requested?
|
2020-05-03 16:19:24 -04:00
|
|
|
request.path.split('.').first.ends_with?('/media') && !tag_requested?
|
2017-08-24 19:41:18 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def replies_requested?
|
2020-05-03 16:19:24 -04:00
|
|
|
request.path.split('.').first.ends_with?('/with_replies') && !tag_requested?
|
2017-08-24 19:41:18 -04:00
|
|
|
end
|
2018-02-25 21:31:28 -05:00
|
|
|
|
2019-02-03 22:25:59 -05:00
|
|
|
def tag_requested?
|
2019-08-18 14:54:36 -04:00
|
|
|
request.path.split('.').first.ends_with?(Addressable::URI.parse("/tagged/#{params[:tag]}").normalize)
|
2019-02-03 22:25:59 -05:00
|
|
|
end
|
|
|
|
|
2020-05-03 10:30:36 -04:00
|
|
|
def filtered_status_page
|
|
|
|
filtered_statuses.paginate_by_id(PAGE_SIZE, params_slice(:max_id, :min_id, :since_id))
|
|
|
|
end
|
|
|
|
|
|
|
|
def params_slice(*keys)
|
|
|
|
params.slice(*keys).permit(*keys)
|
2018-02-25 21:31:28 -05:00
|
|
|
end
|
2019-07-11 14:11:09 -04:00
|
|
|
|
|
|
|
def restrict_fields_to
|
|
|
|
if signed_request_account.present? || public_fetch_mode?
|
|
|
|
# Return all fields
|
|
|
|
else
|
|
|
|
%i(id type preferred_username inbox public_key endpoints)
|
|
|
|
end
|
|
|
|
end
|
2016-02-29 13:42:08 -05:00
|
|
|
end
|