block_service.rb 1023 B

12345678910111213141516171819202122232425262728293031
  1. # frozen_string_literal: true
  2. class BlockService < BaseService
  3. include Payloadable
  4. def call(account, target_account)
  5. return if account.id == target_account.id
  6. UnfollowService.new.call(account, target_account) if account.following?(target_account)
  7. UnfollowService.new.call(target_account, account) if target_account.following?(account)
  8. RejectFollowService.new.call(target_account, account) if target_account.requested?(account)
  9. NotificationPermission.where(account: account, from_account: target_account).destroy_all
  10. block = account.block!(target_account)
  11. BlockWorker.perform_async(account.id, target_account.id)
  12. create_notification(block) if !target_account.local? && target_account.activitypub?
  13. block
  14. end
  15. private
  16. def create_notification(block)
  17. ActivityPub::DeliveryWorker.perform_async(build_json(block), block.account_id, block.target_account.inbox_url)
  18. end
  19. def build_json(block)
  20. Oj.dump(serialize_payload(block, ActivityPub::BlockSerializer))
  21. end
  22. end