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.

52 lines
1.3 KiB

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