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

56 lines
1.5 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. def show
  10. respond_to do |format|
  11. format.html do
  12. @ancestors = @status.reply? ? cache_collection(@status.ancestors(current_account), Status) : []
  13. @descendants = cache_collection(@status.descendants(current_account), Status)
  14. render 'stream_entries/show'
  15. end
  16. format.json do
  17. render json: @status, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter
  18. end
  19. end
  20. end
  21. def activity
  22. render json: @status, serializer: ActivityPub::ActivitySerializer, adapter: ActivityPub::Adapter
  23. end
  24. private
  25. def set_account
  26. @account = Account.find_local!(params[:account_username])
  27. end
  28. def set_link_headers
  29. response.headers['Link'] = LinkHeader.new([[account_stream_entry_url(@account, @status.stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]]])
  30. end
  31. def set_status
  32. @status = @account.statuses.find(params[:id])
  33. @stream_entry = @status.stream_entry
  34. @type = @stream_entry.activity_type.downcase
  35. authorize @status, :show?
  36. rescue Mastodon::NotPermittedError
  37. # Reraise in order to get a 404
  38. raise ActiveRecord::RecordNotFound
  39. end
  40. def check_account_suspension
  41. gone if @account.suspended?
  42. end
  43. end