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.

57 lines
1.6 KiB

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