The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

78 lines
2.1 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. before_action :redirect_to_original, only: [:show]
  10. def show
  11. respond_to do |format|
  12. format.html do
  13. @ancestors = @status.reply? ? cache_collection(@status.ancestors(current_account), Status) : []
  14. @descendants = cache_collection(@status.descendants(current_account), Status)
  15. render 'stream_entries/show'
  16. end
  17. format.json do
  18. render json: @status,
  19. serializer: ActivityPub::NoteSerializer,
  20. adapter: ActivityPub::Adapter,
  21. content_type: 'application/activity+json'
  22. end
  23. end
  24. end
  25. def activity
  26. render json: @status,
  27. serializer: ActivityPub::ActivitySerializer,
  28. adapter: ActivityPub::Adapter,
  29. content_type: 'application/activity+json'
  30. end
  31. def embed
  32. response.headers['X-Frame-Options'] = 'ALLOWALL'
  33. render 'stream_entries/embed', layout: 'embedded'
  34. end
  35. private
  36. def set_account
  37. @account = Account.find_local!(params[:account_username])
  38. end
  39. def set_link_headers
  40. response.headers['Link'] = LinkHeader.new(
  41. [
  42. [account_stream_entry_url(@account, @status.stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]],
  43. [ActivityPub::TagManager.instance.uri_for(@status), [%w(rel alternate), %w(type application/activity+json)]],
  44. ]
  45. )
  46. end
  47. def set_status
  48. @status = @account.statuses.find(params[:id])
  49. @stream_entry = @status.stream_entry
  50. @type = @stream_entry.activity_type.downcase
  51. authorize @status, :show?
  52. rescue Mastodon::NotPermittedError
  53. # Reraise in order to get a 404
  54. raise ActiveRecord::RecordNotFound
  55. end
  56. def check_account_suspension
  57. gone if @account.suspended?
  58. end
  59. def redirect_to_original
  60. redirect_to ::TagManager.instance.url_for(@status.reblog) if @status.reblog?
  61. end
  62. end