1
0

unfavourite_service.rb 641 B

1234567891011121314151617181920212223
  1. # frozen_string_literal: true
  2. class UnfavouriteService < BaseService
  3. include Payloadable
  4. def call(account, status)
  5. favourite = Favourite.find_by!(account: account, status: status)
  6. favourite.destroy!
  7. create_notification(favourite) if !status.account.local? && status.account.activitypub?
  8. favourite
  9. end
  10. private
  11. def create_notification(favourite)
  12. status = favourite.status
  13. ActivityPub::DeliveryWorker.perform_async(build_json(favourite), favourite.account_id, status.account.inbox_url)
  14. end
  15. def build_json(favourite)
  16. Oj.dump(serialize_payload(favourite, ActivityPub::UndoLikeSerializer))
  17. end
  18. end