logo

mastofe

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

collections_controller.rb (1358B)


  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. def show
  8. render json: collection_presenter,
  9. serializer: ActivityPub::CollectionSerializer,
  10. adapter: ActivityPub::Adapter,
  11. content_type: 'application/activity+json',
  12. skip_activities: true
  13. end
  14. private
  15. def set_account
  16. @account = Account.find_local!(params[:account_username])
  17. end
  18. def set_statuses
  19. @statuses = scope_for_collection.paginate_by_max_id(20, params[:max_id], params[:since_id])
  20. @statuses = cache_collection(@statuses, Status)
  21. end
  22. def set_size
  23. case params[:id]
  24. when 'featured'
  25. @account.pinned_statuses.count
  26. else
  27. raise ActiveRecord::NotFound
  28. end
  29. end
  30. def scope_for_collection
  31. case params[:id]
  32. when 'featured'
  33. @account.statuses.permitted_for(@account, signed_request_account).tap do |scope|
  34. scope.merge!(@account.pinned_statuses)
  35. end
  36. else
  37. raise ActiveRecord::NotFound
  38. end
  39. end
  40. def collection_presenter
  41. ActivityPub::CollectionPresenter.new(
  42. id: account_collection_url(@account, params[:id]),
  43. type: :ordered,
  44. size: @size,
  45. items: @statuses
  46. )
  47. end
  48. end