2016-11-16 02:56:29 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-01 05:42:08 +11:00
|
|
|
class AccountsController < ApplicationController
|
2020-06-09 08:18:47 +10:00
|
|
|
PAGE_SIZE = 20
|
|
|
|
PAGE_SIZE_MAX = 200
|
2018-02-26 13:31:28 +11:00
|
|
|
|
2017-04-19 21:52:37 +10:00
|
|
|
include AccountControllerConcern
|
2019-07-12 04:11:09 +10:00
|
|
|
include SignatureAuthentication
|
2018-01-04 11:21:38 +11:00
|
|
|
|
2020-09-14 21:04:29 +10:00
|
|
|
before_action :require_signature!, if: -> { request.format == :json && authorized_fetch_mode? }
|
2018-01-04 11:21:38 +11:00
|
|
|
before_action :set_cache_headers
|
2019-07-08 20:03:45 +10:00
|
|
|
before_action :set_body_classes
|
2016-03-01 05:42:08 +11:00
|
|
|
|
2020-02-20 08:31:53 +11:00
|
|
|
skip_around_action :set_locale, if: -> { [:json, :rss].include?(request.format&.to_sym) }
|
2020-06-20 03:18:47 +10:00
|
|
|
skip_before_action :require_functional!, unless: :whitelist_mode?
|
2019-08-12 06:59:40 +10:00
|
|
|
|
2016-03-01 05:42:08 +11:00
|
|
|
def show
|
|
|
|
respond_to do |format|
|
2016-09-09 04:36:01 +10:00
|
|
|
format.html do
|
2019-07-08 20:03:45 +10:00
|
|
|
expires_in 0, public: true unless user_signed_in?
|
2019-03-18 01:39:25 +11:00
|
|
|
|
2018-08-09 17:56:53 +10:00
|
|
|
@pinned_statuses = []
|
|
|
|
@endorsed_accounts = @account.endorsed_accounts.to_a.sample(4)
|
2019-08-18 02:07:52 +10:00
|
|
|
@featured_hashtags = @account.featured_tags.order(statuses_count: :desc)
|
2017-08-25 09:41:18 +10:00
|
|
|
|
2017-08-17 01:12:58 +10:00
|
|
|
if current_account && @account.blocking?(current_account)
|
|
|
|
@statuses = []
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-09-04 20:53:18 +10:00
|
|
|
@pinned_statuses = cache_collection(@account.pinned_statuses, Status) if show_pinned_statuses?
|
2020-05-04 00:30:36 +10:00
|
|
|
@statuses = filtered_status_page
|
2017-08-25 09:41:18 +10:00
|
|
|
@statuses = cache_collection(@statuses, Status)
|
2019-08-19 04:54:36 +10:00
|
|
|
@rss_url = rss_url
|
2018-04-25 10:10:02 +10:00
|
|
|
|
2018-02-26 13:31:28 +11:00
|
|
|
unless @statuses.empty?
|
2018-04-25 10:10:02 +10: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-26 13:31:28 +11:00
|
|
|
end
|
2016-09-09 04:36:01 +10:00
|
|
|
end
|
2016-03-24 23:21:53 +11:00
|
|
|
|
2018-04-25 10:10:02 +10:00
|
|
|
format.rss do
|
2019-10-03 02:30:33 +10:00
|
|
|
expires_in 1.minute, public: true
|
2019-03-18 01:39:25 +11:00
|
|
|
|
2020-06-09 08:18:47 +10:00
|
|
|
limit = params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE
|
|
|
|
@statuses = filtered_statuses.without_reblogs.limit(limit)
|
2019-08-19 04:54:36 +10:00
|
|
|
@statuses = cache_collection(@statuses, Status)
|
|
|
|
render xml: RSS::AccountSerializer.render(@account, @statuses, params[:tag])
|
2018-04-25 10:10:02 +10:00
|
|
|
end
|
|
|
|
|
2017-07-15 11:01:39 +10:00
|
|
|
format.json do
|
2019-07-12 04:11:09 +10:00
|
|
|
expires_in 3.minutes, public: !(authorized_fetch_mode? && signed_request_account.present?)
|
2020-09-14 21:04:29 +10:00
|
|
|
render_with_cache json: @account, content_type: 'application/activity+json', serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter
|
2017-07-15 11:01:39 +10:00
|
|
|
end
|
2016-03-01 05:42:08 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-07-08 20:03:45 +10:00
|
|
|
def set_body_classes
|
|
|
|
@body_classes = 'with-modals'
|
|
|
|
end
|
|
|
|
|
2017-09-04 20:53:18 +10:00
|
|
|
def show_pinned_statuses?
|
2019-02-05 10:27:18 +11:00
|
|
|
[replies_requested?, media_requested?, tag_requested?, params[:max_id].present?, params[:min_id].present?].none?
|
2017-09-04 20:53:18 +10:00
|
|
|
end
|
|
|
|
|
2017-08-17 01:12:58 +10:00
|
|
|
def filtered_statuses
|
|
|
|
default_statuses.tap do |statuses|
|
2019-02-04 14:25:59 +11:00
|
|
|
statuses.merge!(hashtag_scope) if tag_requested?
|
2017-08-25 09:41:18 +10:00
|
|
|
statuses.merge!(only_media_scope) if media_requested?
|
|
|
|
statuses.merge!(no_replies_scope) unless replies_requested?
|
2017-08-17 01:12:58 +10: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
|
Backport fixes to 3.2 (#15360)
* Fix 2FA/sign-in token sessions being valid after password change (#14802)
If someone tries logging in to an account and is prompted for a 2FA
code or sign-in token, even if the account's password or e-mail is
updated in the meantime, the session will show the prompt and allow
the login process to complete with a valid 2FA code or sign-in token
* Fix Move handler not being triggered when failing to fetch target (#15107)
When failing to fetch the target account, the ProcessingWorker fails
as expected, but since it hasn't cleared the `move_in_progress` flag,
the next attempt at processing skips the `Move` activity altogether.
This commit changes it to clear the flag when encountering any
unexpected error on fetching the target account. This is likely to
occur because, of, e.g., a timeout, when many instances query the
same actor at the same time.
* Fix slow distinct queries where grouped queries are faster (#15287)
About 2x speed-up on inboxes query
* Fix possible inconsistencies in tag search (#14906)
Do not downcase the queried tag before passing it to postgres when searching:
- tags are not downcased on creation
- `arel_table[:name].lower.matches(pattern)` generates an ILIKE anyway
- if Postgres and Rails happen to use different case-folding rules,
downcasing before query but not before insertion may mean that some
tags with some casings are not searchable
* Fix updating account counters when account_stat is not yet created (#15108)
* Fix account processing failing because of large collections (#15027)
Fixes #15025
* Fix downloading remote media files when server returns empty filename (#14867)
Fixes #14817
* Fix webfinger redirect handling in ResolveAccountService (#15187)
* Fix webfinger redirect handling in ResolveAccountService
ResolveAccountService#process_webfinger! handled a one-step webfinger
redirection, but only accepting the result if it matched the exact URI passed
as input, defeating the point of a redirection check.
Instead, use the same logic as in `ActivityPub::FetchRemoteAccountService`,
updating the resulting `acct:` URI with the result of the first webfinger
query.
* Add tests
* Remove dependency on unused and unmaintained http_parser.rb gem (#14574)
It seems that years ago, the “http” gem dependend on the “http_parser.rb” gem
(it now depends on the “http-parser” gem), and, still years ago, we pulled
it from git in order to benefit from a bugfix that wasn't released yet (#7467).
* Add tootctl maintenance fix-duplicates (#14860, #15201, #15264, #15349, #15359)
* Fix old migration script not being able to run if it fails midway (#15361)
* Fix old migration script not being able to run if it fails midway
Improve the robustness of a migration script likely to fail because of database
corruption so it can run again once database corruptions are fixed.
* Display a specific error message in case of index corruption
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
2020-12-19 09:31:14 +11:00
|
|
|
@account.media_attachments.attached.reorder(nil).select(:status_id).group(:status_id)
|
2017-08-17 01:12:58 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
def no_replies_scope
|
|
|
|
Status.without_replies
|
|
|
|
end
|
|
|
|
|
2019-02-04 14:25:59 +11:00
|
|
|
def hashtag_scope
|
2019-03-13 23:02:13 +11:00
|
|
|
tag = Tag.find_normalized(params[:tag])
|
|
|
|
|
|
|
|
if tag
|
|
|
|
Status.tagged_with(tag.id)
|
|
|
|
else
|
|
|
|
Status.none
|
|
|
|
end
|
2019-02-04 14:25:59 +11:00
|
|
|
end
|
|
|
|
|
2019-03-14 15:28:30 +11:00
|
|
|
def username_param
|
|
|
|
params[:username]
|
2016-03-01 05:42:08 +11:00
|
|
|
end
|
2017-08-17 01:12:58 +10:00
|
|
|
|
2019-08-19 04:54:36 +10: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-26 13:31:28 +11: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-04 14:25:59 +11:00
|
|
|
if tag_requested?
|
|
|
|
short_account_tag_url(@account, params[:tag], max_id: max_id, min_id: min_id)
|
|
|
|
elsif media_requested?
|
2018-02-26 13:31:28 +11:00
|
|
|
short_account_media_url(@account, max_id: max_id, min_id: min_id)
|
2017-08-25 09:41:18 +10:00
|
|
|
elsif replies_requested?
|
2018-02-26 13:31:28 +11:00
|
|
|
short_account_with_replies_url(@account, max_id: max_id, min_id: min_id)
|
2017-08-17 01:12:58 +10:00
|
|
|
else
|
2018-02-26 13:31:28 +11:00
|
|
|
short_account_url(@account, max_id: max_id, min_id: min_id)
|
2017-08-17 01:12:58 +10:00
|
|
|
end
|
|
|
|
end
|
2017-08-25 09:41:18 +10:00
|
|
|
|
|
|
|
def media_requested?
|
2020-05-04 06:19:24 +10:00
|
|
|
request.path.split('.').first.ends_with?('/media') && !tag_requested?
|
2017-08-25 09:41:18 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
def replies_requested?
|
2020-05-04 06:19:24 +10:00
|
|
|
request.path.split('.').first.ends_with?('/with_replies') && !tag_requested?
|
2017-08-25 09:41:18 +10:00
|
|
|
end
|
2018-02-26 13:31:28 +11:00
|
|
|
|
2019-02-04 14:25:59 +11:00
|
|
|
def tag_requested?
|
2019-08-19 04:54:36 +10:00
|
|
|
request.path.split('.').first.ends_with?(Addressable::URI.parse("/tagged/#{params[:tag]}").normalize)
|
2019-02-04 14:25:59 +11:00
|
|
|
end
|
|
|
|
|
2020-05-04 00:30:36 +10: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-26 13:31:28 +11:00
|
|
|
end
|
2016-03-01 05:42:08 +11:00
|
|
|
end
|