闭社主体 forked from https://github.com/tootsuite/mastodon
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.

23 lines
700 B

  1. # frozen_string_literal: true
  2. class BlockService < BaseService
  3. include StreamEntryRenderer
  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. block = account.block!(target_account)
  9. BlockWorker.perform_async(account.id, target_account.id)
  10. NotificationWorker.perform_async(build_xml(block), account.id, target_account.id) unless target_account.local?
  11. end
  12. private
  13. def build_xml(block)
  14. AtomSerializer.render(AtomSerializer.new.block_salmon(block))
  15. end
  16. end