1
0

pins_controller.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. class Api::V1::Statuses::PinsController < Api::V1::Statuses::BaseController
  3. before_action -> { doorkeeper_authorize! :write, :'write:accounts' }
  4. before_action :require_user!
  5. def create
  6. StatusPin.create!(account: current_account, status: @status)
  7. distribute_add_activity!
  8. render json: @status, serializer: REST::StatusSerializer
  9. end
  10. def destroy
  11. pin = StatusPin.find_by(account: current_account, status: @status)
  12. if pin
  13. pin.destroy!
  14. distribute_remove_activity!
  15. end
  16. render json: @status, serializer: REST::StatusSerializer
  17. end
  18. private
  19. def distribute_add_activity!
  20. json = ActiveModelSerializers::SerializableResource.new(
  21. @status,
  22. serializer: ActivityPub::AddSerializer,
  23. adapter: ActivityPub::Adapter
  24. ).as_json
  25. ActivityPub::RawDistributionWorker.perform_async(Oj.dump(json), current_account.id)
  26. end
  27. def distribute_remove_activity!
  28. json = ActiveModelSerializers::SerializableResource.new(
  29. @status,
  30. serializer: ActivityPub::RemoveSerializer,
  31. adapter: ActivityPub::Adapter
  32. ).as_json
  33. ActivityPub::RawDistributionWorker.perform_async(Oj.dump(json), current_account.id)
  34. end
  35. end