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.

65 lines
1.9 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. before_action :set_cache_headers
  11. def show
  12. respond_to do |format|
  13. format.html do
  14. @ancestors = @stream_entry.activity.reply? ? cache_collection(@stream_entry.activity.ancestors(current_account), Status) : []
  15. @descendants = cache_collection(@stream_entry.activity.descendants(current_account), Status)
  16. end
  17. format.atom do
  18. unless @stream_entry.hidden?
  19. skip_session!
  20. expires_in 3.minutes, public: true
  21. end
  22. render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.entry(@stream_entry, true))
  23. end
  24. end
  25. end
  26. def embed
  27. redirect_to embed_short_account_status_url(@account, @stream_entry.activity), status: 301
  28. end
  29. private
  30. def set_account
  31. @account = Account.find_local!(params[:account_username])
  32. end
  33. def set_link_headers
  34. response.headers['Link'] = LinkHeader.new(
  35. [
  36. [account_stream_entry_url(@account, @stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]],
  37. [ActivityPub::TagManager.instance.uri_for(@stream_entry.activity), [%w(rel alternate), %w(type application/activity+json)]],
  38. ]
  39. )
  40. end
  41. def set_stream_entry
  42. @stream_entry = @account.stream_entries.where(activity_type: 'Status').find(params[:id])
  43. @type = @stream_entry.activity_type.downcase
  44. raise ActiveRecord::RecordNotFound if @stream_entry.activity.nil?
  45. authorize @stream_entry.activity, :show? if @stream_entry.hidden?
  46. rescue Mastodon::NotPermittedError
  47. # Reraise in order to get a 404
  48. raise ActiveRecord::RecordNotFound
  49. end
  50. def check_account_suspension
  51. gone if @account.suspended?
  52. end
  53. end