]> cat aescling's git repositories - mastodon.git/blob - app/controllers/statuses_controller.rb
Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master
[mastodon.git] / app / controllers / statuses_controller.rb
1 # frozen_string_literal: true
2
3 class StatusesController < ApplicationController
4 include SignatureAuthentication
5 include Authorization
6
7 layout 'public'
8
9 before_action :set_account
10 before_action :set_status
11 before_action :set_link_headers
12 before_action :check_account_suspension
13 before_action :redirect_to_original, only: [:show]
14 before_action :set_cache_headers
15
16 def show
17 respond_to do |format|
18 format.html do
19 use_pack 'public'
20 @ancestors = @status.reply? ? cache_collection(@status.ancestors(current_account), Status) : []
21 @descendants = cache_collection(@status.descendants(current_account), Status)
22
23 render 'stream_entries/show'
24 end
25
26 format.json do
27 skip_session! unless @stream_entry.hidden?
28
29 render_cached_json(['activitypub', 'note', @status.cache_key], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do
30 ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter)
31 end
32 end
33 end
34 end
35
36 def activity
37 skip_session!
38
39 render_cached_json(['activitypub', 'activity', @status.cache_key], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do
40 ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::ActivitySerializer, adapter: ActivityPub::Adapter)
41 end
42 end
43
44 def embed
45 use_pack 'embed'
46 response.headers['X-Frame-Options'] = 'ALLOWALL'
47 render 'stream_entries/embed', layout: 'embedded'
48 end
49
50 private
51
52 def set_account
53 @account = Account.find_local!(params[:account_username])
54 end
55
56 def set_link_headers
57 response.headers['Link'] = LinkHeader.new(
58 [
59 [account_stream_entry_url(@account, @status.stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]],
60 [ActivityPub::TagManager.instance.uri_for(@status), [%w(rel alternate), %w(type application/activity+json)]],
61 ]
62 )
63 end
64
65 def set_status
66 @status = @account.statuses.find(params[:id])
67 @stream_entry = @status.stream_entry
68 @type = @stream_entry.activity_type.downcase
69
70 authorize @status, :show?
71 rescue Mastodon::NotPermittedError
72 # Reraise in order to get a 404
73 raise ActiveRecord::RecordNotFound
74 end
75
76 def check_account_suspension
77 gone if @account.suspended?
78 end
79
80 def redirect_to_original
81 redirect_to ::TagManager.instance.url_for(@status.reblog) if @status.reblog?
82 end
83 end
This page took 0.091188 seconds and 4 git commands to generate.