You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.4 KiB

  1. # frozen_string_literal: true
  2. class StatusesController < ApplicationController
  3. include SignatureAuthentication
  4. include Authorization
  5. layout 'public'
  6. before_action :set_account
  7. before_action :set_status
  8. before_action :set_link_headers
  9. before_action :check_account_suspension
  10. before_action :redirect_to_original, only: [:show]
  11. before_action :set_cache_headers
  12. def show
  13. respond_to do |format|
  14. format.html do
  15. @ancestors = @status.reply? ? cache_collection(@status.ancestors(current_account), Status) : []
  16. @descendants = cache_collection(@status.descendants(current_account), Status)
  17. render 'stream_entries/show'
  18. end
  19. format.json do
  20. skip_session! unless @stream_entry.hidden?
  21. render_cached_json(['activitypub', 'note', @status.cache_key], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do
  22. ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter)
  23. end
  24. end
  25. end
  26. end
  27. def activity
  28. skip_session!
  29. render_cached_json(['activitypub', 'activity', @status.cache_key], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do
  30. ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::ActivitySerializer, adapter: ActivityPub::Adapter)
  31. end
  32. end
  33. def embed
  34. response.headers['X-Frame-Options'] = 'ALLOWALL'
  35. render 'stream_entries/embed', layout: 'embedded'
  36. end
  37. private
  38. def set_account
  39. @account = Account.find_local!(params[:account_username])
  40. end
  41. def set_link_headers
  42. response.headers['Link'] = LinkHeader.new(
  43. [
  44. [account_stream_entry_url(@account, @status.stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]],
  45. [ActivityPub::TagManager.instance.uri_for(@status), [%w(rel alternate), %w(type application/activity+json)]],
  46. ]
  47. )
  48. end
  49. def set_status
  50. @status = @account.statuses.find(params[:id])
  51. @stream_entry = @status.stream_entry
  52. @type = @stream_entry.activity_type.downcase
  53. authorize @status, :show?
  54. rescue Mastodon::NotPermittedError
  55. # Reraise in order to get a 404
  56. raise ActiveRecord::RecordNotFound
  57. end
  58. def check_account_suspension
  59. gone if @account.suspended?
  60. end
  61. def redirect_to_original
  62. redirect_to ::TagManager.instance.url_for(@status.reblog) if @status.reblog?
  63. end
  64. end