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.

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