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.

31 lines
907 B

  1. # frozen_string_literal: true
  2. class UnblockService < BaseService
  3. include Payloadable
  4. def call(account, target_account)
  5. return unless account.blocking?(target_account)
  6. unblock = account.unblock!(target_account)
  7. create_notification(unblock) unless target_account.local?
  8. unblock
  9. end
  10. private
  11. def create_notification(unblock)
  12. if unblock.target_account.ostatus?
  13. NotificationWorker.perform_async(build_xml(unblock), unblock.account_id, unblock.target_account_id)
  14. elsif unblock.target_account.activitypub?
  15. ActivityPub::DeliveryWorker.perform_async(build_json(unblock), unblock.account_id, unblock.target_account.inbox_url)
  16. end
  17. end
  18. def build_json(unblock)
  19. Oj.dump(serialize_payload(unblock, ActivityPub::UndoBlockSerializer))
  20. end
  21. def build_xml(block)
  22. OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.unblock_salmon(block))
  23. end
  24. end