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.

33 lines
981 B

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