闭社主体 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.

57 lines
1.7 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.reply? ? cache_collection(@stream_entry.activity.ancestors(current_account), Status) : []
  14. @descendants = cache_collection(@stream_entry.activity.descendants(current_account), Status)
  15. end
  16. end
  17. format.atom do
  18. render xml: AtomSerializer.render(AtomSerializer.new.entry(@stream_entry, true))
  19. end
  20. end
  21. end
  22. def embed
  23. response.headers['X-Frame-Options'] = 'ALLOWALL'
  24. @external_links = true
  25. return gone if @stream_entry.activity.nil?
  26. render layout: 'embedded'
  27. end
  28. private
  29. def set_account
  30. @account = Account.find_local!(params[:account_username])
  31. end
  32. def set_link_headers
  33. response.headers['Link'] = LinkHeader.new([[account_stream_entry_url(@account, @stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
  34. end
  35. def set_stream_entry
  36. @stream_entry = @account.stream_entries.where(activity_type: 'Status').find(params[:id])
  37. @type = @stream_entry.activity_type.downcase
  38. 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))))
  39. end
  40. def check_account_suspension
  41. gone if @account.suspended?
  42. end
  43. end