logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

statuses_controller.rb (2632B)


  1. # frozen_string_literal: true
  2. class StatusesController < ApplicationController
  3. include SignatureAuthentication
  4. include Authorization
  5. ANCESTORS_LIMIT = 20
  6. layout 'public'
  7. before_action :set_account
  8. before_action :set_status
  9. before_action :set_link_headers
  10. before_action :check_account_suspension
  11. before_action :redirect_to_original, only: [:show]
  12. before_action :set_cache_headers
  13. def show
  14. respond_to do |format|
  15. format.html do
  16. @ancestors = @status.reply? ? cache_collection(@status.ancestors(ANCESTORS_LIMIT, current_account), Status) : []
  17. @next_ancestor = @ancestors.size < ANCESTORS_LIMIT ? nil : @ancestors.shift
  18. @descendants = cache_collection(@status.descendants(current_account), Status)
  19. render 'stream_entries/show'
  20. end
  21. format.json do
  22. skip_session! unless @stream_entry.hidden?
  23. render_cached_json(['activitypub', 'note', @status.cache_key], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do
  24. ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter)
  25. end
  26. end
  27. end
  28. end
  29. def activity
  30. skip_session!
  31. render_cached_json(['activitypub', 'activity', @status.cache_key], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do
  32. ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::ActivitySerializer, adapter: ActivityPub::Adapter)
  33. end
  34. end
  35. def embed
  36. response.headers['X-Frame-Options'] = 'ALLOWALL'
  37. render 'stream_entries/embed', layout: 'embedded'
  38. end
  39. private
  40. def set_account
  41. @account = Account.find_local!(params[:account_username])
  42. end
  43. def set_link_headers
  44. response.headers['Link'] = LinkHeader.new(
  45. [
  46. [account_stream_entry_url(@account, @status.stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]],
  47. [ActivityPub::TagManager.instance.uri_for(@status), [%w(rel alternate), %w(type application/activity+json)]],
  48. ]
  49. )
  50. end
  51. def set_status
  52. @status = @account.statuses.find(params[:id])
  53. @stream_entry = @status.stream_entry
  54. @type = @stream_entry.activity_type.downcase
  55. authorize @status, :show?
  56. rescue Mastodon::NotPermittedError
  57. # Reraise in order to get a 404
  58. raise ActiveRecord::RecordNotFound
  59. end
  60. def check_account_suspension
  61. gone if @account.suspended?
  62. end
  63. def redirect_to_original
  64. redirect_to ::TagManager.instance.url_for(@status.reblog) if @status.reblog?
  65. end
  66. end