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.
 
 
 
 

53 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::CollectionsController < ActivityPub::BaseController
  3. include SignatureVerification
  4. include AccountOwnedConcern
  5. before_action :require_signature!, if: :authorized_fetch_mode?
  6. before_action :set_size
  7. before_action :set_statuses
  8. before_action :set_cache_headers
  9. def show
  10. expires_in 3.minutes, public: public_fetch_mode?
  11. render_with_cache json: collection_presenter, content_type: 'application/activity+json', serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, skip_activities: true
  12. end
  13. private
  14. def set_statuses
  15. @statuses = scope_for_collection
  16. @statuses = cache_collection(@statuses, Status)
  17. end
  18. def set_size
  19. case params[:id]
  20. when 'featured'
  21. @account.pinned_statuses.count
  22. else
  23. raise ActiveRecord::RecordNotFound
  24. end
  25. end
  26. def scope_for_collection
  27. case params[:id]
  28. when 'featured'
  29. @account.statuses.permitted_for(@account, signed_request_account).tap do |scope|
  30. scope.merge!(@account.pinned_statuses)
  31. end
  32. else
  33. raise ActiveRecord::RecordNotFound
  34. end
  35. end
  36. def collection_presenter
  37. ActivityPub::CollectionPresenter.new(
  38. id: account_collection_url(@account, params[:id]),
  39. type: :ordered,
  40. size: @size,
  41. items: @statuses
  42. )
  43. end
  44. end