2017-03-22 14:26:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusesController < ApplicationController
|
2022-10-20 08:35:29 -04:00
|
|
|
include WebAppControllerConcern
|
2018-02-02 04:19:59 -05:00
|
|
|
include SignatureAuthentication
|
2017-05-29 12:22:22 -04:00
|
|
|
include Authorization
|
2019-07-08 06:03:45 -04:00
|
|
|
include AccountOwnedConcern
|
2017-03-22 14:26:22 -04:00
|
|
|
|
2023-04-23 16:27:24 -04:00
|
|
|
vary_by -> { public_fetch_mode? ? 'Accept, Accept-Language, Cookie' : 'Accept, Accept-Language, Cookie, Signature' }
|
2023-04-19 10:07:29 -04:00
|
|
|
|
2022-09-21 16:45:57 -04:00
|
|
|
before_action :require_account_signature!, only: [:show, :activity], if: -> { request.format == :json && authorized_fetch_mode? }
|
2017-03-22 14:26:22 -04:00
|
|
|
before_action :set_status
|
2019-07-11 14:11:09 -04:00
|
|
|
before_action :redirect_to_original, only: :show
|
2017-03-22 14:26:22 -04:00
|
|
|
|
2023-03-25 19:40:01 -04:00
|
|
|
after_action :set_link_headers
|
|
|
|
|
2019-08-11 16:59:40 -04:00
|
|
|
skip_around_action :set_locale, if: -> { request.format == :json }
|
2023-08-02 13:32:48 -04:00
|
|
|
skip_before_action :require_functional!, only: [:show, :embed], unless: :limited_federation_mode?
|
2019-08-11 16:59:40 -04:00
|
|
|
|
2022-12-15 11:11:58 -05:00
|
|
|
content_security_policy only: :embed do |policy|
|
|
|
|
policy.frame_ancestors(false)
|
2018-10-11 14:35:46 -04:00
|
|
|
end
|
|
|
|
|
2017-03-22 14:26:22 -04:00
|
|
|
def show
|
2017-07-14 21:01:39 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2019-06-05 08:02:59 -04:00
|
|
|
expires_in 10.seconds, public: true if current_account.nil?
|
2017-07-14 21:01:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
format.json do
|
2023-04-23 16:27:24 -04:00
|
|
|
expires_in 3.minutes, public: true if @status.distributable? && public_fetch_mode?
|
2019-07-21 16:32:16 -04:00
|
|
|
render_with_cache json: @status, content_type: 'application/activity+json', serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter
|
2017-07-14 21:01:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-22 14:26:22 -04:00
|
|
|
|
2017-07-14 21:01:39 -04:00
|
|
|
def activity
|
2019-07-11 14:11:09 -04:00
|
|
|
expires_in 3.minutes, public: @status.distributable? && public_fetch_mode?
|
2020-06-02 13:24:53 -04:00
|
|
|
render_with_cache json: ActivityPub::ActivityPresenter.from_status(@status), content_type: 'application/activity+json', serializer: ActivityPub::ActivitySerializer, adapter: ActivityPub::Adapter
|
2017-03-22 14:26:22 -04:00
|
|
|
end
|
|
|
|
|
2017-08-30 04:23:43 -04:00
|
|
|
def embed
|
2020-05-03 10:30:36 -04:00
|
|
|
return not_found if @status.hidden? || @status.reblog?
|
2018-06-30 22:12:34 -04:00
|
|
|
|
|
|
|
expires_in 180, public: true
|
2023-05-23 08:27:17 -04:00
|
|
|
response.headers.delete('X-Frame-Options')
|
2018-06-30 22:12:34 -04:00
|
|
|
|
2019-07-07 10:16:51 -04:00
|
|
|
render layout: 'embedded'
|
2017-08-30 04:23:43 -04:00
|
|
|
end
|
|
|
|
|
2017-03-22 14:26:22 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_link_headers
|
2024-09-05 16:05:38 -04:00
|
|
|
response.headers['Link'] = LinkHeader.new(
|
|
|
|
[[ActivityPub::TagManager.instance.uri_for(@status), [%w(rel alternate), %w(type application/activity+json)]]]
|
|
|
|
).to_s
|
2017-03-22 14:26:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_status
|
2019-07-07 10:16:51 -04:00
|
|
|
@status = @account.statuses.find(params[:id])
|
2017-05-29 12:22:22 -04:00
|
|
|
authorize @status, :show?
|
|
|
|
rescue Mastodon::NotPermittedError
|
2020-01-23 18:20:51 -05:00
|
|
|
not_found
|
2017-03-22 14:26:22 -04:00
|
|
|
end
|
|
|
|
|
2017-08-24 10:21:42 -04:00
|
|
|
def redirect_to_original
|
2023-03-25 19:38:32 -04:00
|
|
|
redirect_to(ActivityPub::TagManager.instance.url_for(@status.reblog), allow_other_host: true) if @status.reblog?
|
2017-08-24 10:21:42 -04:00
|
|
|
end
|
2017-03-22 14:26:22 -04:00
|
|
|
end
|