block_service.rb 929 B

1234567891011121314151617181920212223242526272829
  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. block = account.block!(target_account)
  10. BlockWorker.perform_async(account.id, target_account.id)
  11. create_notification(block) if !target_account.local? && target_account.activitypub?
  12. block
  13. end
  14. private
  15. def create_notification(block)
  16. ActivityPub::DeliveryWorker.perform_async(build_json(block), block.account_id, block.target_account.inbox_url)
  17. end
  18. def build_json(block)
  19. Oj.dump(serialize_payload(block, ActivityPub::BlockSerializer))
  20. end
  21. end