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.

71 lines
2.0 KiB

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