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.

54 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. respond_to :json
  8. def create
  9. StatusPin.create!(account: current_account, status: @status)
  10. distribute_add_activity!
  11. render json: @status, serializer: REST::StatusSerializer
  12. end
  13. def destroy
  14. pin = StatusPin.find_by(account: current_account, status: @status)
  15. if pin
  16. pin.destroy!
  17. distribute_remove_activity!
  18. end
  19. render json: @status, serializer: REST::StatusSerializer
  20. end
  21. private
  22. def set_status
  23. @status = Status.find(params[:status_id])
  24. end
  25. def distribute_add_activity!
  26. json = ActiveModelSerializers::SerializableResource.new(
  27. @status,
  28. serializer: ActivityPub::AddSerializer,
  29. adapter: ActivityPub::Adapter
  30. ).as_json
  31. ActivityPub::RawDistributionWorker.perform_async(Oj.dump(json), current_account.id)
  32. end
  33. def distribute_remove_activity!
  34. json = ActiveModelSerializers::SerializableResource.new(
  35. @status,
  36. serializer: ActivityPub::RemoveSerializer,
  37. adapter: ActivityPub::Adapter
  38. ).as_json
  39. ActivityPub::RawDistributionWorker.perform_async(Oj.dump(json), current_account.id)
  40. end
  41. end