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.

58 lines
1.7 KiB

  1. # frozen_string_literal: true
  2. class StreamEntriesController < ApplicationController
  3. include Authorization
  4. include SignatureVerification
  5. layout 'public'
  6. before_action :set_account
  7. before_action :set_stream_entry
  8. before_action :set_link_headers
  9. before_action :check_account_suspension
  10. def show
  11. respond_to do |format|
  12. format.html do
  13. @ancestors = @stream_entry.activity.reply? ? cache_collection(@stream_entry.activity.ancestors(current_account), Status) : []
  14. @descendants = cache_collection(@stream_entry.activity.descendants(current_account), Status)
  15. end
  16. format.atom do
  17. render xml: Ostatus::AtomSerializer.render(Ostatus::AtomSerializer.new.entry(@stream_entry, true))
  18. end
  19. end
  20. end
  21. def embed
  22. response.headers['X-Frame-Options'] = 'ALLOWALL'
  23. return gone if @stream_entry.activity.nil?
  24. render layout: 'embedded'
  25. end
  26. private
  27. def set_account
  28. @account = Account.find_local!(params[:account_username])
  29. end
  30. def set_link_headers
  31. response.headers['Link'] = LinkHeader.new([[account_stream_entry_url(@account, @stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
  32. end
  33. def set_stream_entry
  34. @stream_entry = @account.stream_entries.where(activity_type: 'Status').find(params[:id])
  35. @type = @stream_entry.activity_type.downcase
  36. raise ActiveRecord::RecordNotFound if @stream_entry.activity.nil?
  37. authorize @stream_entry.activity, :show? if @stream_entry.hidden?
  38. rescue Mastodon::NotPermittedError
  39. # Reraise in order to get a 404
  40. raise ActiveRecord::RecordNotFound
  41. end
  42. def check_account_suspension
  43. gone if @account.suspended?
  44. end
  45. end