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.

61 lines
1.4 KiB

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