闭社主体 forked from https://github.com/tootsuite/mastodon
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.

55 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. class StreamEntriesController < ApplicationController
  3. layout 'public'
  4. before_action :set_account
  5. before_action :set_stream_entry
  6. before_action :set_link_headers
  7. before_action :check_account_suspension
  8. def show
  9. respond_to do |format|
  10. format.html do
  11. return gone if @stream_entry.activity.nil?
  12. if @stream_entry.activity_type == 'Status'
  13. @ancestors = @stream_entry.activity.ancestors(current_account)
  14. @descendants = @stream_entry.activity.descendants(current_account)
  15. end
  16. end
  17. format.atom
  18. end
  19. end
  20. def embed
  21. response.headers['X-Frame-Options'] = 'ALLOWALL'
  22. @external_links = true
  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.find(params[:id])
  35. @type = @stream_entry.activity_type.downcase
  36. raise ActiveRecord::RecordNotFound if @stream_entry.activity.nil? || (@stream_entry.hidden? && (@stream_entry.activity_type != 'Status' || (@stream_entry.activity_type == 'Status' && !@stream_entry.activity.permitted?(current_account))))
  37. end
  38. def check_account_suspension
  39. head 410 if @account.suspended?
  40. end
  41. end